Vc6.0 display transparent PNG Images

Source: Internet
Author: User

When using VC as the interface, you will inevitably encounter the need to use images as the interface, but it is still very difficult to use vc6 to display transparent PNG. This article will introduce how to use the cximage class to implement static controls to display transparent PNG.

1. Create a dialog box-based MFC project

2. The new cmystatic class inherits cstatic. The source code is as follows:

MyStatic.h
#if !defined(AFX_MYSTATIC_H__384ED2FD_4979_4F49_A362_EF7AEFA836B4__INCLUDED_)#define AFX_MYSTATIC_H__384ED2FD_4979_4F49_A362_EF7AEFA836B4__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// MyStatic.h : header file///////////////////////////////////////////////////////////////////////////////// CMyStatic window#include ".\\include\\ximage.h"class CMyStatic : public CStatic{// Constructionpublic:CMyStatic();// Attributespublic:// Operationspublic:void SetImage(CxImage *);// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CMyStatic)//}}AFX_VIRTUAL// Implementationpublic:virtual ~CMyStatic();// Generated message map functionsprotected://{{AFX_MSG(CMyStatic)afx_msg void OnPaint();//}}AFX_MSGDECLARE_MESSAGE_MAP()private:CxImage *m_pImage;};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYSTATIC_H__384ED2FD_4979_4F49_A362_EF7AEFA836B4__INCLUDED_)
MyStatic.cpp
// MyStatic.cpp : implementation file//#include "stdafx.h"#include "MyStatic.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CMyStaticCMyStatic::CMyStatic(){}CMyStatic::~CMyStatic(){}BEGIN_MESSAGE_MAP(CMyStatic, CStatic)//{{AFX_MSG_MAP(CMyStatic)ON_WM_PAINT()//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMyStatic message handlersvoid CMyStatic::OnPaint() {CPaintDC dc(this); // device context for paintingRECT rect;this->GetClientRect(&rect);    RGBQUAD rgb=m_pImage->GetPixelColor(1,1);    m_pImage->IncreaseBpp(24);    m_pImage->SetTransIndex(24);    m_pImage->SetTransColor(rgb);m_pImage->Draw2(dc.m_hDC, rect);}void CMyStatic::SetImage(CxImage *pImage) {m_pImage = pImage;}

3. Add PNG resources to the project

4. In the header file

Cmystaticm_simg; (corresponding to the static control to display PNG)
Cximage m_ximage;

5. Add in oninitdialog

M_simg.setimage (& m_ximage );
M_ximage.loadresource (findresource (null, makeintresource (idr_png_logo), "PNG"), cximage_format_png );
M_simg.invalidate ();

In this way, the PNG image can be displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.