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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#define UNICODE 1
#include "windows.h"
//#define _USE_MATH_DEFINES
//#include "stdio.h"
//#include "math.h"
//#include <gl/gl.h>
//#include <gl/glu.h>
//#pragma comment(lib,"opengl32.lib")
//#pragma comment(lib,"glu32.lib")
#define tocString TCHAR*
LRESULT CALLBACK WndProc(HWND Window,unsigned int Message, WPARAM wParam, LPARAM lParam);
class tocApplicationWindow
{
private:
WNDCLASSEX WindowClass;
HWND WindowHandle;
bool Registered;
DWORD WindowStyle;
DWORD WindowStyleEx;
tocString ClassName;
HINSTANCE Application;
int Width;
int Height;
int WindowShow;
RECT WndRealSize;
tocString WndTitle;
public:
//Destroy window
bool Destroy()
{
if (WindowHandle!=0)
{
DestroyWindow(WindowHandle);
return true;
}
return false;
}
//Register window
bool Register()
{
if (!RegisterClassEx(&WindowClass) && !Registered)
{
return false;
}
Registered=true;
return true;
}
bool Create()
{
if (WindowHandle==0 && Registered==true)
{
WndRealSize.left=(long)0;
WndRealSize.right=(long)Width;
WndRealSize.top=(long)0;
WndRealSize.bottom=(long)Height;
AdjustWindowRectEx(&WndRealSize,WindowStyle,false,WindowStyleEx);
WindowHandle = CreateWindowEx(WindowStyleEx,ClassName,WndTitle,WindowStyle,0, 0,
WndRealSize.right-WndRealSize.left,WndRealSize.bottom-WndRealSize.top,0,0,Application,0);
if (WindowHandle==0)
{
MessageBox(WindowHandle,TEXT("FAIL"),TEXT("FAIL"),MB_OK);
}
}
else
{
return false;
}
return true;
}
bool Show()
{
ShowWindow(WindowHandle,WindowShow);
UpdateWindow(WindowHandle);
return true;
}
//Class initializion
tocApplicationWindow(tocString str,HINSTANCE Instance,int Show)
{
if (str!=0 && Instance !=0)
{
WndTitle=TEXT("OH HAI DER");
Registered=false;
WindowShow=Show;
Width=500;
Height=500;
ClassName=str;
Application=Instance;
WindowHandle=0;
WindowClass.cbSize=sizeof(WNDCLASSEX);
WindowClass.cbClsExtra=0;
WindowClass.cbWndExtra=0;
WindowClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
WindowClass.hCursor=LoadCursor(Instance,IDC_ARROW);
WindowClass.hIcon=LoadIcon(Instance,IDI_APPLICATION);
WindowClass.hIconSm=LoadIcon(Instance,IDI_WINLOGO);
WindowClass.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
WindowClass.lpfnWndProc=WndProc;
WindowClass.lpszClassName=ClassName;
WindowClass.lpszMenuName=0;
WindowStyle=WS_OVERLAPPEDWINDOW; // | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
WindowStyleEx=0;
}
}
//Class destructor
~tocApplicationWindow()
{
Destroy();
}
};
int WINAPI WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, char* CommandLine, int Show)
{
tocString Program=TEXT("OH HAI");
tocApplicationWindow Wnd=tocApplicationWindow(Program,Instance,Show);
Wnd.Register();
Wnd.Create();
Wnd.Show();
MSG msg;
bool isDone=false;
while (!isDone)
{
if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
{
if (msg.message == WM_QUIT) // do we receive a WM_QUIT message?
{
isDone = true; // if so, time to quit the application
}
else
{
TranslateMessage(&msg); // translate and dispatch to event queue
DispatchMessage(&msg);
}
}
Sleep(1);
}
Wnd.Destroy();
return 0;
}
LRESULT CALLBACK WndProc(HWND Window,unsigned int Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(Window, Message, wParam, lParam);
break;
}
return 0;
}
| |