[Windows] Some thing to do with invisible windows
Posted: Sat Jul 09, 2011 4:02 pm
I am terrible with thread topic names.. Anyway, I was going through my Folder of Folders and cleaning it up a bit when I came across this bit of code that I made a while back. It displays a drawn image and moves it around the mouse cursor. I'm sure there are better ways of doing this, though. But the Transparent window is pretty neat to have.
[edit] omg, im really dumb. Originally posted around IMG tags, then edited to URL tags..................
Code: Select all
; last modified: March 6th, 2011 @ 9:38:56 AM
;IncludeFile "WinAPI.pbi"
Procedure OpenTransparentWindow(transColor, x, y, width, height) ;-- Create an invisible, borderless, and transparent window
; HideWindow(winResult, 0) after gadgets have been placed. Otherwise you may see flicker.
; I do not know if this works on all versions of windows or just Vista / 7
; I have only tested on both x86 and x64 Windows 7
winResult = OpenWindow(#PB_Any, 1, 1, 1, 1, "",#PB_Window_BorderLess| #PB_Window_Invisible)
SetWindowColor(winResult,transColor)
SetWindowLongPtr_(WindowID(winResult),#GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOOLWINDOW | #WS_EX_TOPMOST) ; -- According to the MSDN, this function will work with both x86 and x64 ( http://msdn.microsoft.com/en-us/library/ms644898(v=VS.85).aspx )
SetWindowPos_(WindowID(winResult),#Null, x, y, width, height, #Null) ; -- Must redraw window, according to the MSDN
SetLayeredWindowAttributes_(WindowID(winResult),transColor,#Null,#LWA_COLORKEY)
ProcedureReturn winResult
EndProcedure
ExamineDesktops()
window = OpenTransparentWindow(RGB(254,0,0),0,0,DesktopWidth(0),DesktopHeight(0))
StickyWindow(window,1)
HideWindow(window,0)
Structure pt
x.l
y.l
EndStructure
msPos.pt
Repeat : eventID = WaitWindowEvent(1)
Delay(1)
GetCursorPos_(msPos)
s.f = 20 * Sin(a.f) : c.f = 20 * Cos(a.f) : s2.f = 10 * Sin(a2.f)
c2.f = 10 * Cos(a2.f) : s3.f = 25 * Sin(a3.f) : c3.f = 25 * Cos(a3.f)
StartDrawing(WindowOutput(window))
Circle(msPos\x+s,msPos\y+c, 2, RGB(Random(255),Random(255),Random(255)))
Circle(msPos\x+s+s2,msPos\y+c+c2, 4, RGB(Random(255),Random(255),Random(255)))
Circle(msPos\x+s+s2+c3,msPos\y+c+c2+s3, 4, RGB(50,0,0))
Circle(msPos\x+s+s2+c3,msPos\y+c+c2+s3, 3, RGB(100,0,0))
Circle(msPos\x+s+s2+c3,msPos\y+c+c2+s3, 2, RGB(200,0,0))
StopDrawing()
InvalidateRect_(WindowID(window),0,#True)
a.f + 0.03 : a2.f + 0.08 : a3.f + 0.1
Until eventID = #PB_Event_CloseWindow ; -- LOL