Page 1 of 2

[Solved] Graphic Aberations seen on Win 7. Do you see them?

Posted: Tue Aug 21, 2012 4:21 am
by IdeasVacuum
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:

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 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:

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: 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 :wink:

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.

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 5:44 am
by GoodNPlenty
Tested and works without any graphic aberations using Windows 7 x64 SP1 with multi monitors using two Nvidia graphics cards. I compiled under x86 and x64 using PureBasic 4.70 beta 1.

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 5:52 am
by IdeasVacuum
Thanks for your test results GoodNPlenty - that's thrown the cat amongst the pigeons :?

I hope a few others can chime in............

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 8:17 am
by hichem
tested win7 pb 4.7 and pb 4.61(64 /32) no aberations at all

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 8:25 am
by IdeasVacuum
Thank you hichem :)

Score so far Good 2 v 1 Not Good

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 11:52 am
by breeze4me
the same problem here. win 7 32bit with the classic theme.

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 1:38 pm
by IdeasVacuum
...owch! Score so far Good 2 v 2 Not Good

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Wed Aug 22, 2012 10:22 pm
by hichem
sorry IdeasVacuum my test wasn't complete under my vm machine (windows xp) the full window is colored in pink under your cursor :oops:

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Thu Aug 23, 2012 12:02 am
by IdeasVacuum
That's interesting - Magenta is the transparency colour. I have not seen that issue before, and was expecting WinXP to be OK :shock:

Score: Good 2 v Not Good 3

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Fri Aug 24, 2012 1:48 am
by IdeasVacuum
Defined what could be a better solution, but the cursor takes 4 or 5 seconds to load:
http://www.purebasic.fr/english/viewtop ... 55#p388755

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Fri Aug 24, 2012 2:50 am
by hichem
don't work seems to be a problem with arguments in loadimage_ function look :

Code: Select all

Procedure.s WindowsLastMessage()
  Protected chars.i, message.s = Space(4096)
  Chars = FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), 0, message, Len(message), 0)
  ProcedureReturn Left(message, Chars-2)
EndProcedure  

Global ighBigCursor.i = LoadImage_(GetModuleHandle_(0),"BigCursor01",#IMAGE_CURSOR,0,0,0)


Debug WindowsLastMessage()

Debug SetSystemCursor_(ighBigCursor,#OCR_NORMAL)

Repeat

Until GetAsyncKeyState_(#VK_ESCAPE) & 1

;### Reset Cursor Pointers Set
SystemParametersInfo_(#SPI_SETCURSORS,0,#Null,#Null)
Delay(1)

in fact the program start but not show the cursor

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Fri Aug 24, 2012 3:20 am
by IdeasVacuum
Thanks for your testing hichem

...Could it be a typo in your .rc file? When I run the code here, WindowsLastMessage() returns "The operation completed successfully."

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Fri Aug 24, 2012 3:27 am
by hichem
sorry :oops:
i will see tomorrow, i'm too tired.
good coding

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Fri Aug 24, 2012 11:00 pm
by hichem
dunno why can't get it to work ???
no cursor visible, is the cursor uploaded ok?
sorry for the disturb

my fault it's work now the start is a (bit) slow but work

Re: Graphic Aberations seen on Win 7. Do you see them?

Posted: Fri Aug 24, 2012 11:14 pm
by IdeasVacuum
Yeah, the latest version works the best (cursors drawn by PB) but the start-up is too slow, still around 4 seconds.