16,471
社区成员
发帖
与我相关
我的任务
分享
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
#include<windows.h>
#include<tchar.h>
//窗口类名和窗口标题
TCHAR szWindowClass[]=_T("HELLOWINDOWS");
TCHAR szWindowTitle1[]=_T("This is the MAIN window");
TCHAR szWindowTitle2[]=_T("Test");
HWND g_hWnd1;
HWND g_hWnd2;
//窗口过程函数
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//LogMessage(logfile,msg,wParam,lParam);//
if(hWnd == g_hWnd1)
{
switch(msg)
{
case WM_DESTROY:
MessageBox(hWnd,"OK!Window1",NULL,0);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
}
else if(hWnd == g_hWnd2)
{
switch(msg)
{
case WM_DESTROY:
MessageBox(hWnd,"OK!Window1",NULL,0);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
}
}
int WINAPI _tWinMain( HINSTANCE hInstance,HINSTANCE,LPTSTR lpCmdLine,int nCmdShow)
{
//注册窗口类
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
//创建主窗口
HWND hWnd1 = CreateWindowEx(0,szWindowClass, szWindowTitle1, WS_OVERLAPPEDWINDOW,
128, 96, 512, 480, HWND_DESKTOP, NULL, hInstance, NULL);
if (!hWnd1)
return FALSE;
g_hWnd1 = hWnd1;
HWND hWnd2 = CreateWindowEx(0,szWindowClass, szWindowTitle2, WS_OVERLAPPEDWINDOW,
128, 96, 512, 480, HWND_DESKTOP, NULL, hInstance, NULL);
if (!hWnd2)
return FALSE;
g_hWnd2 = hWnd2;
//显示并更新主窗口
ShowWindow(hWnd1,nCmdShow);
UpdateWindow(hWnd1);
ShowWindow(hWnd2,nCmdShow);
UpdateWindow(hWnd2);
// 进入消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
//程序退出
}