Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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
 
**********************************************************
#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[^]
Posted 8-Jan-13 21:47pm
tel3124332
Edited 8-Jan-13 22:14pm
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The code you are showing here it is just the skeleton of the callback function. You have to subclass your window (this step is shown in the article) and implement (or copy) the actual callback.
  Permalink  
Comments
tel3124 at 9-Jan-13 4:04am
   
I'm sorry i attached my code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 1,310
1 Sergey Alexandrovich Kryukov 726
2 Tadit Dash 345
3 OriginalGriff 313
4 Manas Bhardwaj 215
0 Sergey Alexandrovich Kryukov 11,700
1 OriginalGriff 6,980
2 Peter Leow 4,915
3 Abhinav S 3,838
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid