#include<Windows.h>
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
/*MessageBox(hWnd,TEXT("窗口已创建"),TEXT("窗口"),MB_OKCANCEL)*/;break;
case WM_DESTROY:
PostQuitMessage(0);break;
case WM_SYSCOMMAND:
if(wParam==SC_CLOSE)
{
int nRect=MessageBox(hWnd,TEXT("确定关闭窗口"),TEXT("窗口"),MB_OKCANCEL);
if(nRect==IDOK)
{}
else
return 0;
break;
}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
void MyRegisterWindowClass(HINSTANCE hInstance,LPCWSTR lpClassName,WNDPROC WndProc)
{
WNDCLASS wc={0};
wc.lpszClassName=lpClassName;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.cbClsExtra=NULL;
wc.cbWndExtra=NULL;
wc.hbrBackground=(HBRUSH)COLOR_WINDOW;
wc.hCursor=NULL;
wc.hIcon=NULL;
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszMenuName=NULL;
RegisterClass(&wc);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
//注册主窗口
MyRegisterWindowClass(hInstance,TEXT("main"),WndProc);
//创建主窗口
HWND hWnd=CreateWindow(TEXT("main"),TEXT("TEXT"),WS_OVERLAPPEDWINDOW,200,200,1000,600,NULL,NULL,hInstance,NULL);
//注册子窗口
MyRegisterWindowClass(hInstance,TEXT("child"),WndProc);
//创建子窗口
HWND hWnd1=CreateWindow(TEXT("child"),TEXT
("TEXT1"),WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW/*前两个必备*/,100,200,500,300,hWnd,NULL,hInstance,NULL);
MoveWindow(hWnd1,100,100,800,400,NULL);
//显示窗口
ShowWindow(hWnd,SW_SHOW); //必须显示主窗口
//ShowWindow(hWnd1,SW_SHOW);
UpdateWindow(hWnd);
//消息循环
MSG msg={0};
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}