今天搞了個子窗口和MDI系統窗口,因爲一個字母,浪費了我一個多小時。。。。
#include "windows.h"
HINSTANCE g_hInstance;
HWND g_hClient = NULL;
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPARAM lparam)
{
switch (uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
//return DefWindowProc(hwnd,uMsg,wparam,lparam);
return DefFrameProc(hwnd,g_hClient,uMsg,wparam,lparam);
}
LRESULT CALLBACK SonWndProc(HWND hwnd,UINT uMsg,WPARAM wparam,LPARAM lparam)
{
return DefMDIChildProc(hwnd,uMsg,wparam,lparam);
}
BOOL CALLBACK RegisteWnd(LPCTSTR WndClaName,WNDPROC WndFun,HBRUSH color)
{
WNDCLASSEX wce;
wce.cbSize = sizeof(wce);
wce.style = CS_HREDRAW|CS_VREDRAW;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hbrBackground = color;
wce.hCursor = NULL;
wce.hIcon = NULL;
wce.hIconSm = NULL;
wce.hInstance = g_hInstance;
wce.lpfnWndProc = WndFun;
wce.lpszClassName = WndClaName;
wce.lpszMenuName = NULL;
ATOM nAtom = RegisterClassEx(&wce);
return TRUE;
}
HWND CALLBACK CreatMainWnd(LPCTSTR WndClaName)
{
HWND hwnd = CreateWindowEx(0,WndClaName,L"good",WS_OVERLAPPEDWINDOW,0,0,600,500,NULL,NULL,g_hInstance,NULL);
return hwnd;
}
HWND CALLBACK CreatMDIWnd(LPCTSTR WndClaName,HWND Parent)
{
CLIENTCREATESTRUCT cs = {0};
cs.idFirstChild = 1000;
HWND hwnd = CreateWindowEx(0,WndClaName,L"DMI",WS_CHILD|WS_VISIBLE,0,0,400,400,Parent,NULL,g_hInstance,&cs);
return hwnd;
}
HWND CALLBACK CreatSonWnd(LPCTSTR WndClaName,HWND Parent)
{
HWND hwnd = CreateWindowEx(WS_EX_MDICHILD,WndClaName,L"son",
WS_CHILD|WS_VISIBLE,
0,0,100,200,Parent,NULL,g_hInstance,NULL);
return hwnd;
}
void ShowWnd(HWND hwnd)
{
MSG msg;
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0))
{
// TranslateMessage(&msg);
DispatchMessage(&msg);
}
return;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
g_hInstance = hInstance;
RegisteWnd(L"MyWnd",WndProc,(HBRUSH )(COLOR_BTNFACE + 3));
RegisteWnd(L"SonWnd",SonWndProc,(HBRUSH )(COLOR_WINDOW));
HWND hwnd = CreatMainWnd(L"MyWnd");
g_hClient = CreatMDIWnd(L"MDICLIENT",hwnd);//MDICLIENT一個字母讓我找了好久的錯誤~
MoveWindow(g_hClient,0,0,100,200,TRUE);
HWND sonhwnd = CreatSonWnd(L"SonWnd",g_hClient);
ShowWnd(hwnd);
return 0;
}