CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ExtractIconEx(?)



This code (at the bottom) is straight out of the Win32 SDK in your BCB MS
Help folder. I get (double) errors at 

lpResource = LockResource(hMem);

I tried changing the declaration from BYTE to LPVOID and it stoped the two
at lpResource = and created one identical in CreateIconFromResourceEx(
lpResource... because it's still of type void* and needs to be unsigned
char*

So How do I convert a void* to an unsigned char*  ???
Or rather : how do I get a "blasted" icon from any other .exe file painted
next to a button on my form?

Basically what I'm trying to do is paint an applications icon next to a
user defined text-button to launch that application. Sort of a custom
launchpad.

I couldn't get it to work with ExtractIconEx(0, "MyApp.Exe", 0); because I
can't get a string from an edit box into the space where you see MyApp.Exe.
It's a const char and and can't be modified...???

The rest of the code works, and I could let it go as is, but I really
want an icon to go next to that text-button. (Especially since you can't
put the icon on the button!) I don't like Text buttons. I got a handful
of macros like that in Word6.

/*Copied and pasted right to the unit.cpp from the help file*/
void __fastcall TForm1::Button4Click(TObject *Sender)
{
    HICON hIcon1;
    HINSTANCE hExe;
    HRSRC hResource;
    HRSRC hMem;
    BYTE lpResource;
    int nID;
    HDC hdc;
    hdc = Form1;
    hExe = LoadLibrary("MyApp.exe");
    hResource = FindResource(hExe, MAKEINTRESOURCE(0), RT_ICON);
    hMem = LoadResource(hExe, hResource);
    lpResource = LockResource(hMem);
    nID = LookupIconIdFromDirectoryEx((PBYTE) lpResource, true, 32, 32, LR_DEFAULTCOLOR);
    hResource = FindResource(hExe, MAKEINTRESOURCE(nID),
			     MAKEINTRESOURCE(RT_ICON));
    hMem = LoadResource(hExe, hResource);
    lpResource = LockResource(hMem);
    hIcon1 = CreateIconFromResourceEx( lpResource, SizeofResource(hExe,hResource), 
				       true, 0x00030000, 32, 32, LR_DEFAULTCOLOR);
    DrawIcon(hdc, 20, 20, hIcon1);
}

Rick Malik
rmfci@pacbell.net

Visit the C++ Bulder Hobby Pages
http://home.pacbell.net/rmfci/bcbhp.htm


W Komornicki's Home Page | Main Index | Thread Index