Windows Dialogs in a Class

Started by
2 comments, last by Webbster 19 years, 8 months ago
I'm still having a lot of issues with the Windows API and wrapping it up with C++. The new problem is coming from a Dialog Box that I am trying to display. I have the dialog resource itself created, and I've already coded the Dialog Procedure but I've put them into a class temporarily called CApp. CApp's constructor makes a call to the DialogBox() function that will display the dialog itself but somethings not working, the Debug says:- error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'int (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long) I'm not to sure what to make of it! The Dialog Procedure is a public member at the moment, and this is my call to the DialogBox() function:- DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SETUP), hWND, SetupDlgProc); I can get it all to work in standard C but the process doesn't seem to like being put into a class the way I have done it. I'm having very similiar problems with the applications main window, with it not being able to 'use' it's procedure. I'd appreciate any help, I've already waisted to much time with windows and so far very little to show for it. Ad
Advertisement
I dont want to sound mean but this question is all over the forums *points to search*

Make the message handler statis and it will work.

Ofcourse this means that you can only have one window. So you are best having a single static message handler that has a list of pointers to your dialog class.

Each time you make a dialog you add the this pointer to the list. When the static message handler is called it can check to find the right dialog class (based on the Window Handle or such) and then pass the message to a none static message handler for that class.

If thats not very clear (and on a reread I see that it isn't just search the forums for a better explanation, actually I think there was a previous featured article on win32 classes if you search back a year or two).
The first thing I did to get around the fact that a message handler cannot be a class member is to first, ditch dialogs. Make them standard windows, and then modify their attributes to look like dialogs.

Your problem can be overcome, but the solution is kinda messy. I've forgotten the specifics, but I think that it involves creating one message handler (not part of the object) and when you create the window, piggyback a pointer to the object in the LPARAM (or whatever the last argument is when creating the dialog), and derefrencing it when the one message handler recieves it. All dialogs you create would use the message handler as an entry point for dispatching the correct classes message handler function.

If you want to PM me, i can grab some source code when i get home and send it to you
Hey thanks for the help, I did a little scout around the GameDev forums, and I've found a way to deal with it using pointers.

Thanks :)

This topic is closed to new replies.

Advertisement