#include
#include
#include"resource.h"
//全局变量
LPSTR g_MainFrame = "主框架";
LPSTR g_ClientFrame = "客户区框架";
LPSTR g_ChildFrame[] = { "子框架1","子框架2" };
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
//函数执行的入口函数
int WINAPI WinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nShowCmd)
{
//1.初始化需要注册的窗口信息
WNDCLASS MainFrame = { 0 };
MainFrame.hbrBackground = (HBRUSH)::GetStockObject(GRAY_BRUSH);//背景
MainFrame.hCursor = ::LoadCursor(NULL, IDC_ARROW);
MainFrame.hInstance = hInstance;
MainFrame.lpfnWndProc = WndProc;
MainFrame.lpszClassName = g_MainFrame;
MainFrame.lpszMenuName = MAKEINTRESOURCE(IDR_MainFrame);//定位资源,通过MAKEINTRESOURCE转换的id, //也可以是资源名称的字符串。
MainFrame.style = CS_VREDRAW | CS_HREDRAW;
//2.注册MainFrame窗口
if (!RegisterClass(&MainFrame))
{
MessageBox(NULL, _T("主框架注册失败!"), _T("Error"), MB_OK | MB_ICONERROR);//_T() 需用用到tchar.h头文件
}
//3.创建窗口
HWND mainframe_hwnd;
mainframe_hwnd= CreateWindow(
g_MainFrame,
g_ClientFrame,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(!mainframe_hwnd)
MessageBox(NULL, _T("主框架创建失败!"), _T("Error"), MB_OK | MB_ICONERROR);
//4.显示窗口
ShowWindow(mainframe_hwnd, nShowCmd);
//5.刷新窗口
UpdateWindow(mainframe_hwnd);
//6.信息捕获
MSG mainframe_msg;
while (::GetMessage(&mainframe_msg, NULL, 0, 0))
{
::TranslateMessage(&mainframe_msg);//TranslateMessage是用来把虚拟键消息转换为字符消息。
::DispatchMessage(&mainframe_msg);//消息调度
}
return mainframe_msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//处理消息
switch (message)
{
/*1.关不窗口时,会收到该消息,PostQuitMessage()像系统表明终止当前线程,没有这个函数的话,窗口不会关闭*/
case WM_DESTROY:
PostQuitMessage(0);//用于相应关闭消息,否则线程不会关闭,导致系统阻塞
return 0;
}
//将不需要处理的消息传递给系统作默认处理
return DefWindowProc(hwnd, message, wParam, lParam);
}