
代码语言:javascript
代码运行次数:0
运行 复制#include<windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdshow) {
static TCHAR szAppName[] = TEXT("你好");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_VREDRAW | CS_HREDRAW; // 窗口风格
wndclass.lpfnWndProc = WindowProc; // 消息响应
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance; // 句柄
wndclass.hIcon = LoadIcon(NULL, IDI_ERROR); // 图标
wndclass.hCursor = LoadCursor(NULL, IDI_APPLICATION); // 光标
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // 背景
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass)) {
MessageBox(NULL, TEXT("此程序需要Windows NT!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(
szAppName,
TEXT("第二个程序"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, // 初始 x 位置
CW_USEDEFAULT, // 初始 y 位置
CW_USEDEFAULT, // 初始 x 大小
CW_USEDEFAULT, // 初始 y 大小
NULL, // 父窗口句柄
NULL, // 窗口菜单句柄
hInstance, // 程序实例句柄
NULL // 创建参数
);
ShowWindow(hwnd, nCmdshow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (uMsg) {
case WM_CREATE:
return 0;
case WM_PAINT:
return 0;
case WM_DESTROY:
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
</windows.h>以上就是Windows窗口模板的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号