Dynamic icon

zhaozj2021-02-11  160

Dynamic icon

I have seen this long-awaited Windows monotonous and standard interface, I don't know if you will feel some annoyance. In fact, you only need to change slightly, you can make your application a lot of color. In a popular words, it is Cool extreme. This article will introduce a method of implementing a dynamic icon in the window title bar, with a small amount of code, you can get a wonderful effect. Just like the superkartte the icon that is constantly turning at runtime. Let's get started below. We will use Visual C to implement it. First, based on C 's object-oriented design idea, we should establish a class to manage the creation, operation, destruction of class objects, etc. But don't forget to use Visual C , it is necessary to be good at using Microsoft's MFC (basic class library), in MFC, encapsulates a lot of common class and some Windows API functions. We should thank these outstanding programmers, thank you for a lot of work for us. Due to their efforts, many complex problems become simple. At this point, we can find that there is a class called CImage List in the MFC to help us very helpful. This class is used to effectively manage a series of similar bitmaps or icons, which implements the general image list control of Windows. We should include an object of this class as a data member in the class of our application, and then complete some additional work. The relevant data members and members of the CIMAGELIST class we have to use are as follows: m_himagelist is a handle Create function that contains a graphic list related to this object to initialize an image lin list and connect it to the CImageList class. A parameter is a bitmap resource ID value containing an icon. The second parameter refers to a bitmap of 16 × 16 points. The third parameter uses the default value, and the fourth parameter is the RGB value of the color. The specific practices are as follows: 1. Add header files and implementations to your own project. Second, create a needed bitmap resource (four 16 × 16 pixel points icons) Third, the beginning of the header file in the main frame class # Include "MyActive.h" four, add the following data member cmyactive m_active; // joining the class object uint m_time; // Set time 5, add the following code m-active.setimagelist (IDB) -Anim-imglist, 4, rgb (0, 0)); the first parameter of the above function is the resource ID value, the second is the number of similar images, the third parameter setting color m_time = this-> setTimer (99, 500, null); The above function is used to generate a timer six. Use the classwizard to increase the WM_DESTROY message for the main frame class, add the onDestroy () member function, add the following statement, recycle system resources. CframeWnd :: ONDSTROY (); if (m_time! = 0) KillTimer (m_time); seven, use classwizard to add a WM_TIMER message for the main frame class, add member functions, and add the following code to implement dynamic icon m_active.shownextImage () Finally, compile, running.

The header files and implementations of the class we define are as follows: //myactive.h Implementation Class's Statement #if! Defined (AFX-MyActive-H_-47E058AD-6F69-11D2-B59C-86DD54033006-Includ-Ed-) #define AFX- MYACTIVE-H-47E058AD-6F69-11D2-B59C-86DD54033006-INCLUDED- class CMyactive {protected: CImageList m_imgList; // constructed object int m_Counter; // save data int m_Images; HICON hIcon; // icon handle HICON hPrevIcon; Public: cmyactive (); ~ cmyactive (); Bool Set Image List (Int IdResource, Int Number, Colorref Color); Bool ShownextImage ();}; #ndif // # define afX-myac-Tive-H-47E058AD-6F69 -11d2-b59c-86dd54033006_-include- // Implement file #include "stdafx.h" #include "myactive.h" cmyactive :: cmyactive () // default constructor {m_counter = -1; m_Images = -99; m_imgList.m_hImageList = NULL; // initialize list} CMyactive :: ~ CMyactive () {if (hPrevIcon) DestroyIcon (hPrevIcon); // recovering resources} BOOL CMyactive :: SetImageList (int IDResource, int number, COLORREF color) {if (Number <= 0) Return False; M-IMages = Number; Verify (IdResource, 16, 1, Color); Return True;} Bool CMyActive :: SH OwnextImage () // This function will be repeatedly called to achieve dynamic effect {if (m_imglist.m_himagelist == null) return false; m_counter ; if (m_counter> = m_images) m_counter = 0; // Create an icon from the image Link list Hicon = m_imglist.extracticon (m_counter); // Send a message to the main window Notification Update icon HICON HPREVICON = (HICON) AFXGETMAINWND () -> SendMAESSAGE (WM_SETICON, TRUE, (LPARAM) HICON; // Release Resource IF (HPREVICON) Destroyicon HPREVICON;

转载请注明原文地址:https://www.9cbs.com/read-5485.html

New Post(0)