|
Try http://codeproject.com/win32/IconExtraction.asp
|
|
|
|
|
Thanks dude, that makes just what I need, but saving the icon as a file :S
I need to get a resource ID or a HICON so I can add it to the list.
I tried to adapt it, but I cant make it work.
Maybe I just lost my patience and focus
|
|
|
|
|
I use this to extract an icon (from any file, not just EXEs).
This will get the default icon from Windows if none is in the exe.
<br />
HICON hIcon = 0;<br />
<br />
<br />
SHFILEINFO shfi;<br />
memset(&shfi, 0, sizeof(shfi));<br />
if (SHGetFileInfo(pszPathname,<br />
FILE_ATTRIBUTE_NORMAL,<br />
&shfi,<br />
sizeof(shfi),<br />
SHGFI_ICON | SHGFI_SMALLICON))<br />
{<br />
hIcon = shfi.hIcon;<br />
}<br />
<br />
<br />
<br />
if (hIcon == 0)<br />
{<br />
LPTSTR pszExtension = PathFindExtension(pszPathname);<br />
CString DummyFileName;<br />
DummyFileName = _T("dummyfile");<br />
if (pszExtension[0] == _T('.'))<br />
DummyFileName += pszExtension;<br />
else<br />
DummyFileName += _T(".");<br />
<br />
SHFILEINFO shfi;<br />
memset(&shfi, 0, sizeof(shfi));<br />
if (SHGetFileInfo(DummyFileName,<br />
FILE_ATTRIBUTE_NORMAL,<br />
&shfi,<br />
sizeof(shfi),<br />
SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES))<br />
{<br />
hIcon = shfi.hIcon;<br />
*pRetImgFlags |= RECORDIMGDATAFLAG_ICONFROMSHELL;<br />
}<br />
}<br />
<br />
if (hIcon)<br />
{<br />
...<br />
Will that work?
Mark
|
|
|
|
|
I use this to get an icon for any file. This will get the default exe icon if none
found in the exe itself:
<br />
HICON hIcon = 0;<br />
<br />
<br />
SHFILEINFO shfi;<br />
memset(&shfi, 0, sizeof(shfi));<br />
if (SHGetFileInfo(pszPathname,<br />
FILE_ATTRIBUTE_NORMAL,<br />
&shfi,<br />
sizeof(shfi),<br />
SHGFI_ICON | SHGFI_SMALLICON))<br />
{<br />
hIcon = shfi.hIcon;<br />
}<br />
<br />
<br />
<br />
if (hIcon == 0)<br />
{<br />
LPTSTR pszExtension = PathFindExtension(pszPathname);<br />
CString DummyFileName;<br />
DummyFileName = _T("dummyfile");<br />
if (pszExtension[0] == _T('.'))<br />
DummyFileName += pszExtension;<br />
else<br />
DummyFileName += _T(".");<br />
<br />
SHFILEINFO shfi;<br />
memset(&shfi, 0, sizeof(shfi));<br />
if (SHGetFileInfo(DummyFileName,<br />
FILE_ATTRIBUTE_NORMAL,<br />
&shfi,<br />
sizeof(shfi),<br />
SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES))<br />
{<br />
hIcon = shfi.hIcon;<br />
*pRetImgFlags |= RECORDIMGDATAFLAG_ICONFROMSHELL;<br />
}<br />
}<br />
<br />
if (hIcon)<br />
{<br />
...<br />
}<br />
Is that what you're looking for?
Mark
|
|
|
|
|
Sorry about the double post.
I got an error the first time. I should have checked to see if it posted first
Mark
|
|
|
|
|
Thanks mate, and no problem about the double post.
Yeap that works but I don't know why i have a lot of apps wich fail loading the icon
I post my code, maybe someone sees what im doing wrong
do {<br />
<br />
imageIndex = 0;<br />
<br />
keyNameLenght = 256;<br />
<br />
res = RegEnumKeyEx(phkResult,<br />
dwIndex,<br />
keyName,<br />
&keyNameLenght,<br />
NULL,<br />
NULL,<br />
NULL,<br />
NULL);<br />
<br />
if(res == ERROR_SUCCESS) {<br />
<br />
<br />
sprintf(lpSubKey2,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s\\", keyName);<br />
<br />
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey2,NULL,KEY_ALL_ACCESS,&phkResult2);<br />
<br />
if (ERROR_SUCCESS == result)<br />
{<br />
if (ERROR_SUCCESS == RegQueryValue(phkResult2, NULL, path, &largoBuffer)) {<br />
<br />
<br />
CString tup = path;<br />
HICON temp = NULL;<br />
HMODULE hMod = NULL;<br />
int res = 0;<br />
WORD pis = 0;<br />
<br />
tup.Remove('"');<br />
<br />
SHFILEINFO shfi;<br />
memset(&shfi, 0, sizeof(shfi));<br />
if (SHGetFileInfo(tup,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON))<br />
{<br />
temp = shfi.hIcon;<br />
imageIndex = m_imageList.Add(temp);<br />
}<br />
else {<br />
<br />
LPTSTR pszExtension = PathFindExtension(tup);<br />
CString DummyFileName;<br />
DummyFileName = _T("dummyfile");<br />
<br />
if (pszExtension[0] == _T('.'))<br />
DummyFileName += pszExtension;<br />
else<br />
DummyFileName += _T(".");<br />
<br />
<br />
SHFILEINFO shfi;<br />
memset(&shfi, 0, sizeof(shfi));<br />
<br />
if (SHGetFileInfo(keyName,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES))<br />
{<br />
temp = shfi.hIcon;<br />
}<br />
<br />
if(temp != NULL) {<br />
<br />
imageIndex = m_imageList.Add(temp);<br />
<br />
}<br />
else {<br />
<br />
imageIndex = 0;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
lvi.mask = LVIF_TEXT | LVIF_IMAGE;<br />
lvi.iItem = 0;<br />
lvi.iSubItem = 0;<br />
lvi.pszText = keyName;<br />
lvi.iImage = imageIndex;<br />
m_listOrigin.InsertItem(&lvi);<br />
<br />
m_listOrigin.SetItem(&lvi);<br />
<br />
<br />
}<br />
<br />
}<br />
<br />
dwIndex++;<br />
<br />
}while(res != ERROR_NO_MORE_ITEMS);
|
|
|
|
|
>>...but I don't know why i have a lot of apps wich fail loading the icon
What do you mean? EXEs without icons?
Are you just getting the default EXE icon or none at all?
Mark
|
|
|
|
|
>>...but I don't know why i have a lot of apps wich fail loading the icon
What do you mean? EXEs without icons?
Are you just getting the default EXE icon or none at all?
By the way, don't forget to use DestroyIcon() on the returned HICON after you add it to your
image list
Mark
|
|
|
|
|
First thanks to all the people that helped me with that
The problem wasn't the technique used to get the icon, the problem was that when I used RegQueryValue I didn't re initialized the variable with the buffer lenght
So a lot of entries were corrupt and that's why some exe didn't get an icon
|
|
|
|
|
Cool!
And remember, don't forget to use DestroyIcon() on the returned HICON after you add it to your
image list
Mark
|
|
|
|
|
Done
Thanks a lot Mark, you were really helpful
|
|
|
|
|
Hello *,
dialog boxes can have a question mark button in their caption that (when clicked) changes cursor and provides help for selected control.
I'd like to have the same functionality in the main window of the application, triggered for example by a toolbar button.
I guess a specialized message loop is needed to provide all the functionality (changing cursor, sending the WM_HELP, cancelling on ESC, ...) Is this piece of code avaiable or would I need to implement it myself ?
One more thing - no MFC if possible, just pure Win32.
Thanks in advance,
Vlasta
|
|
|
|
|
This is what I would try,
When user clicks on '?' button:
- capture mouse to main window
- set flag variable that context help is active
In main window's WM_SETCURSOR function set cursor to question mark.
In main window's WM_LBUTTONDOWN:
- use ChildWindowFromPoint() to get the window clicked on.
- Post WM_HELP to that window
- Release the capture
- Clear the flag variable
|
|
|
|
|
Thanks for the reply, I was hoping somebody already did this. Oh well.
|
|
|
|
|
How do I query the settings in the Windows Properties Display Panel, e.g. to find whether normal or large or extra large fonts have been selected?
thanks in advance!
~ Mike
|
|
|
|
|
My first guess would be the Windows System Information functions like GetSystemMetrics(...) , SystemParametersInfo(...) , etc. Try starting with those functions in MSDN help, search and KB articles.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Are you referring to the Appearance tab of the Display Properties dialog? If so, that information is stored in the registry at:
HKCU\Software\Microsoft\Windows\CurrentVersion\ThemeManager\SizeName
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
See WMI class maybe its some helpful for you
|
|
|
|
|
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.?
Is it even possible?
SnaidiS(Semion)
|
|
|
|
|
i'd say "no, not possible".
|
|
|
|
|
while number received != -1
store the number
end while
calculate the average
iterate through the array constructed below
if number in the iteration is above the average
increment counter
end if
end iterations
but the question is, WHY don't you want to use the STL ??
managing your own memory with such growing arrays are not good things to do by yourself...
|
|
|
|
|
While you can certainly compute the average without any additional storage, you'd still need to be able to go back through the set of numbers to pick out those greater than the average.
Just for our edificaton, why the restriction?
Is this your post, too?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
toxcct wrote: iterate through the array
you can't use arrays
|
|
|
|
|
|
why does that matter?
the original post said "no arrays".
|
|
|
|