Using GDI + to invoke PNG pictures in VC6.0 to implement a translucent gradient effect window

Source: Internet
Author: User

I. Overview

The application of GDI + makes the graphic image programming easier, this paper takes a dialog-based clock program as an example, calls the *.png picture to implement the translucent gradient window in the VC6.0, the program realizes both the pointer and the digital clock display mode. The window implements a semitransparent gradient window, drag the window without moving the rectangle, hide the Taskbar form button, and so on.

The effect chart is as follows:

Figure A program after the execution and WINDOWXP desktop background effect diagram

Ii. preparatory work

1, the picture resources preparation work. First, in Photoshop, edit the background of the clock, the hour hand, the minute hand, and all the pictures of the digital clock display, as shown in the following illustration: Save these pictures as a. png format with transparent channels (the background can be transparently tuned when the GDI + call is displayed). So the picture resources in the program are ready.

2, the following start to do the VC6.0 under the basic preparations for the work.

(1), download Gdiplus forVC6.0 SDK, (total two trillion more)

(2), in the C Set up folder "GDI +" will be a copy of the development package inside, that is, set up the following path, so that the example code to compile smoothly (of course, you can put to any of your favorite places, as long as in your project correctly include the path!)! )。

C:\GDI+\Includes
C:\GDI+\Lib
C:\GDI+\gdiplus.dll

(3) Add the settings for the GDI + environment in StdAfx.h

#define UNICODE
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include "c:\gdi+\includes\gdiplus.h" ////请修改为你的头文件路径
using namespace Gdiplus;
#pragma comment(lib, "c:\\gdi+\\lib\\gdiplus.lib") ////请修改为你的.lib文件路径

(4) Add the following code in the InitInstance () of the GDIPClock.cpp Edit app to initialize GDI +

GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
......
//在对话框程序结束后
//关闭gdiplus的环境
GdiplusShutdown(gdiplusToken);

Third, the implementation of the whole process of procedure

1, create a dialog box based project, where the name is Gdipclock

2. Define all class member variables in GDIPClockDlg.h, including all picture's pointer and picture's long width size information.

    Image *m_pImageClock;
    Image *m_pImageClock1;
    Image *m_pImageHHour;
    Image *m_pImageHMinu;
    Image *m_pImageHSec;
    Image *m_pImageNum;
    int m_BakWidth , m_BakHeight ;
    int m_HourWidth, m_HourHeight;
    int m_MinuWidth , m_MinuHeight;
    int m_SecWidth , m_SecHeight ;
    HINSTANCE hFuncInst ;
    Typedef BOOL (WINAPI*MYFUNC)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,
COLORREF,BLENDFUNCTION*,DWORD);     
    MYFUNC UpdateLayeredWindow;

In this step you need to specifically note that in creating a transparent window you need to invoke a Windows API function Updatelayeredwindow (), This function is stated in the SDK version of. NET above, but it is called from "User32.dll" in the VC6.0 to invoke either the High version SDK that downloads more than 200 megabytes, or from the dynamic link library "User32.dll". The latter three of these definitions are intended for this purpose.

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.