LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Icon from exe

I need to be able to display the icon bitmaps embedded in exe files on a
panel of a CVI application. I am using LabWindows CVI 8.0 base verson.

Can someone help me understand how to do this.

Thanks.......


0 Kudos
Message 1 of 16
(6,096 Views)
Hello Michael,

So CVI doesn't provide a built-in function to allow you extract an image from a DLL or EXE.  Instead, you will have to use the ExtractIcon(Ex) and DrawIcon functions available in CVI Full Development System and the Windows SDK.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 16
(6,049 Views)
Michael,

You can also download the Windows Platform SDK directly from Microsoft since you do not have the FDS version of CVI.

Mert A.
National Instruments
0 Kudos
Message 3 of 16
(6,035 Views)

Hello,

I am also interested in getting the icons from a DLL or EXE file. I have used the ExtractIcon function successfully to get a handle to the icons (HICON). Unfortunately I don't know how to handle HICON variables. Is there any way to turn them into a CVI bitmap, that I can draw to a picture control, canvas or table cell?

Thanks,

Wim

0 Kudos
Message 4 of 16
(5,867 Views)
Hi Wim,
 
The DrawIcon function, mentioned above, will allow you to position your HICON.  Otherwise, you would have to use a Windows SDK function to convert from HICON to bitmap - there is no CVI built-in function.  The available CVI functions are in Library >> User Interface Library >> Bitmaps.  I did not find any Windows SDK functions available to convert an HICON to a bitmap.  However, I did see a .NET function Bitmap.FromHicon Method.  This method cannot be used directly in CVI, though you could use it for a Measurement Studio project. 
Cheers,

David Goldberg
National Instruments
Software R&D
Message 5 of 16
(5,820 Views)

Hi David,

Thanks for the quick reply. I don't really understand the usage of the first parameter in this DrawIcon function (handle to device context). How can I get the value of this parameter form my picture control?

0 Kudos
Message 6 of 16
(5,808 Views)
You can obtain a system handle from a top level CVI panel with:

    int han;

    GetPanelAttribute (panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, &han);

then you can obtain the Windows DC for the panel by:

    HDC panDC;

    panDC = GetDC ((HWND) han);

which will allow you to use the DrawIcon function, or indeed many other SDK drawing functions. Note that the offsets to the drawing position are with respect to the panel top left corner - you can easily aim the target of your drawing to any part of your panel or control by using suitable offset values.
 
JR
Message 7 of 16
(5,804 Views)

Hello all,

I'm sorry but I can't get this thing working. I use the DrawIcon function, but nothing appears on my panel. Can someone see what I am doing wrong? I attached my project to this message.

Thanks a lot,

Wim

0 Kudos
Message 8 of 16
(5,785 Views)
The reason you cannot see the result is because of how the CVI panel gets drawn. You are only calling draw icon once, and you are just drawing directly to the screen. This means that the next time the CVI panel redraws, whatever you have drawn will be "covered up" by the new draw. The way to handle this is to redraw whatever you want every time the panel window recieves a WM_PAINT message. You can do this by using InstallWinMsgCallback. I made some quick and dirty modifications to the example you posted that should give you an idea how this is done in CVI. There are some caveats to doing this (CVI isn't really expecting you to be drawing onto the panel) but it does work.

Regards,

-alex
Message 9 of 16
(5,783 Views)
Thanks Alex. This seems to work fine. What I would like to do now is save each extracted icon to a PNG file, keeping the icon's transparency. I adjusted my code, trying to get al icon information to create a CVI bitmap. If this would work, then I could simply use the SaveBitmapToPNGFile function. I succeed in getting a handle to the color bitmap and the mask bitmap, using the GetIconInfo function. But then, when trying to get the information from these two bitmaps, the pointer to the data (bmBits member of the BITMAP structure) is always NULL Smiley Sad . I already tried a lot of work arounds, but I'm afraid I am stuck here...
0 Kudos
Message 10 of 16
(5,762 Views)