<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. C語言

    C語言怎樣創建windows窗口

    時間:2025-03-01 21:44:18 C語言 我要投稿
    • 相關推薦

    C語言怎樣創建windows窗口

      耐得住寂寞,禁得起誘惑,這就是程序人生

      步驟:

      1.在WinMain中定義各種變量

      2.注冊窗口類RegisterClass

      3.創建窗口CreateWindow

      4.顯示窗口和更新窗口

      復制代碼 代碼如下:

      ShowWindow (hwnd, iCmdShow) ;

      UpdateWindow (hwnd) ;

      5.消息循環

      復制代碼 代碼如下:

      while (GetMessage (&msg, NULL, 0, 0))

      {

      TranslateMessage (&msg) ;

      DispatchMessage (&msg) ;

      }

      完整代碼:

      復制代碼 代碼如下:

      #include

      LRESULT CALLBACK MyProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);

      int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )

      {

      MSG msg;

      HWND hwnd;

      static TCHAR szAppName[] = "hl";

      WNDCLASS wndclass;

      wndclass.style = CS_HREDRAW | CS_VREDRAW;

      wndclass.cbClsExtra = 0;

      wndclass.cbWndExtra = 0;

      wndclass.lpfnWndProc = MyProc;

      wndclass.hInstance = hInstance;

      wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);

      wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);

      wndclass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);

      wndclass.lpszMenuName = NULL;

      wndclass.lpszClassName= szAppName;

      if(!RegisterClass(&wndclass))

      {

      MessageBox(NULL,TEXT("error"),TEXT("title"),MB_ICONERROR);

      return 0;

      }

      hwnd = CreateWindow(szAppName,

      TEXT("Hello"),

      WS_OVERLAPPEDWINDOW,

      CW_USEDEFAULT,

      CW_USEDEFAULT,

      CW_USEDEFAULT,

      CW_USEDEFAULT,

      NULL,

      NULL,

      hInstance,

      NULL

      );

      ShowWindow(hwnd,nShowCmd);

      UpdateWindow(hwnd);

      while(GetMessage(&msg,hwnd,0,0))

      {

      TranslateMessage(&msg);

      DispatchMessage(&msg);

      }

      return msg.wParam;

      }

      LRESULT CALLBACK MyProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)

      {

      switch(message)

      {

      case WM_DESTROY:

      PostQuitMessage(0);

      return 0;

      }

      return DefWindowProc(hwnd,message,wParam,lParam);

      }

    【C語言怎樣創建windows窗口】相關文章:

    C語言創建windows窗口實例05-14

    C語言文件的創建與建立08-12

    c語言—文件的創建與建立09-27

    c語言文件創建與建立05-31

    怎樣學習c++c語言編程10-26

    C語言怎樣輸出菱形08-02

    用C語言編寫Windows服務程序的五個步驟10-27

    怎么利用c語言創建excel文件08-13

    C語言實現自定義windows系統日志的方法08-01

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人