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

Ask for Help (v2) • Re: Why Msgbox dosn't use "TraySetIcon"?

$
0
0
@Seven0528, thanks for pointing out that bit in the documentation for LoadPicture(). Ran some leak tests and was noticing some performance issues after about 1600 MsgBox() calls, so we've tweaked the function yet again, now deleting the handles right after they've been applied and are now no longer needed.

CODE:

MsgBox.Native := MsgBox.Call
MsgBox.DefineProp("Call", {Call: MsgBoxEx})
MsgBoxEx(this, Text?, Title?, Options?, IconFile := A_IconFile ? A_IconFile : A_AhkPath, IconNumber := A_IconNumber ? A_IconNumber : 1) {
WinTitle := (title ?? A_ScriptName) " ahk_class #32770"
OnMessage(0x0044, WM_NOTIFY_MSGBOXEX)
result := this.Native(text?, title?, options?)
return result

WM_NOTIFY_MSGBOXEX(*) {
static ICON_BIG := 1, ICON_SMALL := 0, SM_CXICON := SysGet(11), SM_CYICON := SysGet(12), SM_CXSMICON := SysGet(49), SM_CYSMICON := SysGet(50), WM_SETICON := 0x0080
hICON_BIG := LoadPicture(IconFile, "w" SM_CXICON " h" SM_CYICON " Icon" IconNumber, &HandleType)
hICON_SMALL := LoadPicture(IconFile, "w" SM_CXSMICON " h" SM_CYSMICON " Icon" IconNumber, &HandleType)
DetectHiddenWindows(True)
SendMessage(WM_SETICON, ICON_BIG, hICON_BIG, Control?, WinTitle, Text ?? "Press OK to continue.")
SendMessage(WM_SETICON, ICON_SMALL, hICON_SMALL, Control?, WinTitle, Text ?? "Press Ok to continue.")
DetectHiddenWindows(False)
OnMessage(0x0044, WM_NOTIFY_MSGBOXEX, 0)
SetTimer((*) => DllCall("DestroyIcon", "ptr", hICON_BIG), -100)
SetTimer((*) => DllCall("DestroyIcon", "ptr", hICON_SMALL), -100)
}
}

Statistics: Posted by Panaku — Today, 19:18



Viewing all articles
Browse latest Browse all 579

Trending Articles