I shall Paste The Whole thing shall I,
//RegWnd.h
#pragma once
#include <windows.h>
#include "resource.h"
class RegWnd
{
public:
RegWnd(HINSTANCE hInstance, char *ClassName, WNDPROC WndProc, LPCTSTR MenuName = NULL);
void Register();
protected:
WNDCLASSEX wc;
};</windows.h>
//RegWnd.cpp
#include "RegWnd.h"
RegWnd::RegWnd(HINSTANCE hInstance, char *ClassName, WNDPROC WndProc, LPCTSTR MenuName)
{
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = static_cast<hicon>(LoadImage( hInstance,
MAKEINTRESOURCE(IDI_MAIN),
IMAGE_ICON,
255,
255,
LR_DEFAULTCOLOR));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = static_cast<hbrush>(GetStockObject(WHITE_BRUSH));
wc.lpszMenuName = MenuName;
wc.lpszClassName = ClassName;
wc.hIconSm = static_cast<hicon>(LoadImage( hInstance,
MAKEINTRESOURCE(IDI_MAIN),
IMAGE_ICON,
16,
16,
LR_DEFAULTCOLOR));
}
void RegWnd::Register()
{
RegisterClassEx(&wc);
}</hicon></hbrush></hicon>
//CreateWnd.h
#pragma once
#include <windows.h>
class CreateWnd
{
public:
CreateWnd();
HWND CreateParent(HINSTANCE hInstance,
LPCTSTR ClassName,
LPCTSTR WndName,
HWND parent = NULL,
DWORD dStyle = WS_OVERLAPPEDWINDOW,
DWORD dXStyle = 0L,
int xPos = CW_USEDEFAULT,
int yPos = CW_USEDEFAULT,
int Width = CW_USEDEFAULT,
int height = CW_USEDEFAULT);
HWND CreateChild(HINSTANCE hInstance,
LPCTSTR ClassName,
LPCTSTR WndName,
HWND parent,
DWORD dStyle = WS_OVERLAPPEDWINDOW,
DWORD dXStyle = 0L,
int xPos = 800,
int yPos = 450,
int Width = 200,
int height = 200);
BOOL show(int dCmdShow = SW_SHOWNORMAL);
BOOL showChild(int dCmdShow = SW_SHOWNORMAL);
operator HWND();
protected:
HWND hWnd;
};</windows.h>
//CreateWnd.cpp
#include "CreateWnd.h"
CreateWnd::CreateWnd()
{
hWnd = NULL;
}
HWND CreateWnd::CreateParent(HINSTANCE hInstance, LPCTSTR ClassName, LPCTSTR WndName, HWND parent, DWORD dStyle, DWORD dXStyle, int xPos, int yPos, int Width, int height)
{
hWnd = CreateWindowEx(dXStyle,ClassName,WndName,dStyle,xPos,yPos,Width,height,parent,NULL,hInstance,NULL);
if(hWnd == NULL)
{
MessageBox(NULL, TEXT("Create Window Failed!"), TEXT("Error"), MB_ICONEXCLAMATION|MB_OK);
return 0;
}else{
return hWnd;
}
return NULL;
}
HWND CreateWnd::CreateChild(HINSTANCE hInstance, LPCTSTR ClassName, LPCTSTR WndName, HWND parent, DWORD dStyle, DWORD dXStyle, int xPos, int yPos, int Width, int height)
{
hWnd = CreateWindowEx(dXStyle,ClassName,WndName,dStyle,xPos,yPos,Width,height,parent,NULL,hInstance,NULL);
if(hWnd == NULL)
{
MessageBox(NULL, TEXT("Create Window Failed!"), TEXT("Error"), MB_ICONEXCLAMATION|MB_OK);
return 0;
}else{
return hWnd;
}
return NULL;
}
BOOL CreateWnd::show(int dCmdShow)
{
if(ShowWindow(hWnd, dCmdShow) && UpdateWindow(hWnd))
{
return TRUE;
}
return FALSE;
}
BOOL CreateWnd::showChild(int dCmdShow)
{
if(ShowWindow(hWnd, dCmdShow) && UpdateWindow(hWnd))
{
return TRUE;
}
return FALSE;
}
CreateWnd::operator HWND()
{
return hWnd;
}
And Finally Main.cpp
#include <windows.h>
#include "RegWnd.h"
#include "CreateWnd.h"
HWND hParent;
HWND hChild;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK WndProcChild(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
break;
case WM_CLOSE:
break;
case WM_DESTROY:
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
char *ClassName = "MainClass";
char *WndName = "Sarriss";
char *ChildClassName = "ChildClass";
char *ChildWndName = "Sarriss";
RegWnd WinApp(hInstance, ClassName, WndProc);
WinApp.Register();
CreateWnd Wnd;
Wnd.CreateParent(hInstance, ClassName, WndName);
Wnd.show();
hParent = Wnd;
Sleep(3000);
RegWnd WinAppChild(hInstance, ChildClassName, WndProcChild);
WinAppChild.Register();
CreateWnd WndChild;
WndChild.CreateChild(hInstance, ChildClassName, ChildWndName, hParent);
WndChild.show();
hChild = WndChild;
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}</windows.h>
|