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 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| #include "RenderTest.hpp"
#define WIN_H 600
#define WIN_W 600
#define WIN_H_CHILD 50
#define WIN_W_CHILD 50
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
// the WindowProc function prototype
LRESULT CALLBACK WindowProcChild(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
void initClass (WNDCLASSEX & wc, WNDPROC winProc, char * className, HINSTANCE hInstance);
// the entry point for any Windows program
int WINAPI MyCreateWindow(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow,
int nbChild)
{
// the handle for the window, filled by a function
HWND hWnd;
// this struct holds information for the window class
WNDCLASSEX wc;
// clear out the window class for use
ZeroMemory(&wc, sizeof(WNDCLASSEX));
initClass(wc, (WNDPROC)WindowProc, "WindowClass1", hInstance);
if (!RegisterClassEx(&wc)) return 0;
// this struct holds information for the window class
WNDCLASSEX wc2;
// clear out the window class for use
ZeroMemory(&wc2, sizeof(WNDCLASSEX));
initClass(wc2, (WNDPROC)WindowProcChild, "WindowClass1", hInstance);
if (!RegisterClassEx(&wc2))
{
unsigned long tmp = GetLastError();
return 0;
}
// create the window and use the result as the handle
hWnd = CreateWindowEx(NULL,
"WindowClass1", // name of the window class
"Our First Windowed Program", // title of the window
WS_OVERLAPPEDWINDOW, // window style
300, // x-position of the window
300, // y-position of the window
WIN_W, // width of the window
WIN_H, // height of the window
NULL, // we have no parent window, NULL
NULL, // we aren't using menus, NULL
hInstance, // application handle
NULL); // used with multiple windows, NULL
int maxCol = WIN_W / WIN_W_CHILD;
int nbCol = 0;
int nbRow = 0;
for (int i = 0; i < nbChild; i++) {
int posX = nbCol * WIN_W_CHILD;
int posY = nbRow * WIN_H_CHILD;
HWND child = CreateWindowEx(NULL,
"WindowClass2", // name of the window class
"Our Second Windowed Program" , // title of the window
WS_CHILD | WS_BORDER | WS_OVERLAPPED, // window style // WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,// WS_CLIPCHILDREN
posX, // x-position of the window
posY, // y-position of the window
WIN_W_CHILD, // width of the window
WIN_H_CHILD, // height of the window
hWnd, // we have parent window
NULL, // we aren't using menus, NULL
hInstance, // application handle
NULL); // used with multiple windows, NULL
// display the window on the screen
ShowWindow(child, WS_VISIBLE);
if (nbCol == maxCol) {
nbCol = 0;
nbRow++;
}
}
ShowWindow(hWnd, nCmdShow);
// enter the main loop:
// this struct holds Windows event messages
MSG msg;
// wait for the next message in the queue, store the result in 'msg'
// Enter the infinite message loop
while(TRUE)
{
// Check to see if any messages are waiting in the queue
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// If the message is WM_QUIT, exit the while loop
if (msg.message == WM_QUIT)
break;
// Translate the message and dispatch it to WindowProc()
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Run game code here
// ...
// ...
}
// return this part of the WM_QUIT message to Windows
return msg.wParam;
}
// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// sort through and find what code to run for the message given
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
} break;
}
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}
// this is the main message handler for the child program
LRESULT CALLBACK WindowProcChild(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// sort through and find what code to run for the message given
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
} break;
}
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}
void initClass (WNDCLASSEX & wc, WNDPROC winProc, char * className, HINSTANCE hInstance)
{
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = winProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW);
wc.lpszClassName = className;
} |
Partager