Click here to Skip to main content
15,914,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Not using .Net Technology Pin
Hamid_RT30-Sep-08 22:01
Hamid_RT30-Sep-08 22:01 
QuestionEnumerating Files in a Folder Pin
Bram van Kampen30-Sep-08 14:14
Bram van Kampen30-Sep-08 14:14 
AnswerRe: Enumerating Files in a Folder Pin
Saurabh.Garg30-Sep-08 14:33
Saurabh.Garg30-Sep-08 14:33 
GeneralRe: Enumerating Files in a Folder Pin
Bram van Kampen30-Sep-08 15:04
Bram van Kampen30-Sep-08 15:04 
GeneralRe: Enumerating Files in a Folder Pin
Saurabh.Garg1-Oct-08 20:10
Saurabh.Garg1-Oct-08 20:10 
QuestionParent Forms Pin
Sarriss30-Sep-08 6:05
Sarriss30-Sep-08 6:05 
QuestionRe: Parent Forms Pin
Mark Salsbery30-Sep-08 6:25
Mark Salsbery30-Sep-08 6:25 
AnswerRe: Parent Forms Pin
Sarriss30-Sep-08 7:37
Sarriss30-Sep-08 7:37 
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";

//----------------------------------------------------------
//---------Create Parent Window-----------------------------

	RegWnd WinApp(hInstance, ClassName, WndProc);
	WinApp.Register();

	CreateWnd Wnd;
	Wnd.CreateParent(hInstance, ClassName, WndName);
	Wnd.show();
	hParent = Wnd;
//----------------------------------------------------------
//----------------------------------------------------------
Sleep(3000);
//----------------------------------------------------------
//---------Create Child Window-----------------------------
	
	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>

GeneralRe: Parent Forms Pin
Mark Salsbery30-Sep-08 8:31
Mark Salsbery30-Sep-08 8:31 
GeneralRe: Parent Forms Pin
Sarriss30-Sep-08 9:26
Sarriss30-Sep-08 9:26 
AnswerRe: Parent Forms Pin
led mike30-Sep-08 7:57
led mike30-Sep-08 7:57 
GeneralRe: Parent Forms Pin
Sarriss30-Sep-08 8:04
Sarriss30-Sep-08 8:04 
QuestionRe: Parent Forms Pin
Mark Salsbery30-Sep-08 8:32
Mark Salsbery30-Sep-08 8:32 
AnswerRe: Parent Forms Pin
Sarriss30-Sep-08 9:24
Sarriss30-Sep-08 9:24 
GeneralRe: Parent Forms Pin
Mark Salsbery30-Sep-08 9:30
Mark Salsbery30-Sep-08 9:30 
GeneralRe: Parent Forms Pin
Sarriss30-Sep-08 9:33
Sarriss30-Sep-08 9:33 
GeneralRe: Parent Forms Pin
Mark Salsbery30-Sep-08 9:58
Mark Salsbery30-Sep-08 9:58 
GeneralRe: Parent Forms Pin
Sarriss30-Sep-08 10:31
Sarriss30-Sep-08 10:31 
GeneralRe: Parent Forms Pin
Hamid_RT30-Sep-08 10:50
Hamid_RT30-Sep-08 10:50 
GeneralRe: Parent Forms Pin
Sarriss30-Sep-08 11:04
Sarriss30-Sep-08 11:04 
QuestionTracking application memory usage Pin
JoeSchmoe00730-Sep-08 5:25
JoeSchmoe00730-Sep-08 5:25 
AnswerRe: Tracking application memory usage Pin
Rick York30-Sep-08 6:17
mveRick York30-Sep-08 6:17 
GeneralRe: Tracking application memory usage Pin
JoeSchmoe00730-Sep-08 6:59
JoeSchmoe00730-Sep-08 6:59 
AnswerRe: Tracking application memory usage Pin
David Crow30-Sep-08 10:19
David Crow30-Sep-08 10:19 
AnswerRe: Tracking application memory usage Pin
Naveen30-Sep-08 14:03
Naveen30-Sep-08 14:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.