{"id":1113,"date":"2022-08-11T01:00:01","date_gmt":"2022-08-11T01:00:01","guid":{"rendered":"https:\/\/262235.xyz\/?p=1113"},"modified":"2022-08-11T01:00:01","modified_gmt":"2022-08-11T01:00:01","slug":"1113","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2022\/08\/11\/1113\/","title":{"rendered":"C++ \u4f7f\u7528WinAPI  CreateWindowEx  \u521b\u5efa\u65e0\u6807\u9898\u7a97\u53e3\uff0c\u5c45\u4e2d\u7a97\u53e3"},"content":{"rendered":"<h2>C++ \u4f7f\u7528 WinAPI  <code>CreateWindowEx<\/code>  \u521b\u5efa\u65e0\u6807\u9898\u7a97\u53e3\uff0c\u5c45\u4e2d\u7a97\u53e3<\/h2>\n<pre><code>\ufeff#if defined(UNICODE) &amp;&amp; !defined(_UNICODE)\n    #define _UNICODE\n#elif defined(_UNICODE) &amp;&amp; !defined(UNICODE)\n    #define UNICODE\n#endif\n\n#include &lt;tchar.h&gt;\n#include &lt;windows.h&gt;\n\n\/*  Declare Windows procedure  *\/\nLRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);\n\n\/*  Make the class name into a global variable  *\/\nTCHAR szClassName[ ] = _T(\"CodeBlocksWindowsApp\");\n\nint WINAPI WinMain (HINSTANCE hThisInstance,\n                     HINSTANCE hPrevInstance,\n                     LPSTR lpszArgument,\n                     int nCmdShow)\n{\n    HWND hwnd;               \/* This is the handle for our window *\/\n    MSG messages;            \/* Here messages to the application are saved *\/\n    WNDCLASSEX wincl;        \/* Data structure for the windowclass *\/\n\n    \/* The Window structure *\/\n    wincl.hInstance = hThisInstance;\n    wincl.lpszClassName = szClassName;\n    wincl.lpfnWndProc = WindowProcedure;      \/* This function is called by windows *\/\n    wincl.style = CS_DBLCLKS;                 \/* Catch double-clicks *\/\n    wincl.cbSize = sizeof (WNDCLASSEX);\n\n    \/* Use default icon and mouse-pointer *\/\n    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);\n    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);\n    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);\n    wincl.lpszMenuName = NULL;                 \/* No menu *\/\n    wincl.cbClsExtra = 0;                      \/* No extra bytes after the window class *\/\n    wincl.cbWndExtra = 0;                      \/* structure or the window instance *\/\n    \/* Use Windows's default colour as the background of the window *\/\n    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;\n\n    \/* Register the window class, and if it fails quit the program *\/\n    if (!RegisterClassEx (&amp;wincl))\n        return 0;\n\n    \/* The class is registered, let's create the program*\/\n    hwnd = CreateWindowEx (\n           0,                   \/* Extended possibilites for variation *\/\n           szClassName,         \/* Classname *\/\n           _T(\"Code::Blocks Template Windows App\"),       \/* Title Text *\/\n           WS_POPUP , \/* \u65e0\u6807\u9898\u7a97\u53e3*\/\n           0,       \/* Windows decides the position *\/\n           0,       \/* where the window ends up on the screen *\/\n           400,                 \/* The programs width *\/\n           300,                 \/* and height in pixels *\/\n           HWND_DESKTOP,        \/* The window is a child-window to desktop *\/\n           NULL,                \/* No menu *\/\n           hThisInstance,       \/* Program Instance handler *\/\n           NULL                 \/* No Window Creation data *\/\n           );\n\n\n   \/\/ \u5c45\u4e2d\u7a97\u53e3\n   int scrWidth, scrHeight;\n   RECT rect;\n\n   scrWidth = GetSystemMetrics(SM_CXSCREEN);\n   scrHeight = GetSystemMetrics(SM_CYSCREEN);\n   GetWindowRect(hwnd, &amp;rect);\n   SetWindowPos(hwnd, HWND_TOPMOST, (scrWidth - rect.right) \/ 2, (scrHeight - rect.bottom) \/ 2, rect.right - rect.left, rect.bottom - rect.top, SWP_SHOWWINDOW);\n\n\n    \/* Make the window visible on the screen *\/\n    ShowWindow (hwnd, nCmdShow);\n\n    \/* Run the message loop. It will run until GetMessage() returns 0 *\/\n    while (GetMessage (&amp;messages, NULL, 0, 0))\n    {\n        \/* Translate virtual-key messages into character messages *\/\n        TranslateMessage(&amp;messages);\n        \/* Send message to WindowProcedure *\/\n        DispatchMessage(&amp;messages);\n    }\n\n    \/* The program return-value is 0 - The value that PostQuitMessage() gave *\/\n    return messages.wParam;\n}\n\n\n\/*  This function is called by the Windows function DispatchMessage()  *\/\n\nLRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\n{\n    switch (message)                  \/* handle the messages *\/\n    {\n        case WM_DESTROY:\n            PostQuitMessage (0);       \/* send a WM_QUIT to the message queue *\/\n            break;\n        default:                      \/* for messages that we don't deal with *\/\n            return DefWindowProc (hwnd, message, wParam, lParam);\n    }\n\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>C++ \u4f7f\u7528 WinAPI CreateWindowEx \u521b\u5efa\u65e0\u6807\u9898\u7a97\u53e3\uff0c\u5c45\u4e2d\u7a97\u53e3 \ufeff#if def [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[31],"class_list":["post-1113","post","type-post","status-publish","format-standard","hentry","category-learn","tag-cpp"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=1113"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1113\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}