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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
///////////////// Function Prototypes ////////////////////
HWND wnd1TextBox, wnd2TextBox, wnd3TextBox;
/////////////// Global Variables: //////////////////////////////
bool openMainWnd, openchildWnd1, openchildWnd2, openchildWnd3 = false;
bool windowclass1registeredbefore, windowclass2registeredbefore, windowclass3registeredbefore, windowclass4registeredbefore = false;
enum windowtoopenenumt {none, ChildWindow1, ChildWindow2, ChildWindow3};
windowtoopenenumt windowtoopenenum=none;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nShowCmd )
{
bool endprogram = false;
WNDCLASSEXW childCls1;
WNDCLASSEXW childCls2;
WNDCLASSEXW childCls3;
HWND mainWndHnd;
HWND childWndHnd1;
HWND childWndHnd2;
HWND childWndHnd3;
// Creating Parent Window
MSG msg;
WNDCLASSEXW mainWnd;
mainWnd.cbSize ;
mainWnd.style
mainWnd.hbrBackground
mainWnd.hCursor
mainWnd.hInstance
mainWnd.lpszClassName
mainWnd.lpszMenuName
mainWnd.lpfnWndProc e
mainWnd.cbWndExtra = 0;
mainWnd.cbClsExtra = 0;
mainWnd.hIcon
mainWnd.hIconSm
if(!RegisterClassExW(&mainWnd))
{
int nResult=GetLastError();
MessageBox(NULL, "Window class creation failed", "Window Class Failed", MB_ICONERROR);
//return 0;
}
RegisterDialogClass(hInst);
mainWndHnd = CreateWindowExW("Main Window); // removed to meet 9000 characters requirements
if(!mainWndHnd)
{
int nResult=GetLastError();
MessageBox(NULL, "Window creation failed", "Window Creation Failed", MB_ICONERROR);
}
ShowWindow(mainWndHnd,nShowCmd);
bool endloop=false;
while (endloop == false)
{
if (GetMessage(&msg,NULL,0,0));
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (windowtoopenenum != none)
{
switch (windowtoopenenum)
{
case ChildWindow1:
// Open first windows
if (openchildWnd1 == false)
{
createChildWindow1(childCls1,childWndHnd1,hInst,nShowCmd);
SetWindowText(wnd1TextBox, loopStartTime());
cout << "child window 1 created" << endl;
// Open Second windows
if (openchildWnd2 == false)
{
createChildWindow2(childCls2,childWndHnd2,hInst,nShowCmd);
SetWindowText(wnd2TextBox, integerCal());
cout << "child window 2 created" << endl;
// Open third windows
if (openchildWnd3 == false)
{
//windowtoopenenum = ChildWindow3;
createChildWindow3(childCls3,childWndHnd3,hInst,nShowCmd);
SetWindowText(wnd3TextBox, integerCal());
cout << "child window 3 created" << endl;
}
else
{
SetWindowText(wnd3TextBox, integerCal());
UpdateWindow(childWndHnd3);
}
}
else
{
SetWindowText(wnd3TextBox, integerCal());
UpdateWindow(childWndHnd2);
}
}
else // if window is already open, then just update
{
SetWindowText(wnd1TextBox, loopStartTime());
UpdateWindow(childWndHnd1);
}
break;
}
break;
case ChildWindow3:
if (openchildWnd3==false)
{
createChildWindow3(childCls3,childWndHnd3,hInst,nShowCmd);
cout << "child window 2 created" << endl;
}
break;
}
windowtoopenenum = none;
}
if (openMainWnd==false && openchildWnd1==false && openchildWnd2==false && openchildWnd3==false )
endloop=true;
} // end while loop
MessageBox(NULL, "All Windows are closed. Program will now close.", "Message", MB_ICONINFORMATION);
return 0;
}
void createChildWindow1(WNDCLASSEXW& wc,HWND& hwnd,HINSTANCE hInst,int nShowCmd)
{
MSG Msg;
if (windowclass1registeredbefore == false)
{
// Creating Parent Window
MSG msg;
WNDCLASSEXW wc;
wc.cbSize ;
wc.style
wc.hbrBackground
wc.hCursor
wc.hInstance
wc.lpszClassName
wc.lpszMenuName
wc.lpfnWndProc e
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hIcon
wc.hIconSm
if(!RegisterClassExW(&wc))
{
int nResult=GetLastError();
MessageBox();
}
else
windowclass1registeredbefore=true;
}
CreateWindowExW(Wnd 1" ); // removed to meet 9000 characters requirements
if(!hwnd)
{
int nResult=GetLastError();
MessageBox();
}
ShowWindow(hwnd,nShowCmd);
}
void createChildWindow2()
{
// Basically the same code as in createChildWindow1, but replace all 1's with 2
}
void createChildWindow3()
{
// Basically the same code as in createChildWindow1, but replace all 1's with 3
}
//////////////////////////////////////////////////// WINDOW PROCEDURES ////////////////////////////////////////////////
LRESULT CALLBACK WindowProcedureMain(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_COMMAND:
switch(wp)
{
case IDA_MENU_EXIT:
DestroyWindow(hWnd);
break;
case IDA_MENU_ABOUT:
displayDialog(hWnd);
break;
case ID_OPEN_WINDOWS_BUTTON1:
windowtoopenenum = ChildWindow1;
break;
case ID_OPEN_WINDOWS_BUTTON2:
windowtoopenenum = ChildWindow2;
break;
} // end inner switch
break;
case WM_CREATE:
openMainWnd = true;
CreateWindowW(L"Part 1"); // removed to meet 9000 characters requirements
CreateWindowW(L"Part 2"); // removed to meet 9000 characters requirements
addMenu(hWnd);
break;
// Sent when a window is being destroyed.
case WM_DESTROY:
openMainWnd = false;
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd,msg,wp,lp);
} // end outer switch
} // end
LRESULT CALLBACK WindowProcedureChild1(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_CREATE:
openchildWnd1 = true;
addMenu(hwnd);
wnd1TextBox = CreateWindowW(); // removed to meet 9000 characters requirements
break;
case WM_DESTROY:
openchildWnd1 = false;
PostQuitMessage(0);
break;
case WM_COMMAND:
switch LOWORD(wParam)
{
case IDA_MENU_EXIT:
DestroyWindow(hwnd);
break;
case IDA_MENU_ABOUT:
displayDialog(hwnd);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK WindowProcedureChild2(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Basically the same code as in WindowProcedureChild1, but replace all 1's with 3
}
LRESULT CALLBACK WindowProcedureChild3(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Basically the same code as in WindowProcedureChild1, but replace all 1's with 3
}
| |