zoukankan      html  css  js  c++  java
  • A simple windows programm in c

       
    A simple windows programm in c
            
    The following programm is a minimal windows program. It opens a window and writes a text into the window.
    If you compile it with MinGW, be sure to add the -mwindows flag in order to prevent the ... undefined reference to 'TextOutA@20' and ... undefined reference to 'GetStockObject@4 linker error.

    #include <windows.h>

    LRESULT CALLBACK WndProc(
        HWND   hWnd,
        UINT   msg,
        WPARAM wParam,
        LPARAM lParam ) {

      switch( msg ) {
        case WM_PAINT: {
          PAINTSTRUCT ps;
          HDC hDC = BeginPaint( hWnd, &ps );
          TextOut(hDC, 10, 10, "ADP GmbH", 8 );
          EndPaint( hWnd, &ps );
        }
        break;

        case WM_DESTROY:
          PostQuitMessage(0);
        break;

        default:
          return DefWindowProc( hWnd, msg, wParam, lParam);
      }
      return 0;
    }


    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow) {

      WNDCLASSEX wce;

      wce.cbSize        = sizeof(wce);
      wce.style         = CS_VREDRAW | CS_HREDRAW;
      wce.lpfnWndProc   = (WNDPROC) WndProc;
      wce.cbClsExtra    = 0;
      wce.cbWndExtra    = 0;
      wce.hInstance     = hInstance;
      wce.hIcon         = LoadIcon((HINSTANCE) NULL, IDI_APPLICATION);
      wce.hCursor       = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
      wce.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
      wce.lpszMenuName  = 0;
      wce.lpszClassName = "ADPWinClass",
      wce.hIconSm       = 0;
     
      if (!RegisterClassEx(&wce)) return 0;
     
      HWND hWnd = CreateWindowEx(
        0,          // Ex Styles
        "ADPWinClass",
        "ADP GmbH",
         WS_OVERLAPPEDWINDOW,
         CW_USEDEFAULT,  // x
         CW_USEDEFAULT,  // y
         CW_USEDEFAULT,  // Height
         CW_USEDEFAULT,  // Width
         NULL,           // Parent Window
         NULL,           // Menu, or windows id if child
         hInstance,      //
         NULL            // Pointer to window specific data
      );

      ShowWindow( hWnd, nCmdShow );

      MSG msg;
      int r;
      while ((r = GetMessage(&msg, NULL, 0, 0 )) != 0) {
        if (r == -1) {
          ;  // Error!
        }
        else {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      }

      // The application's return value
      return msg.wParam;
    };

  • 相关阅读:
    JVM常用参数整理
    mac系统使用Chrome浏览器https不自动保存密码
    JVM和JMM内存模型
    Chrome提示是否保存密码点击了否,导致没有自动保存密码
    解决Mac系统IDEA debug卡顿问题
    DBeaver的时区问题
    IDEA导航光标回退和前进快捷键失效
    Dubbo 2.6.0升级到2.7.3
    chrome浏览器备忘
    电脑导入mobi书籍文件到IPAD的方法
  • 原文地址:https://www.cnblogs.com/honeynm/p/4695878.html
Copyright © 2011-2022 走看看