1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#ifndef WIN32_HPP
#define WIN32_HPP
#include <windows.h>
#include <windowsx.h>
RECT DesktopRect()
{
RECT desktopRect;
HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktopRect);
return desktopRect;
}
class Window
{
private:
HWND hWindow;
HWND ParentWindow;
WNDCLASSEX WindowClass;
MSG message;
LPCSTR WindowT;
int CmdShow;
int default_x;
int default_y;
int x;
int y;
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
public:
UINT GetMessages()
{
while(GetMessage((&this->message),NULL,0,0)
{
TranslateMessage(&message);
DispatchMessage(&message);
return message.message;
}
}
void QuitWindow()
{
DestroyWindow(hWindow);
}
Window(int CmdShow, LPCSTR ClassName, LPCSTR WindowTitle,
UINT WindowProprieties, HINSTANCE Instance, LPCSTR Cursor = IDC_ARROW, int x = 0, int y = 0, int y_axis = DesktopRect().bottom , int x_axis = DesktopRect().right, HWND Parent = NULL)
{
this->CmdShow = CmdShow;
ParentWindow = Parent;
default_x = x;
default_y = y;
this->y = y_axis;
this->x = x_axis;
WindowT = WindowTitle;
ZeroMemory(&WindowClass, sizeof(WNDCLASSEX));
WindowClass.cbSize = sizeof(WNDCLASSEX);
WindowClass.style = WindowProprieties;
WindowClass.lpfnWndProc = WindowProc;
WindowClass.hInstance = Instance;
WindowClass.hCursor = LoadCursor(NULL, Cursor);
WindowClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
WindowClass.lpszClassName = ClassName;
RegisterClassEx(&WindowClass);
}
UINT Run()
{
this->hWindow = CreateWindowEx(NULL, WindowClass.lpszClassName, WindowT, WS_OVERLAPPEDWINDOW, this->default_x, this->default_y,this->x,this->y, this->ParentWindow, 0, 0, NULL);
ShowWindow(this->hWindow, this->CmdShow);
return this->GetMessages();
}
~Window()
{
CloseWindow(hWindow);
PostQuitMessage(0);
}
bool IsCloseTried()
{
if(this->message.message == WM_QUIT)
{
return true;
}
else return false;
}
};
#endif //WIN32_HPP
|