[Solved] Graphic Aberations seen on Win 7. Do you see them?
Posted: Tue Aug 21, 2012 4:21 am
I have defined a 'giant' cross-hair cursor that runs independently, essentially replacing the normal cursor. It's basically a transparent Window twice the size of the desktop. Compiled as a 32bit app, it works exactly as intended on my XP 32bit PC, without fault. The same app on my Win7 64bit laptop works, but if the cursor is swiped over another window, then that other window is at least temporarily messed up.
So, first thing I'd like to know is, given that it works so well on XP, is it really a Win7 problem or is it just my Win7?
If you have a minute to spare, please test it.
Below is the code to make two exe files, one being the cursor and the other is a simple window, containing an image, to test.
CrossHairCursor:
The above code uses a 'blank' cursor used to temporarily replace the system cursor.
The cursor is referenced in a Resource File, something like this: Cursor01 CURSOR "C:\PROJECTS_DrvC\GlobalCursor\Cursor01.cur"
The blank cursor file is here: Download Blank Cursor
Code for the image window:
Edit: To the 50 peeps that have taken a look at this post but not dared to test - give it a go, even if you are not using Win7 it would be a great help to know if you see good graphics or bad 
Edit: In the code above, I have reduced the cursor line lengths so that they do not touch the edge of the window - I think that might be the cause of the loss-of-transparency issue.
So, first thing I'd like to know is, given that it works so well on XP, is it really a Win7 problem or is it just my Win7?
If you have a minute to spare, please test it.
Below is the code to make two exe files, one being the cursor and the other is a simple window, containing an image, to test.
CrossHairCursor:
Code: Select all
Enumeration
#BigCur
#ImgBigCursor
#ImgGdtBigCursor
#TempWin
EndEnumeration
Enumeration 0 Step 1
#MONITOR_DEFAULTTONULL
#MONITOR_DEFAULTTOPRIMARY
#MONITOR_DEFAULTTONEAREST
EndEnumeration
Structure MONITORINFO
cbSize.l
rcMonitor.RECT
rcWorkArea.RECT
flags.l
EndStructure
Global pgGlobalCurPos.POINT
igBigCursWinBackColour = RGB(255,0,255)
igActiveCrossCurColour = RGB(255,0,0)
Global igArrowCur.i = LoadCursor_(0,#IDC_ARROW)
Global igCopyArrowCur.i = CopyImage_(igArrowCur,#IMAGE_CURSOR,0,0,#LR_COPYFROMRESOURCE)
Global igBlankCur.i = LoadCursor_(GetModuleHandle_(0), "Cursor01") ;No graphic (to hide cursor)
SetSystemCursor_(igBlankCur,#OCR_NORMAL)
Global gWinInfo.MONITORINFO
gWinInfo\cbSize = SizeOf(gWinInfo)
gWinInfo\flags = 0
If OpenWindow(#TempWin, 20, 20, 20, 20, "Cursor",#PB_Window_BorderLess)
;possible that multi-monitor uses different size monitors
hMonWn = MonitorFromWindow_(WindowID(#TempWin),#MONITOR_DEFAULTTONEAREST)
GetMonitorInfo_(hMonWn,@gWinInfo)
CloseWindow(#TempWin)
EndIf
igWinW = ((gWinInfo\rcWorkArea\Right) - (gWinInfo\rcWorkArea\Left))
igWinH = ((gWinInfo\rcWorkArea\bottom) - (gWinInfo\rcWorkArea\top))
igWinW = igWinW * 2
igWinH = igWinH * 2
;Draw window off screen
If OpenWindow(#BigCur, gWinInfo\rcWorkArea\Right - 20, gWinInfo\rcWorkArea\bottom -20, igWinW, igWinH, "Cursor",#PB_Window_BorderLess | #PB_Window_Invisible)
;Set the Window Backcolour to the Image Backcolour - avoids 'flash' when window first launched
SetWindowColor(#BigCur,igBigCursWinBackColour)
SetWindowLongPtr_(WindowID(#BigCur),#GWL_EXSTYLE,#WS_EX_LAYERED | #WS_EX_TOOLWINDOW | #WS_EX_TOPMOST)
;Use SetWindowPos to 'redraw' the window
SetWindowPos_(WindowID(#BigCur),#Null, gWinInfo\rcWorkArea\Right - 20, gWinInfo\rcWorkArea\bottom -20, igWinW, igWinH, #Null)
SetLayeredWindowAttributes_(WindowID(#BigCur),igBigCursWinBackColour,0,#LWA_COLORKEY)
SetCursor_(igBlankCur)
CreateImage(#ImgBigCursor,igWinW,igWinH,32) ;BigCursor Window Background
If StartDrawing(ImageOutput(#ImgBigCursor))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,igWinW,igWinH,igBigCursWinBackColour)
DrawingMode(#PB_2DDrawing_Default)
Box((igWinW/2) - 2,(igWinH/2) - 7,3,12,igActiveCrossCurColour)
Box((igWinW/2) - 7,(igWinH/2) - 2,12,3,igActiveCrossCurColour)
;x1 ;y1 ;x2 ;y2
LineXY((igWinW/2) - 1, 10, (igWinW/2) - 1, igWinH - 10, igActiveCrossCurColour)
LineXY( 10, (igWinH/2) - 1, igWinW - 10, (igWinH/2) - 1, igActiveCrossCurColour)
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box((igWinW/2) - 2,(igWinH/2) - 2,3,3,RGBA(0,0,0,0))
StopDrawing()
EndIf
ImageGadget(#ImgGdtBigCursor,0,0,igWinW,igWinH,ImageID(#ImgBigCursor))
SetCursor_(igBlankCur)
HideWindow(#BigCur,#False)
SmartWindowRefresh(#BigCur,#True)
Repeat
GetCursorPos_(pgGlobalCurPos)
SetCursor_(igBlankCur)
ResizeWindow(#BigCur,(pgGlobalCurPos\x - (igWinW/2)), (pgGlobalCurPos\y - (igWinH/2)), #PB_Ignore, #PB_Ignore)
SetCursor_(igBlankCur)
StickyWindow(#BigCur,#True)
igEventID = WaitWindowEvent(1)
If(GetAsyncKeyState_(#VK_ESCAPE) & 32768)
Break
EndIf
ForEver
EndIf
SetSystemCursor_(igCopyArrowCur,#OCR_NORMAL)
End
The cursor is referenced in a Resource File, something like this: Cursor01 CURSOR "C:\PROJECTS_DrvC\GlobalCursor\Cursor01.cur"
The blank cursor file is here: Download Blank Cursor
Code for the image window:
Code: Select all
If OpenWindow(0, 0, 0, 400, 400, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 400, 400) And StartDrawing(ImageOutput(0))
y = 0
For x = 0 To 95 Step 10
Box(x, y, 400-2*x, 400-2*y, RGB(Random(255), Random(255), Random(255)))
y + 20
Next x
StopDrawing()
ImageGadget(0, 0, 0, 400, 400, ImageID(0))
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Edit: In the code above, I have reduced the cursor line lengths so that they do not touch the edge of the window - I think that might be the cause of the loss-of-transparency issue.