jNizM had presented me with some pretty functional code in the IRC. It used raw dllcalls instead of tic's wrapper. I changed it to using the wrapper, and it seems to be working pretty well on both 32 and 64 bit. What do you think of the code? I get the feeling that I did something wrong, especially since I couldn't get Gdip_CreateBitmapFromFile to work how I wanted.
Code: Select all
#NoEnv
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
NotifyIcon := new Notify()
Sleep, 1000
loop, 10
{
NotifyIcon.SetText(A_Index-1)
Sleep, 500
}
return
Exit:
Gdip_Shutdown(pToken)
ExitApp
return
Class Notify
{
__New(IconFont="Verdana", IconSize=16)
{
this.IconFont := IconFont, this.IconSize := IconSize
;this.pBitmapIcon := Gdip_CreateBitmapFromFile(A_AhkPath)
DllCall("shell32.dll\SHExtractIconsW", "Str", A_AhkPath
, "Int", 0, "Int", IconSize, "Int", IconSize
, "Ptr*", hIcon, "UInt*", 0, "UInt", 1, "UInt", 0)
this.pBitmapIcon := Gdip_CreateBitmapFromHICON(hIcon)
DestroyIcon(hIcon)
this.pBitmap := Gdip_CreateBitmap(IconSize, IconSize)
this.G := Gdip_GraphicsFromImage(this.pBitmap)
this.pBrush := Gdip_BrushCreateSolid(0xFF5555FF)
}
SetText(String)
{
Gdip_GraphicsClear(this.G, 0x00000000)
Gdip_DrawImage(this.G, this.pBitmapIcon)
; Draw the "bubble"
Gdip_FillRectangle(this.G, this.pBrush, 5, 6, 11, 9)
Gdip_FillRectangle(this.G, this.pBrush, 6, 5, 9, 11)
Gdip_TextToGraphics(this.G, String, "x7 y5 s8 cFFFFFFFF", this.IconFont)
hIcon := Gdip_CreateHICONFromBitmap(this.pBitmap)
this.SetIcon(hIcon)
DestroyIcon(hIcon)
}
SetIcon(hIcon)
{
static NIM_MODIFY := 1, NIF_ICON := 2, NOTIFYICONDATA
, Size := VarSetCapacity(NOTIFYICONDATA, (A_PtrSize == 8) ? 976 : 956, 0)
Addr := NumPut(Size, NOTIFYICONDATA, 0, "UInt") ; UINT cbSize
Addr := NumPut(A_ScriptHwnd, Addr+0, A_PtrSize-4, "UPtr") ; HWND hWnd
Addr := NumPut(1028, Addr+0, 0, "UInt") ; UINT uID
Addr := NumPut(NIF_ICON, Addr+0, 0, "UInt") ; UINT uFlags
Addr := NumPut(hIcon, Addr+0, A_PtrSize, "UPtr") ; HICON hIcon
DllCall("shell32.dll\Shell_NotifyIcon", "UInt", NIM_MODIFY, "UPtr", &NOTIFYICONDATA)
}
__Delete()
{
Gdip_DeleteBrush(this.pBrush)
Gdip_DeleteGraphics(this.G)
Gdip_DisposeImage(this.pBitmap)
Gdip_DisposeImage(this.pBitmapIcon)
}
}