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?
The icon that is displayed on the message box dialog is implemented using a
STATICcontrol withSS_ICONstyle. You can obtain the icon handle by sending that control theSTM_GETICONmessage.In the code in your question, the variable named
hlblis actually the window handle of theSTATICcontrol that contains the icon. I’d name ithIconWnd. With that name change, the code to obtain the icon would look like this: