Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Handler for Dialog

Status
Not open for further replies.

koraykazgan

Programmer
Jan 11, 2005
17
0
0
DE
Hi there,

I like to programm a Win32 application, without using MFC. I can create a Window by code, but it is not easy to design the entire window with all its controls on it. So I want to use a resource and put the controls onto the dialog resource. Then I want to use this resource as template for my windows.

With the CreateDialog function I can get the resources HWND. Then with the function ShowFucntion I display the dialog. But the dialog responds to no message. I have written a DialogMessageHandler function, which processes the events.

What I want to know is, how I bind the MessageHandler Function to the dialog.

I tried to cast the functions name to DLGPROC and then send it as parameter to the createdialog function, but I doesn't worked.

Thank a lot for your help,
Bye...
 
That is exactly what you need to do, give it a DLGPROC. How did it not work? Did it not compile? Be more specific and post the appropriate code.
 
It compiles without any errors or warnings, but the dialog isn't shown on screen. When I set the lpDialogFunc parameter in CreateDialog to null, then the dialog is shown, but it responds to no message, because it doesn't have any message handler set.

So I wrote a message handler and set the lpDialogFunc parameter to the written function. But when I run my app, the dialog isn't shown, even if I use ShowWindow, after CreateWindow. Maybe I have to do something in the WM_SHOW or WM_CREATE event. But i dunno.

Here is the code:

#include <windows.h>
#include "resource.h"

LRESULT CALLBACK fnWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hWnd;
MSG msg;

hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)fnWndProc);
if (!hWnd)
return 0;

ShowWindow(hWnd, nShowCmd);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
}

LRESULT CALLBACK fnWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;

default:
return DefDlgProc(hWnd, msg, wParam, lParam);
}

return 0;
}

Hopefully you can say me, what I have to do, to display the dialog on screen. But I don't want to use the ClassWizard, because it includes code in my project, which I don't want. I just want to create a resource, write a message handler, create an instance from the template, and set the written handler function to my dialog.

Thanks for your help,
bye...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top