Windows窗口原理
消息提示框
参数一: HWND(显示在哪一个窗口之上)
参数二: 所要提示的文本内容(注意使用UniCode编码 例: L"123")
参数三: 消息提示框标题
参数四: 消息提示框中按钮组件(MB_OK) | 图标组件(MB_ICONEXCLAMATION)
MessageBox(NULL, L"First Window!", L"Window", MB_OK);
MessageBox有返回值
例如: IDYES = MessageBox(......); //点击了是按钮
WINAPI : 实质是一个__stdcall(函数调用约定) 的宏
__cdecl 调用方清理栈
__stdcall 被调用方清理栈
MAKEINTRESOURCE(int); //将宏转换为LPSTR类型
#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
#include<Windows.h>
#include"resource.h"
LRESULT CALLBACK WindowProcfn(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc = { 0 };
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = WindowProcfn;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wc.hCursor = LoadCursor(NULL,IDC_HAND);
wc.hbrBackground = CreateSolidBrush(RGB(255, 0, 255));
wc.lpszMenuName = NULL;
wc.lpszClassName = L"byteDance";
ATOM at = RegisterClass(&wc);
if (at == 0)
{
MessageBox(NULL, L"注册窗口失败!", L"温馨提示", MB_YESNO);
}
else
{
MessageBox(NULL, L"注册窗口成功!", L"温馨提示", MB_YESNO);
}
HWND hWnd = CreateWindow(
L"byteDance",
L"窗口一",
WS_BORDER | WS_SYSMENU | WS_CAPTION | WS_MAXIMIZE | WS_MINIMIZE,
100,100,
400,400,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProcfn(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}