當(dāng)前位置:
首頁(yè) >
win32项目-最基础的窗口程序
發(fā)布時(shí)間:2025/3/15
22
豆豆
生活随笔
收集整理的這篇文章主要介紹了
win32项目-最基础的窗口程序
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
程序運(yùn)行截圖如下:
代碼如下:
main.cpp
#include <windows.h>LRESULT CALLBACK GLWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {switch (msg) {case WM_CLOSE:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, msg, wParam, lParam); }INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevlnstance, LPSTR lpCmdLine, int nShowCmd) {WNDCLASSEX wndclass;wndclass.cbClsExtra = 0;wndclass.cbSize = sizeof(WNDCLASSEX);wndclass.cbWndExtra = 0;wndclass.hbrBackground = NULL;wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);wndclass.hIcon = NULL;wndclass.hIconSm = NULL;wndclass.hInstance = hInstance;wndclass.lpfnWndProc = GLWindowProc;wndclass.lpszClassName = L"GLWindow";wndclass.lpszMenuName = NULL;wndclass.style = CS_VREDRAW | CS_HREDRAW;ATOM atam = RegisterClassEx(&wndclass);if (!atam) {MessageBox(NULL, L"Notice", L"Error", MB_OK);return 0;}RECT rect;rect.left = 0;rect.right = 800;rect.top = 0;rect.bottom = 600;AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, NULL);int windowWidth = rect.right - rect.left;int windowHeight = rect.bottom - rect.top;HWND hwnd = CreateWindowEx(NULL, L"GLWindow", L"OpenGL Window", WS_OVERLAPPEDWINDOW, 100, 100, windowWidth, windowHeight, NULL, NULL, hInstance, NULL);ShowWindow(hwnd, SW_SHOW);UpdateWindow(hwnd);MSG msg;while (true) {if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {if (msg.message == WM_QUIT)break;TranslateMessage(&msg);DispatchMessage(&msg);}}return 0; }?
總結(jié)
以上是生活随笔為你收集整理的win32项目-最基础的窗口程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt线程间通信-自定义事件
- 下一篇: 软件设计师习题笔记-重点习题二