Code:
#include <windows.h>
#include "hex.h"
const char g_ClassName[]="hwnd window class name";
const char g_ChildClassName[]="child window class name";
HWND child_window;
HINSTANCE hInstance_child;
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case HWND_FILE_EXIT:
PostQuitMessage(0);
break;
case EXTRA_BASE_CONVERT:
ShowWindow(child_window,SW_SHOW);
UpdateWindow(child_window);
break;
}
}
break;
case WM_CREATE:
{
child_window = CreateWindowEx(WS_EX_CLIENTEDGE,
g_ChildClassName,
"Base Converter",
WS_OVERLAPPED|WS_CHILD|WS_SYSMENU,
10,10,
150,150,
hwnd,
(HMENU)EXTRA_BASE_CONVERT,
hInstance_child,
NULL);
}
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
}
bool CALLBACK chWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return true;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR nCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Message;
WNDCLASSEX wc;
WNDCLASSEX wc_child;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.style = 0;
wc.hbrBackground = CreateSolidBrush(RGB(0,0,100));
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.lpszMenuName = MAKEINTRESOURCE(HWND_MENU);
wc.lpszClassName = g_ClassName;
wc.lpfnWndProc = WndProc;
wc_child.cbSize = sizeof(WNDCLASSEX);
wc_child.cbWndExtra = 0;
wc_child.cbClsExtra = 0;
wc_child.style = 0;
wc_child.hbrBackground = CreateSolidBrush(RGB(0,100,0));
wc_child.hInstance = hInstance;
wc_child.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc_child.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wc_child.hCursor = LoadCursor(NULL,IDC_ARROW);
wc_child.lpszMenuName = NULL;
wc_child.lpszClassName = g_ChildClassName;
wc_child.lpfnWndProc = WndProc;
RegisterClassEx(&wc);
RegisterClassEx(&wc_child);
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
g_ClassName,
"Window Title",
WS_OVERLAPPEDWINDOW,
200,200,
200,200,
HWND_DESKTOP,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Message,NULL,0,0)>0)
{
TranslateMessage(&Message);
DispatchMessage (&Message);
}
return Message.wParam;
}
ok, I think I know why its not working, the message loop has no way of getting to the second callback function (for my child windw). In the tutorial I seen in modeless dialog boxes, they used a message loop something like this: