Jump to content
  • Advertisement
Sign in to follow this  
ukdeveloper

Using Dialogs as resources (Win32)

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm working on an app in Win32, and I'm having problems getting the main window set up. At the moment, I've got a hard-coded, programmatically created window working, with a Menu as a resource. I've also got part of that menu which can open a separate About dialogue box as a resource, so that's fine. What I want to be able to do is to create my main app window as a Dialog resource complete with buttons, text boxes etc, and load it when the program starts instead of hardcoding every single control. However, I'm unsure how to do it, and the tutorials I've found online cause VC++ to throw errors. The main problem is I can get the custom dialogue resource to display, I just can't get the callback working with it (it won't respond to button clicks etc.). Here's my code to show the dialogue resource on screen:
MainWindow=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),0,0);
ShowWindow(MainWindow,SW_SHOWNORMAL);



As you can see, the lack of response is called by me not including the callback function in those parameters. However, when I swap the second zero in CreateDialog to the name of my callback function, WndProcedure, I get: error C2664: 'CreateDialogParamA' : cannot convert parameter 4 from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to 'DLGPROC' 1> None of the functions with this name in scope match the target type even though I've seen this method used in several online tutorials. I'm not using MFC, it's straight Win32, and I'm stuck. Can anybody help? Thanks in advance, ukdeveloper. [Edited by - ukdeveloper on July 25, 2005 6:14:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
You are using 0 where you need to supply the DlgProc. Here is my entire main.cpp from a project I wrote a week ago. Note that, this dialog box only responds to events, it can't do anything like render a picture at 30fps or anything that didn't require an even to have run.

[source="cpp"]

int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR Arg,int nCmdShow)
{

hInst = hInstance;

DialogBox(hInst, MAKEINTRESOURCE(IDD_DLG_MAIN), NULL, MainDlgProc);

return true;
}


CALLBACK MainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
HRESULT hRes;

switch(msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDC_BTN_LIGHTAMB:
{
//DialogBox(hInst, MAKEINTRESOURCE(IDD_DLG_LIGHTING), NULL, MainDlgProc);
}break;

case IDC_BTN_RENDER:
{
Render();
}break;

default:
return false; // Didn't handle message
}break;

case WM_ACTIVATE:
{
if (LOWORD(wParam) == WA_ACTIVE);
}break;

case WM_INITDIALOG:
{
//grab all the controls
hStcRender = GetDlgItem(hDlg,IDC_STC_RENDER);

SetWindowText(hDlg,APP_TITLE);
SetWindowText(hStcRender,"");

RenderInit(hStcRender);
Render();

}break;
case WM_NOTIFY:
break;


//window being destroyed
case WM_CLOSE:
case WM_QUIT:
case WM_DESTROY:
RenderShutdown();
EndDialog(hDlg,0);
break;

default:
return false; // Didn't handle message
}

return TRUE;
}



Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
You are using 0 where you need to supply the DlgProc.


That's what I was trying to do. And I get the error I mentioned when doing precisely that, I can't fathom it, it shouldn't do it.

Share this post


Link to post
Share on other sites
Have you tried casting? As in, "CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),0,(DLGPROC)MainDlgProc);"?

Share this post


Link to post
Share on other sites
Quote:
Original post by TDragon
Have you tried casting? As in, "CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),0,(DLGPROC)MainDlgProc);"?


That fixed it [smile]!

Thank you both for your help!

Share this post


Link to post
Share on other sites
No problem. Do you happen to be using C++ rather than C? If so, it's the difference in strictness that causes this -- but that's a good thing. If not, congratulations on using good C compiler with strict argument checking.

Share this post


Link to post
Share on other sites
At first glance, the return type of your dialog procedure is nor specified. From what I read in the platform SDK it should be INT_PTR. I Don't think that just casting away the problem is the way to go in that case.

Share this post


Link to post
Share on other sites
Quote:
Original post by VolkerG
At first glance, the return type of your dialog procedure is nor specified. From what I read in the platform SDK it should be INT_PTR. I Don't think that just casting away the problem is the way to go in that case.



1 -- That's not the op's source.

2 -- that is how MS makes their own DLGProcs from the direct x source samples.

Share this post


Link to post
Share on other sites
Thanks for all your help.


Actually, there's another problem:

The dialog box appears at startup, but it is locked in position and can't be moved (the position has to be hardcoded using the resource file). The caption also won't appear on the title bar, even though it shows up in the resource file. Also, the system menu and X buttons on the dialog frame at the top don't work.

The buttons work, though. Bringing up another dialog using IDOK causes my app to freeze.

Any ideas? Might there be a problem in my Callback or something?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!