Programming acquisition icon

xiaoxiao2021-03-06  44

In the program, when you need to get an icon of other programs, we can first call the SDK function SHGETFILEINFO to get information about the application, and use the obtained HICON handle to display the icon display.

For example, if you need to display a write panel icon in the upper left corner of the program window (see Figure 1), you can add the following code in the corresponding view class onDRAW:

Void CsampleView: OnDraw (CDC  PDC)

{

// Get icon information

IF (: ShgetfileInfo (_t (c: // program files // accessories // wordpad.exe "), 0,

&& StfileInfo, Sizeof (StfileInfo), SHGFI_ICON))

{

// Display the obtained icon information using the Drawicon interface of the device description table

PDC -> Drawicon (10, 10, stfileinfo.chicon);

}

}

Alternatively, you can also call the Extracticon function to obtain the icon information of the application, and the Drawicon function of the device description table is called display.

Void CsampleView :: OnDraw (CDC PDC)

{

HiCon Hicon = :: Extracticon (AfxgetInstanceHandle (), _ T

("C: // Program Files // Accessories // WordPad.exe"), 0);

IF (Hicon &&& HiCon! = (HICON) -1)

PDC-> Drawicon (10, 10, Hicon);

}

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

New Post(0)