Code:
#include <windows.h>
#include "WM_CHARH.h"
//#include "CreateWindowTwo.h"
//#include "WndProcH.h"
//Global Varibles
HWND g_hWnd;
HWND g_hWnd2;
char *WinApp = "WinApp";
char *WinApp2 = "WinApp2";
WNDCLASSEX wc;
WNDCLASSEX wc2;
//Function Prototypes
LRESULT WINAPI WndProc(HWND,UINT,WPARAM,LPARAM); //main windows function
void RegisterWindowClass(HINSTANCE hInstance);
void RegisterWindowClass2(HINSTANCE hInstance);
void CreateAppWindow(HINSTANCE hInstance);
void CreateAppWindow2(HINSTANCE hInstance);
WPARAM StartMessageLoop();
//Global Varibles
//HWND g_hWnd;
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
RegisterWindowClass(hInstance);
CreateAppWindow(hInstance);
RegisterWindowClass2(hInstance);
CreateAppWindow2(hInstance);
//ShowWindow(g_hWnd , SW_SHOWDEFAULT);
ShowWindow(g_hWnd , SW_NORMAL);
UpdateWindow(g_hWnd);
INT result = StartMessageLoop();
return result;
}
LRESULT CALLBACK WndProc(HWND hWnd ,UINT msg , WPARAM wParam , LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
ValidateRect(g_hWnd, NULL);
return 0;
case WM_COMMAND:
break;
case WM_KEYDOWN: break;
case WM_CHAR:
WM_CHARH(wParam , g_hWnd , g_hWnd2); break;
}
return DefWindowProc(hWnd , msg , wParam , lParam);
}
//RegisterWindow 1
void RegisterWindowClass(HINSTANCE hInstance)
{
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL , IDI_APPLICATION);
wc.hCursor = (HCURSOR)LoadCursor(NULL , IDC_ARROW); //Mouse Cursor
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //background window colour
wc.lpszMenuName = NULL;
wc.lpszClassName = WinApp;
wc.hIconSm = NULL;
RegisterClassEx(&wc);
}
void CreateAppWindow(HINSTANCE hInstance)
{
g_hWnd = CreateWindowEx(
NULL,
"WinApp",
"Basic Windows Application",
WS_OVERLAPPEDWINDOW,
//NULL,
100,
100,
648,
514,
GetDesktopWindow(),
NULL,
hInstance,
NULL
);
}
//RegisterWindow 2
void RegisterWindowClass2(HINSTANCE hInstance)
{
wc2.cbSize = sizeof(WNDCLASSEX);
wc2.style = CS_HREDRAW; /*| CS_VREDRAW | CS_OWNDC;*/
wc2.lpfnWndProc = WndProc;
wc2.cbClsExtra = 0;
wc2.cbWndExtra = 0;
wc2.hInstance = hInstance;
wc2.hIcon = LoadIcon(NULL , IDI_INFORMATION);
wc2.hCursor = (HCURSOR)LoadCursor(NULL , IDC_ARROW); //Mouse Cursor
//wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH+21); //background window colour
wc2.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH+1));
wc2.lpszMenuName = "new";
wc2.lpszClassName = WinApp2;
wc2.hIconSm = NULL;
RegisterClassEx(&wc2);
}
void CreateAppWindow2(HINSTANCE hInstance)
{
g_hWnd2 = CreateWindowEx(
NULL,
WinApp2,
"Basic Windows Application",
WS_OVERLAPPEDWINDOW | WS_CHILD,
1,
1,
500,
200,
g_hWnd,
NULL,
hInstance,
NULL
);
}
WPARAM StartMessageLoop()
{
MSG msg;
while(1)
{
if(PeekMessage(&msg , NULL , 0 , 0 , PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// UpdateWindow(g_hWnd);
// UpdateWindow(g_hWnd2);
//use idle time here
}
}
return msg.wParam;
}