Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Scripts and Functions (v2) • Re: [Function] MsgBoxTBI - Display a MsgBox window with an icon in the title bar

$
0
0
@burque505 Thank you for your testing. From what you reported, it looks like LoadPicture is working. The fact that you don't see any icons suggests that you are not getting to the SetTitleBarIcon nested function.

I would appreciate it if you could run the following diagnostic code and report any errors or what is displayed in the final MsgBox:

CODE:

#Requires AutoHotkey v2.0.3+

StatusLog := A_TickCount '`n'
MsgBoxTBI( , , 'T1')
StatusLog .= '`n'
MsgBoxTBI( , , 'T1', A_AhkPath)
StatusLog .= '`n'
MsgBoxTBI( , , 'T1', 'DDORes.dll', 2)
StatusLog .= '`n'
MsgBoxTBI( , , 'T1', 'DDORes.dll', 87)
MsgBox StatusLog

MsgBoxTBI(Text?, Title?, Options?, IconFile?, IconNumber?) {
static CXICON := SysGet(11)
static CYICON := SysGet(12)
static CXSMICON := SysGet(49)
static CYSMICON := SysGet(50)
static WM_COMMNOTIFY := 0x0044
static MsgNum := DllCall('User32.dll\RegisterShellHookWindow', 'Ptr', A_ScriptHwnd, 'Int')
&& DllCall('User32.dll\RegisterWindowMessageW', 'WStr', 'SHELLHOOK', 'UInt')

global StatusLog
SetTitleBarIconState := false
ShellMessageState := false
if IsSet(IconFile) {
IconNumber := IconNumber ?? 1
hIconSmall := LoadPicture(IconFile, 'w' CXSMICON ' h' CYSMICON ' Icon' IconNumber, &ImageType)
if ImageType != 1 ; IMAGE_ICON
throw Error('Unable to extract icon from resource.', -1, 'Small icon.')
hIconBig := LoadPicture(IconFile, 'w' CXICON ' h' CYICON ' Icon' IconNumber, &ImageType)
if ImageType != 1 ; IMAGE_ICON
throw Error('Unable to extract icon from resource.', -1, 'Big icon.')
OnMessage WM_COMMNOTIFY, SetTitleBarIcon
OnMessage MsgNum, ShellMessage
}
return MsgBox(Text?, Title?, Options?)

SetTitleBarIcon(*) {
; Critical
static ICON_SMALL := 0
static ICON_BIG := 1
static WM_SETICON := 0x0080

HiddenWindowsState := A_DetectHiddenWindows
DetectHiddenWindows true
if !WinExist('ahk_class #32770')
throw Error('There is no such window.', -1, 'ahk_class #32770')
SendMessage WM_SETICON, ICON_SMALL, hIconSmall
SendMessage WM_SETICON, ICON_BIG, hIconBig
OnMessage WM_COMMNOTIFY, SetTitleBarIcon, 0
DetectHiddenWindows HiddenWindowsState
StatusLog .= A_TickCount '`tSetTitleBarIcon`n'
}

ShellMessage(wParam, lParam, *) {
; Critical
static HSHELL_WINDOWCREATED := 1
static HSHELL_WINDOWDESTROYED := 2
static hwnd

if wParam = HSHELL_WINDOWCREATED {
hwnd := lParam
StatusLog .= A_TickCount '`tHSHELL_WINDOWCREATED`n'
} else if wParam = HSHELL_WINDOWDESTROYED && lParam = hwnd {
DllCall('User32.dll\DestroyIcon', 'Ptr', hIconSmall, 'Int')
DllCall('User32.dll\DestroyIcon', 'Ptr', hIconBig, 'Int')
OnMessage MsgNum, ShellMessage, 0
StatusLog .= A_TickCount '`tHSHELL_WINDOWDESTROYED`n'
}
}
}

I get the following on my machine:

CODE:

179182953

179184015SetTitleBarIcon
179184031HSHELL_WINDOWCREATED
179185015HSHELL_WINDOWDESTROYED

179185031SetTitleBarIcon
179185031HSHELL_WINDOWCREATED
179186031HSHELL_WINDOWDESTROYED

179186046SetTitleBarIcon
179186062HSHELL_WINDOWCREATED
179187046HSHELL_WINDOWDESTROYED


If you don't get something like that, you might try to uncomment the two Critical statements in the SetTitleBarIcon and ShellMessage nested functions.

Thank you for your help.

Statistics: Posted by iPhilip — Today, 17:54



Viewing all articles
Browse latest Browse all 579

Trending Articles