Reputation: 327
I have a WH_CALLWNDPROC hook code which handles WM_INITDIALOG message to get information about message boxes. I could get "Message", "Title", "Buttons" but I couldnt get "icon" information. I'm trying to use a function like below:
long getIcon(HWND hwnd) { // handle of messagebox dialog
HWND hlbl = GetDlgItem(hwnd,20);
wcout << "LABEL HWND: " << hlbl << endl;
if (hlbl != NULL) {
LRESULT r = SendMessage(hlbl,WM_GETICON,0,0);
return (long)r;
}
return 0;
}
function always returns 0. I have checked by MS Spy++ and I saw that icon handle is 0. What is the correct way to get icon?
Upvotes: 3
Views: 2027
Reputation: 613572
The icon that is displayed on the message box dialog is implemented using a STATIC
control with SS_ICON
style. You can obtain the icon handle by sending that control the STM_GETICON
message.
In the code in your question, the variable named hlbl
is actually the window handle of the STATIC
control that contains the icon. I'd name it hIconWnd
. With that name change, the code to obtain the icon would look like this:
HICON getIcon(HWND hwnd) { // handle of messagebox dialog
HWND hIconWnd = GetDlgItem(hwnd, 20);
if (hIconWnd != NULL) {
return (HICON)SendMessage(hIconWnd, STM_GETICON, 0, 0);
}
return NULL;
}
Upvotes: 2