Untitled

 avatar
unknown
plain_text
4 years ago
1.4 kB
3
Indexable
#include <windows.h>

class Widget 
{
  HWND hWnd;
  int width, height, x_pos, y_pos;

  static LRESULT CALLBACK Procedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  {
      switch(msg)
      {
        case WM_DESTROY:
          PostQuitMessage(0);
          break;
      }

    return DefWindowProcW(hWnd, msg, wParam, lParam);
  }

  public:
    Widget(int width, int height, int x_pos, int y_pos)
    {
      WNDCLASSEXW wc = {0};
      wc.cbSize = sizeof(WNDCLASSEXW);
      wc.lpszClassName = L"Widget";
      wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc   = Procedure;
      wc.hCursor       = LoadCursor(0, IDC_ARROW);

      RegisterClassExW(&wc);

      CreateWindowExW(NULL, wc.lpszClassName, L"Windows",
                  WS_OVERLAPPEDWINDOW,
                  x_pos, y_pos, width, height, NULL, NULL, NULL, NULL);      
    }

    void show()
    {
      ShowWindow(hWnd, SW_SHOW);
      UpdateWindow(hWnd);
    }
};

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PWSTR lpCmdLine, int nCmdShow) {
    MSG  msg;

    Widget widget(640, 360, 0, 0);
    widget.show();    

    while (GetMessage(&msg, NULL, 0, 0)) {
  
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}

Editor is loading...