windows編程:第一個windows程式

來源:互聯網
上載者:User

標籤:

 1 #define WIN32_LEAN_AND_MEAN 2 #include <windows.h> 3 #include <windowsx.h> 4 #include <math.h> 5 #define WINDOW_CLASS_NAME L"WINCLASS1" 6 //視窗處理函數 7 LRESULT CALLBACK WindowProc(HWND hwnd, 8     UINT msg, 9     WPARAM wParam,10     LPARAM lPram)11 {12     PAINTSTRUCT ps;13     HDC hdc;14     switch (msg)15     {16     case WM_CREATE:17     {18                       return 0;19     }break;20     case WM_PAINT:21     {22                      hdc = BeginPaint(hwnd, &ps);23                      EndPaint(hwnd, &ps);24                      return 0;25     }break;26     default:break;27     }28     return DefWindowProc(hwnd, msg, wParam, lPram);29 }30 void GameMain()31 {32     return;33 }34 int WINAPI WinMain(HINSTANCE hInstance,35     HINSTANCE hPrevInstance,36     LPSTR lpCmdLine,37     int nCmdShow)38 {39     //定義視窗類別40     WNDCLASSEX winClass;41     HWND hWnd;42     MSG msg;43     //填充視窗類別的個成員44     winClass.cbSize = sizeof(WNDCLASSEX);45     winClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;46     winClass.lpfnWndProc = WindowProc;    //視窗訊息處理函數47     winClass.cbClsExtra = 0;48     winClass.cbWndExtra = 0;49     winClass.hInstance = hInstance;50     winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);51     winClass.hCursor = LoadCursor(NULL, IDC_ARROW);52     winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);53     winClass.lpszMenuName = NULL;54     winClass.lpszClassName = WINDOW_CLASS_NAME;        //視窗類別名55     winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);56 57     //註冊視窗類別58     if (!RegisterClassEx(&winClass))59     {60         return 0;61     }62 63     //建立視窗類別的一個成員64     if (!(hWnd = CreateWindowEx(NULL,65         WINDOW_CLASS_NAME,66         L"hello world",67         WS_OVERLAPPEDWINDOW | WS_VISIBLE,68         0, 0,69         640, 480,70         NULL,71         NULL,72         hInstance,73         NULL)))74     {75         return 0;76     }77 78     //訊息迴圈79     while (true)80     {81         if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))82         {83             if (msg.message == WM_QUIT)84             {85                 break;86             }87             TranslateMessage(&msg);88             DispatchMessage(&msg);89         }90         GameMain();91     }92     return msg.wParam;93 }

 

windows編程:第一個windows程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.