Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "GUIMain.h"
- #include <Windows.h>
- #define AS2CmdGenerate 1
- #define AS2CmdQuit 2
- GUIMain::GUIMain(HINSTANCE hInstance)
- {
- this->hInstance = hInstance;
- }
- GUIMain::~GUIMain()
- {
- }
- void GUIMain::Register()
- {
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.lpszClassName = TEXT("AS2MainWindow");
- wc.lpfnWndProc = WndProcA;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.hbrBackground = (HBRUSH)GetStockObject(COLOR_BACKGROUND);
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
- wc.cbWndExtra = sizeof(GUIMain *);
- wc.lpszMenuName = 0;
- RegisterClassEx(&wc);
- }
- bool GUIMain::Create()
- {
- hWnd = CreateWindowEx(0, TEXT("AS2MainWindow"),
- TEXT("AS2"),
- WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
- CW_USEDEFAULT, CW_USEDEFAULT,
- 824, 350,
- 0, 0,
- hInstance, 0);
- return (bool)hWnd;
- }
- WPARAM GUIMain::Show(int nCmdShow)
- {
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- MSG msg;
- while (GetMessage(&msg, 0, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK GUIMain::wndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
- {
- switch(Msg)
- {
- case WM_COMMAND:
- handleCommand(LOWORD(wParam));
- return 0;
- case WM_CREATE:
- initialise(hWnd);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- default:
- return DefWindowProc(hWnd, Msg, wParam, lParam);
- }
- return 0;
- }
- LRESULT CALLBACK GUIMain::WndProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
- {
- if (Msg == WM_NCCREATE)
- {
- SetWindowLong(hWnd, GWL_USERDATA, (long) ((LPCREATESTRUCT)lParam)->lpCreateParams);
- SetWindowLong(hWnd, GWL_WNDPROC, (long) WndProcB);
- }
- GUIMain *g = (GUIMain *)GetWindowLong(hWnd, GWL_USERDATA);
- if (g)
- return g->wndProc(hWnd, Msg, wParam, lParam);
- else
- return DefWindowProc(hWnd, Msg, wParam, lParam);
- }
- LRESULT CALLBACK GUIMain::WndProcB(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
- {
- return ((GUIMain *)GetWindowLong(hWnd, GWL_USERDATA))->wndProc(hWnd, Msg, wParam, lParam);
- }
- void GUIMain::initialise(HWND hWnd)
- {
- this->hWnd = hWnd;
- cmdGenerate = CreateWindowEx(0, TEXT("BUTTON"), TEXT("&Generate..."),
- WS_VISIBLE | WS_CHILD,
- 6, 6, 150, 25,
- hWnd, (HMENU)AS2CmdGenerate, 0, 0);
- cmdQuit = CreateWindowEx(0, TEXT("BUTTON"), TEXT("&Quit"),
- WS_VISIBLE | WS_CHILD,
- 6, 37, 150, 25,
- hWnd, (HMENU)AS2CmdQuit, 0, 0);
- }
- void GUIMain::handleCommand(int cmd)
- {
- switch (cmd)
- {
- case AS2CmdQuit:
- PostQuitMessage(0);
- return;
- default:
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement