Click here to Skip to main content
15,896,539 members

how to load an image in mainframe window's client area

tel3124 asked:

Open original thread
how to load an image in mainframe window's client area
i found the solution in code procect but it's working under the VS2005 version
i'm using VS2008 (2005 style, MDI project)
Do you have any solution??

Under Callback Function is not called in my project

**********************************************************
C++
#include "stdafx.h"
#include "afxwinappex.h"
#include "skin4.h"
#include "MainFrm.h"

#include "ChildFrm.h"
#include "skin4Doc.h"
#include "skin4View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// Cskin4App

BEGIN_MESSAGE_MAP(Cskin4App, CWinAppEx)
	ON_COMMAND(ID_APP_ABOUT, &Cskin4App::OnAppAbout)
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
END_MESSAGE_MAP()


// Cskin4App construction

HBITMAP hBkBmp;	// Bk bitmap
WNDPROC pfnOldWndProc;	// old wnd proc

LRESULT CALLBACK pfnNewWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
	HDC hdc = (HDC)wParam;
	HDC hcompdc;
	RECT rect;

	switch (uMsg)	{
	case WM_SIZE :
		SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)GetDC(hwnd), 0);
		return 1;
	case WM_ERASEBKGND :
		//CallWindowProc(pfnOldWndProc, hwnd, uMsg, wParam, lParam);

		hcompdc = CreateCompatibleDC(hdc);
		SelectObject(hcompdc, hBkBmp);
		GetClientRect(hwnd, &rect);
		//bitmap dimensions are static for better performance (I assume
		//background image is statically loaded)

		if (FALSE == StretchBlt(hdc, rect.left, rect.top, rect.right, rect.bottom,
			hcompdc, 0, 0, 600, 377, SRCCOPY))
			MessageBox(hwnd, "error", "while StretchBlt", MB_OK);

		DeleteDC(hcompdc);
		return 1;
	default :
		return CallWindowProc(pfnOldWndProc, hwnd, uMsg, wParam, lParam);
	}
}

BOOL Cskin4App::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinAppEx::InitInstance();

	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}
	AfxEnableControlContainer();
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)

	InitContextMenuManager();

	InitKeyboardManager();

	InitTooltipManager();
	CMFCToolTipInfo ttParams;
	ttParams.m_bVislManagerTheme = TRUE;
	theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
		RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(IDR_skin4TYPE,
		RUNTIME_CLASS(Cskin4Doc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(Cskin4View));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
	{
		delete pMainFrame;
		return FALSE;
	}
	m_pMainWnd = pMainFrame;
	// call DragAcceptFiles only if there's a suffix
	//  In an MDI app, this should occur immediately after setting m_pMainWnd


	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);



	
	hBkBmp = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
	if (hBkBmp == NULL)
		MessageBox(NULL, "Error", "Bitmap could not be loaded !!!", MB_OK);

	HWND hMain = pMainFrame->GetWindow(GW_CHILD)->GetSafeHwnd();
	pfnOldWndProc = (WNDPROC)GetWindowLong(hMain, GWL_WNDPROC);
	SetWindowLong(hMain, GWL_WNDPROC, (LONG)pfnNewWndProc);
	/**********************************************************************/


Drawing Image on MDI Main Frame background[^]
Tags: C++

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900