Thanks, I'm finding it very useful.
I knew there had to be a better way than counting blue pixels! This approach listens for the little gmail notification window sliding up and when it finds it, displays the graphic. So the big envelope will come out once each time a new message is announced by gmail, regardless of the color of the systray icon. It stays up until you touch it with the mouse. It seems perfect to me. The listening loop happens once every one second, and uses less than one ms to do the test. No cpu hit at all.
Code: Select all
;===============================================
; Program: Google Notifier Enhancer
; Date: July 18, 2006
; Author: netmaestro
; TargetOS: Windows 2000/XP
; Compiler: PureBasic 4.0
;===============================================
;
*MyMutex = CreateMutex_(#Null, 1, "EnhancedGMailNotifier")
If *MyMutex <> 0 And GetLastError_() = #ERROR_ALREADY_EXISTS
CloseHandle_(*MyMutex)
MessageRequester("Notice", "The Enhanced Gmail Notifier is already running!", #MB_ICONINFORMATION)
End
EndIf
Global gMessages = 0
Global win
Declare Envelope(void)
Declare StartWithWindows(state.b)
StartWithWindows(1)
CreateImage(0,640,480,#PB_Image_DisplayFormat)
StartDrawing(ImageOutput(0))
b = RGB(0,0,160)
Box(0,0,640,400,b)
Box(30,30,580,340,#White)
Box(200,185,240,30,b)
LineXY(0,15, 200, 200, b)
LineXY(15,0, 215, 185, b)
FillArea(32,32,b,b)
LineXY(0,384,200,200,b)
LineXY(15,399,230,200,b)
FillArea(32,368,b,b)
LineXY(624,0,425,186,b)
LineXY(639,15,440,200,b)
FillArea(442,197,b,b)
LineXY(440,200,639,385,b)
LineXY(424,214,610,385,b)
FillArea(442,220,b,b)
StopDrawing()
Global hBrush = CreatePatternBrush_(ImageID(0))
CreateImage(1,200,80,#PB_Image_DisplayFormat)
StartDrawing(ImageOutput(1))
Box(0,0,200,80,#White)
StopDrawing()
CreateImage(2, 360,65,#PB_Image_DisplayFormat)
LoadFont(0, "Arial", 60, #PB_Font_Bold|#PB_Font_HighQuality)
Repeat
hTaskBar.l = FindWindow_("Shell_TrayWnd", #Null)
hSystemTray.l = FindWindowEx_(hTaskBar, 0, "TrayNotifyWnd", 0)
GetWindowRect_(hSystemTray, Tray.RECT)
pt.POINT
pt\x = Tray\right - 50
pt\y = Tray\top - 20
wc$ = Space(255)
win = WindowFromPoint_(pt\x,pt\y)
GetClassName_(win, @wc$, 254)
If wc$="RichEdit20W"
win2=GetParent_(win)
win3=GetParent_(win2)
GetClassName_(win3,@wc$,254)
If wc$ = "GoogleGmailNotifySysTray"
gMessages + 1
Delay(1500)
;*****************************************************
GetWindowRect_(win2, @wr.RECT)
srcDC = GetWindowDC_(win2)
trgDC = StartDrawing(ImageOutput(2))
Box(0,0,360,65,RGB(227,226,229))
BitBlt_( trgDC, 0, 0, wr\right-wr\left, wr\bottom-wr\top, srcDC, 0,0, #SRCCOPY)
StopDrawing()
ReleaseDC_(win2, srcDC)
;*****************************************************
If Not FindWindow_(0, "EnhancedgmailNotifier")
CreateThread(@Envelope(), win)
EndIf
Repeat
Delay(10)
Until IsWindow_(win) = #False
EndIf
EndIf
Delay(100)
ForEver
DeleteObject_(hBrush)
End
Procedure Envelope(void)
cc = 0 : oldgM = 0 : alphas = 20
OpenWindow(0,0,0,640,400,"EnhancedgmailNotifier",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED | #WS_EX_TOOLWINDOW)
SetLayeredWindowAttributes_(WindowID(0), 0, alphas, #LWA_ALPHA)
CreateGadgetList(WindowID(0))
ContainerGadget(0,0,0,640,400)
SetClassLong_(GadgetID(0), #GCL_HBRBACKGROUND, hBrush)
ImageGadget(1,225,90,200,80,ImageID(1))
ImageGadget(2,144,304,360,65,ImageID(2))
ShowWindow_(WindowID(0), #SW_SHOW)
StartTime = ElapsedMilliseconds()
While WindowEvent():Wend
SetForegroundWindow_(WindowID(0))
StickyWindow(0,1)
Repeat
EventID = WaitWindowEvent(10)
If gMessages <> oldgM
oldgM = gMessages
StartDrawing(ImageOutput(1))
Box(0,0,200,80,#White)
DrawingFont(FontID(0))
DrawText(98 - TextWidth(Str(gMessages)) / 2, 0, Str(gMessages), RGB(0,0,160), #White)
StopDrawing()
SetGadgetState(1, ImageID(1))
SetGadgetState(2, ImageID(2))
EndIf
If ElapsedMilliseconds()-StartTime > 350
StartTime = ElapsedMilliseconds()
If alphas < 180
alphas + 1
SetLayeredWindowAttributes_(WindowID(0), 0, alphas, #LWA_ALPHA)
EndIf
EndIf
If EventID = #WM_MOUSEMOVE
If cc=0
GetCursorPos_(@cp1.POINT)
Else
GetCursorPos_(@cp2.POINT)
EndIf
cc+1
If cc > 5
If Abs(cp2\x - cp1\x) > 10 Or Abs(cp2\y - cp1\y) > 10
Break
EndIf
EndIf
EndIf
ForEver
gMessages = 0
CloseWindow(0)
EndProcedure
Procedure StartWithWindows(State.b)
Protected Key.l = #HKEY_CURRENT_USER ;or #HKEY_LOCAL_MACHINE for every user on the machine
Protected Path.s = "Software\Microsoft\Windows\CurrentVersion\Run" ;or RunOnce if you just want to run it once
Protected Value.s = "GmailEnhancer" ;Change into the name of your program
Protected String.s = Chr(34)+ProgramFilename()+Chr(34) ;Path of your program
Protected CurKey.l
If State
RegCreateKey_(Key,@Path,@CurKey)
RegSetValueEx_(CurKey,@Value,0,#REG_SZ,@String,Len(String))
Else
RegOpenKey_(Key,@Path,@CurKey)
RegDeleteValue_(CurKey,@Value)
EndIf
RegCloseKey_(CurKey)
EndProcedure