关于创建子窗口,该怎么处理
关于创建子窗口
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //父窗口过程
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
int cxClient,cyClient;
switch (message)
{
case WM_CREATE: //把窗口分成左右两个子窗口 LHwnd,RHwnd 存在全局变量中
MyRegisterChildClass(hInst);
LHwnd = CreateWindow(TEXT( "Child "),NULL,WS_CHILDWINDOW|WS_VISIBLE,0,0,0,0,hWnd,NULL,hInst,NULL);
RHwnd = CreateWindow(TEXT( "Child "),NULL,WS_CHILDWINDOW|WS_VISIBLE,0,0,0,0,hWnd,NULL,hInst,NULL);
break;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
MoveWindow(LHwnd,0,0,cxClient/2,cyClient,true);
MoveWindow(RHwnd,cxClient/2,0,cxClient/2,cyClient,true);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //子窗口消息处理过程
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_CREATE:
MessageBox(hWnd,TEXT( "ChildWindow Create Successfully "),TEXT( "CHILD ONE "),MB_OKCANCEL); //提示子窗口建立成功
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
ATOM MyRegisterChildClass(HINSTANCE hInstance) //注册子窗口类
{
WNDCLASSEX ChildClass;
ChildClass.cbSize = sizeof(WNDCLASSEX);
ChildClass.style = CS_HREDRAW|CS_VREDRAW;
ChildClass.cbClsExtra = 0;
ChildClass.cbWndExtra = 0;
ChildClass.hCursor = NULL;
ChildClass.hIcon = NULL;
ChildClass.hIconSm = NULL;
ChildClass.lpszMenuName = NULL;
ChildClass.lpfnWndProc = ChildWndProc;
ChildClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
ChildClass.lpszClassName = TEXT( "Child ");
return RegisterClassEx(&ChildClass);
}
到主窗口处理WM_CREATE的时候 LHwnd和RHwnd在CreateWindow以后都是0X0000000
子窗口就没有创建 怎么回事啊?
------解决方案--------------------
接分
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //父窗口过程
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
int cxClient,cyClient;
switch (message)
{
case WM_CREATE: //把窗口分成左右两个子窗口 LHwnd,RHwnd 存在全局变量中
MyRegisterChildClass(hInst);
LHwnd = CreateWindow(TEXT( "Child "),NULL,WS_CHILDWINDOW|WS_VISIBLE,0,0,0,0,hWnd,NULL,hInst,NULL);
RHwnd = CreateWindow(TEXT( "Child "),NULL,WS_CHILDWINDOW|WS_VISIBLE,0,0,0,0,hWnd,NULL,hInst,NULL);
break;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
MoveWindow(LHwnd,0,0,cxClient/2,cyClient,true);
MoveWindow(RHwnd,cxClient/2,0,cxClient/2,cyClient,true);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //子窗口消息处理过程
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_CREATE:
MessageBox(hWnd,TEXT( "ChildWindow Create Successfully "),TEXT( "CHILD ONE "),MB_OKCANCEL); //提示子窗口建立成功
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
ATOM MyRegisterChildClass(HINSTANCE hInstance) //注册子窗口类
{
WNDCLASSEX ChildClass;
ChildClass.cbSize = sizeof(WNDCLASSEX);
ChildClass.style = CS_HREDRAW|CS_VREDRAW;
ChildClass.cbClsExtra = 0;
ChildClass.cbWndExtra = 0;
ChildClass.hCursor = NULL;
ChildClass.hIcon = NULL;
ChildClass.hIconSm = NULL;
ChildClass.lpszMenuName = NULL;
ChildClass.lpfnWndProc = ChildWndProc;
ChildClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
ChildClass.lpszClassName = TEXT( "Child ");
return RegisterClassEx(&ChildClass);
}
到主窗口处理WM_CREATE的时候 LHwnd和RHwnd在CreateWindow以后都是0X0000000
子窗口就没有创建 怎么回事啊?
------解决方案--------------------
接分