Hi,
I posted this on another forum but haven't really understood some of the replies I received, I was wondwering if you guys could take a look at these questions for me, thanks.
So on with the questions! Callback functions for DB's (Dialog Boxes). As I understand it there's no such thing as a DB without a callback function, otherwise you can't 'do' anything with the user input the DB is intended to capture. Now I don't want to get into the guts of a DB callback function just yet - most of it from what I can see revolves around lengthly switch/case statements each one bound to the ID designated for each box/menu/button.
I have some more general questions about them. Looking at a DB creation function below:for those of you who have forgotten or aren't familiar with what it looks like.Code:int DialogBox(HINSTANCE hInstance, LPCSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc);
I'm ok with most of the parameters. In fact I'm *fairly* ok with them all. The first parameter wants a windows handle to the module where the resource files are. IN my case it's a DLL I'm working with. Fine. THe lpTemplate part is the template for the DB defined in the .rc file. This is where all the data regarding how the box should look, and where its buttons are - is contained. Ok, this is the part where you need that MAKEINTRESOURCE() thing to use with your defines inside the resource.h file. Ok with that too. hWndParent is the parent window - ok with that. However:
1)What is a DLGPROC variable? I've seen some strange stuff used here. In the source I've got which compiles ok I have the following:which uses the re-interpret cast thing. In my book I've seen just simply the name of a function used for this parameter with no casting:Code:DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST), hWnd, reinterpret_cast<DLGPROC>(DlgProc));The difference is, the source I have has the DlgProc function defined as:Code:nResult = DialogBox(m_hDll, "dlgChangeDevice", hWnd, DlgProc);, whereas in my book I've got:Code:LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)The only real difference being one has a return variable of LRESULT and the other a return variable of BOOL. What I'm really wondering is, does the return variable type of a callback function have any bearing on how that function can be passed as an argument to the DialogBox function? Also what is it we are actually passing here? By simply passing a function's name is it somehow decaying to a function pointer and thus satisfying the requirements of the DLGPROC variable? Is that what a DLGPROC variable is, a pointer/function pointer? Proper confused here - you can probably tell! ;o)Code:BOOL CALLBACK DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
2)One rather interesting query pops up in my book. He states that a class member function can be used as the callback function. Ok sounds great, so I can use the member callback function to fill out a load of private data in the class. Super. Only problem is it appears that the compiler is not happy unless there's a guaranteed instance of said class at run-time. In my book he basically states that without an existing declared instance of a class which contains the member callback function at compile time, the code will not compile. Is this to prevent a Dialog Box from ever being run without a callback function to use - this preventing it from being high and dry?
Thanks for any help anyone can offer - cheers!



LinkBack URL
About LinkBacks



