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
|
#include <windows.h>
LRESULT CALLBACK FirstWinProc(HWND, UINT, WPARAM, LPARAM); // First Window Procedure
LRESULT CALLBACK SecondWinProc(HWND, UINT, WPARAM, LPARAM); // Second Window Procedure
HINSTANCE g_hinst;
//Main
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR lpCmdLine, int nCmdShow)
{
// Begin Registering the main windows classes
// fw. First Window. FWmsg is the first window message queue
MSG FWmsg;
WNDCLASSW fw = {0};
fw.lpszClassName = L"FirstWindow";
fw.hInstance = hInstance;
fw.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
fw.lpfnWndProc = FirstWinProc;
fw.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClassW(&fw);
//sw. First Window. SWmsg is the Second window message queue
MSG SWmsg;
WNDCLASSW sw = {0};
sw.lpszClassName = L"SecondWindow";
sw.hInstance = hInstance;
sw.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
sw.lpfnWndProc = SecondWinProc;
sw.hCursor = LoadCursor(0, IDC_HAND);
RegisterClassW(&sw);
// End of Registering Window Classes
CreateWindowW(fw.lpszClassName, L"First Window", //Display First Window
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 300, 300, 0, 0, hInstance, 0);
CreateWindowW(sw.lpszClassName, L"Second Window", //Display Second Window
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
300, 0, 300, 300, 0, 0, hInstance, 0);
// Message Loop For First Window
while( GetMessage(&FWmsg, NULL, 0, 0)) {
TranslateMessage(&FWmsg);
DispatchMessage(&FWmsg);
}
return (int) FWmsg.wParam;
// Message Loop For Second Window
while( GetMessage(&SWmsg, NULL, 0, 0)) {
TranslateMessage(&SWmsg);
DispatchMessage(&SWmsg);
}
return (int) SWmsg.wParam;
}
// Window Procedure For First Window
LRESULT CALLBACK FirstWinProc(HWND hwnd, UINT FWinSW,
WPARAM wParam, LPARAM lParam)
{
//Start of First Window Switch FWinSW
switch(FWinSW)
{
case WM_CREATE:
CreateWindowW(L"button", L"Change Title",
WS_VISIBLE | WS_CHILD ,
20, 50, 100, 25,
hwnd, (HMENU) 1, NULL, NULL);
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1) {
SetWindowTextW(hwnd, L"Title Changed");
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
// End of First Window Switch
return DefWindowProcW(hwnd, FWinSW, wParam, lParam);
}
// End of Window Procedure
// Window Procedure For Second Window SWinSW
LRESULT CALLBACK SecondWinProc(HWND hwnd, UINT SWinSW,
WPARAM wParam, LPARAM lParam)
{
//Start of Second Window Switch
switch(SWinSW)
{
case WM_CREATE:
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_COMMAND:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
// End of Second Window Switch
return DefWindowProcW(hwnd, SWinSW, wParam, lParam);
}
|