Re: 2 parm vs. 1parm GetDlgItem() trouble . . .
1. I would just make the button members part of the class, again using the
wizard. If there is more than one dialog there should be more than set of
variables for each and each dialog should be initialied in its own
OnInitDialog() function. Assuming gMBs is a global variable (I didn't see
where you declared it so not sure what it is) that would be working around
the encapsulation idea of OOP.
2. I don't think you should have to pass around HWNDs or CWnd *'s. Instead
you could just structure your dialogs:
Main dialog - has own set of controls
Sub dialog - opened by main dialog when a button is clicked. At this
time the main dialog creates a sub dialog object then assigns info to it as
needed before calling DoModal().
When Sub dialog completes Main dialog can fish information from it.
void CImageFileSavedView::OnBnClickedButton()
{
CSubDlg dlg;
dlg.m_Param1 = m_Param1;
dlg.m_Param2 = m_Param2;
if(dlg.DoModal() == IDOK) {
m_Param1 = dlg.m_Param1;
m_Param2 = dlg.m_Param2;
}
}
Of course the params could be any variable names or any types of variable
data. Both the top dialog and the sub dialog have their own copy of the
data so you can change one without necessarily having to affect the other.
3. Really easy. When you dialog is open, right click on a control and
select Add Event Handler or Add Variable from the menu. The wizard will pop
up for you. What it does is creates a variable of the correct type as a
member in your class. I typically create a control and data variable for
each control on the dialog that needs to be accessed. If you want to create
variables for static controls you'll have to change the default ID created
ID_STATIC to something else.
4. I think this is confusing too. If all the screens simply have their own
buttons (created in the dialog editor) then you shouldn't have to store them
elsewhere.
5. There are lots of places to look at code and learn MFC. It seems
confusing at first, but then you'll have one of those "aha" moments where
it will make sense. If you start by using the wizards and dialog editor to
do thing they will do a lot of work for you. You could also look at:
www.codeproject.com
www.codeguru.com
To get lots of free code and examples.
And... keep asking questions. That's what we do here and each of us learned
the same way you are.
Tom
"Kevin Waite" <kevin001.waite@gmail.com> wrote in message
news:18D301E3-925F-4E38-8031-89E58B24AA30@microsoft.com...
Hi David,
( also check Giovanni feedback )
1. I am confused about the variable gMBs. Why does this variable appear
in mpc.cpp? Your do_mpc_btn_init() function is a method of class Mpc. Are
you sure that you understand how OOP programming works?
where should gMBs be declared -- I need to store data for the described
buttons
somewhere? In an OOP way, where would you place this button control class?
2. Since you are using MFC, I would pass a CWnd* pointer to this method,
not an HWND (though I am not quite sure why you need either).
This seems to be inline with what Giovanni is suggusting.
Hmmmmm, this pointer CWnd* in my case would be?
CWnd *my_cwd = AfxGetMainWnd( );
maybe?
3. Your GetDlgItem() with casting technique is not the right way to
assign member variables to controls. Rather you should use the Add
Variable wizard to add a control variable of type CButton.
Do not know about this wizard -- this is a programmatic wizard? Not even
sure I
want to add control variables -- I want to programmatice count
button clicks/touches and toggle/swap the bitmap on the fly for screen X
of button Y.
4. What is this Btn[][] array?
As described in mpc.h -- there will be X screens of Y buttons -- where Y
is 6 and
the number of screens is set to 1 now -- but will be 2 or 3 or n -- etc.
5. It would seem you are trying to use MFC without really knowing how it
works. I would suggest study of a good book, e.g. Prosise.
Prosise? Which book David?
Thanks.
Sincerely,
Kevin Waite