Change the icon to change the window

zhaozj2021-02-11  218

As you want to change the window of the window, Suzhou Xitang South Lane Shen Jianxin - When using VC 5.0 development applications, we may need to change the icon of the frame window (including the main frame window and sub-frame window, not using VC). You are ready, it's hard to see the icon. But the author refers to many books and materials, but did not find any articles that describe how to change the window icon (maybe many people think this is not worth mentioning), so that many beginners have no hand. After practicing, the author discovered two methods of changing the frame window icon. Using Method One can specify the icon of the frame window when writing an application, using method 2 can dynamically change the icon of the window as needed when running. If these two methods are combined, you can change the icon of the window as you wish. ---- Method 1, in programming, specify the icon of the window ---- One, if it is the icon for the main frame window, the steps are as follows:

Create or open the engineering icon (hereinafter used as an example of ICON). Click the ResourceView tab of the Workspace window, select the resource ID as the IDR_MAINFRAME icon resource, then press the Delete button to remove it. Note: Be sure to delete it. Select Resource from the Insert menu of Developer Studio, then select ICON, New (New) a new icon or import (import) an existing icon. Change the resource ID of the new icon to AFX_IDI_STD_MDIFRAME (if it is an MDI application) or changed to AFX_IDI_STD_FRAME (if it is an SDI application). AFX_IDI_STD_MDIFRAME and AFX_IDI_STD_FRAME These two resource IDs are predefined in the MFC. Compile and run the program, you can find that the icon of the main frame window is the icon you specified. ---- II. If it is an icon for the MDI sub-frame window, its steps are similar to those described above.

Ibid. Create or open the engineering icon. Deleting a resource ID is IDR_ICONTYPE (which should be iDR_xxxtype in your project, where xxx is your project name) icon resource. It is also important to pay attention to: Be sure to delete it. Ibid. New (New) a new icon or import (import) an existing icon. Change the resource ID of the new icon to iDR_ICONTYPE (the resource ID that is removed in step 2). Compile and run the program, you can find that the icon of the subframe window is the icon you specified. ---- With this method, you can specify different icons in a multi-view class MDI application. ---- Method 2 news. Its method is: hicon hicon = AFXGETAPP () -> Loadicon (IDi_icon1);

Assert (hic);

AFXGETMAINWND () -> SendMessage (WM_SETICON, TRUE, (LPARAM) HICON;

---- The AFXGETMAINWND () in the above description is the window handle of the main frame window, so the icon of the main frame window (including MDI and SDI) is changed, and the MDI application can be changed with the same method. Frame window icon. ---- Let an example will explain how to change the icon of the main frame window, steps below: ---- 1. Create or open the engineering icon. ---- 2. Select RESSOURCE from the Insert menu of Developer Studio, then select ICON, New (New) or Import (IMPORT), and the resource ID is changed to IDi_ICON_Green, IDi_ICON_RED. ---- 3. Click the ResourceView tab of the Workspace window to edit the IDR_MAINFRAME menu resource. Add a separator and Green Icon, Red Icon, two menu items in the View menu. Its resource ID is changed to ID_VIEW_GREEN and ID_VIEW_RED. ---- 4. Add the following message processing function for the main window: // CMAINFRAME Message Handlersvoid CMAINFRAME :: OnViewGreen ()

{

// Todo: add your command handler code here

HiCon Hicon = AFXGETAPP () -> Loadicon (IDi_ICON_GREEN);

Assert (hic);

SendMessage (WM_SETICON, TRUE, (LPARAM) HICON;

// Because it is in class CMAINFRAME, it is not necessary

AFXGETMAINWND () -> SendMessage (WM_SETICON, TRUE, (LPARAM) HICON;

}

Void cmainframe :: onviewred ()

{

// Todo: add your command handler code here

Hicon Hicon = AFXGetApp () -> Loadicon (IDi_ICON_RED);

Assert (hic);

SendMessage (WM_SETICON, TRUE, (LPARAM) HICON;

}

---- 5. Finally compile and execute the program, execute the Green Icon and Red icon of the View menu, you can see the icon that successfully changes the main frame window. ---- The above instance is the icon of the main frame window when the program is run, and the same method can change the icon of the sub-frame window of the MDI program, interested friends can try it.

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

New Post(0)