Advertisement
Guest User

Untitled

a guest
Nov 6th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include "GUIMain.h"
  2.  
  3. #include <Windows.h>
  4.  
  5. #define AS2CmdGenerate 1
  6. #define AS2CmdQuit     2
  7.  
  8. GUIMain::GUIMain(HINSTANCE hInstance)
  9. {
  10.     this->hInstance = hInstance;
  11. }
  12.  
  13. GUIMain::~GUIMain()
  14. {
  15.  
  16. }
  17.  
  18. void GUIMain::Register()
  19. {
  20.     WNDCLASSEX wc;
  21.  
  22.     wc.cbSize        = sizeof(WNDCLASSEX);
  23.     wc.cbClsExtra    = 0;
  24.     wc.cbWndExtra    = 0;
  25.     wc.hInstance     = hInstance;
  26.  
  27.     wc.lpszClassName = TEXT("AS2MainWindow");
  28.    
  29.     wc.lpfnWndProc   = WndProcA;
  30.  
  31.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  32.     wc.hbrBackground = (HBRUSH)GetStockObject(COLOR_BACKGROUND);
  33.    
  34.     wc.hCursor       = LoadCursor(0, IDC_ARROW);
  35.     wc.hIcon         = LoadIcon(hInstance, IDI_APPLICATION);
  36.     wc.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
  37.  
  38.     wc.cbWndExtra    = sizeof(GUIMain *);
  39.  
  40.     wc.lpszMenuName  = 0;
  41.  
  42.     RegisterClassEx(&wc);
  43. }
  44.  
  45. bool GUIMain::Create()
  46. {
  47.     hWnd = CreateWindowEx(0, TEXT("AS2MainWindow"),
  48.                           TEXT("AS2"),
  49.                           WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
  50.                           CW_USEDEFAULT, CW_USEDEFAULT,
  51.                           824, 350,
  52.                           0, 0,
  53.                           hInstance, 0);
  54.  
  55.     return (bool)hWnd;
  56. }
  57.  
  58. WPARAM GUIMain::Show(int nCmdShow)
  59. {
  60.     ShowWindow(hWnd, nCmdShow);
  61.  
  62.     UpdateWindow(hWnd);
  63.  
  64.     MSG msg;
  65.    
  66.     while (GetMessage(&msg, 0, 0, 0))
  67.     {
  68.         TranslateMessage(&msg);
  69.         DispatchMessage(&msg);
  70.     }
  71.  
  72.     return msg.wParam;
  73. }
  74.  
  75. LRESULT CALLBACK GUIMain::wndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  76. {
  77.     switch(Msg)
  78.     {
  79.         case WM_COMMAND:
  80.             handleCommand(LOWORD(wParam));
  81.             return 0;
  82.        
  83.         case WM_CREATE:
  84.             initialise(hWnd);
  85.             return 0;
  86.         case WM_DESTROY:
  87.             PostQuitMessage(0);
  88.             return 0;
  89.  
  90.         default:
  91.             return DefWindowProc(hWnd, Msg, wParam, lParam);
  92.     }
  93.  
  94.     return 0;
  95. }
  96.  
  97. LRESULT CALLBACK GUIMain::WndProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  98. {
  99.     if (Msg == WM_NCCREATE)
  100.     {
  101.         SetWindowLong(hWnd, GWL_USERDATA, (long) ((LPCREATESTRUCT)lParam)->lpCreateParams);
  102.         SetWindowLong(hWnd, GWL_WNDPROC,  (long) WndProcB);
  103.     }
  104.  
  105.     GUIMain *g = (GUIMain *)GetWindowLong(hWnd, GWL_USERDATA);
  106.  
  107.     if (g)
  108.         return g->wndProc(hWnd, Msg, wParam, lParam);
  109.     else
  110.         return DefWindowProc(hWnd, Msg, wParam, lParam);
  111. }
  112.  
  113. LRESULT CALLBACK GUIMain::WndProcB(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  114. {
  115.     return ((GUIMain *)GetWindowLong(hWnd, GWL_USERDATA))->wndProc(hWnd, Msg, wParam, lParam);
  116. }
  117.  
  118. void GUIMain::initialise(HWND hWnd)
  119. {
  120.     this->hWnd = hWnd;
  121.  
  122.     cmdGenerate = CreateWindowEx(0, TEXT("BUTTON"), TEXT("&Generate..."),
  123.                                WS_VISIBLE | WS_CHILD,
  124.                                6, 6, 150, 25,        
  125.                                hWnd, (HMENU)AS2CmdGenerate, 0, 0);
  126.  
  127.     cmdQuit     = CreateWindowEx(0, TEXT("BUTTON"), TEXT("&Quit"),
  128.                                WS_VISIBLE | WS_CHILD,
  129.                                6, 37, 150, 25,        
  130.                                hWnd, (HMENU)AS2CmdQuit, 0, 0);
  131. }
  132.  
  133. void GUIMain::handleCommand(int cmd)
  134. {
  135.     switch (cmd)
  136.     {
  137.         case AS2CmdQuit:
  138.             PostQuitMessage(0);
  139.             return;
  140.  
  141.         default:
  142.             return;
  143.     }
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement