如何在大型机窗口的客户区加载图像 [英] how to load an image in mainframe window's client area

查看:49
本文介绍了如何在大型机窗口的客户区加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在大型机窗口的客户区加载图像

i在代码procect中找到解决方案,但它在VS2005版本下运行

i'使用VS2008(2005风格,MDI项目)

你有什么解决方案吗?



在Callback下我没有调用函数项目



********************************* *************************

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);
	/**********************************************************************/





在MDI主框架背景上绘制图像 [ ^ ]

推荐答案

这里显示的代码只是回调函数的骨架。您必须对窗口进行子类化(此步骤显示在文章中)并实现(或复制)实际的回调。
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.


这篇关于如何在大型机窗口的客户区加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆