Hi Folks,
The following test code works fine under Windows XP and other OSs when %LOCALDC is set to zero (draw on the screen DC), but under Vista it is very slow. It is actually to do with the new "Aero" feature, because when Aero is disabled, the drawing is as fast as normal.
I guess my question is: does anyone know of a workaround or switch to speed up the screen DC drawing when run in Vista's Aero mode? I need the whole screen DC as the actual code will need to draw outside of any windows.
I have included the %LOCALDC flag to demonstrate the speed for Vista users.
The following test code works fine under Windows XP and other OSs when %LOCALDC is set to zero (draw on the screen DC), but under Vista it is very slow. It is actually to do with the new "Aero" feature, because when Aero is disabled, the drawing is as fast as normal.
I guess my question is: does anyone know of a workaround or switch to speed up the screen DC drawing when run in Vista's Aero mode? I need the whole screen DC as the actual code will need to draw outside of any windows.
I have included the %LOCALDC flag to demonstrate the speed for Vista users.
Code:
#Compile Exe #Dim All #Include "WIN32API.INC" #Include "TYPES.INC" %THICKNESS = 5 ' Line thickness (must be 1 or greater). %STYLE = 0 ' Line style (0 solid, 1 animated). %LOCALDC = 1 ' DC mode (0 use screen DC, 1 Use dialog DC). Global GHDC As Dword ' Device context. '------------------------------------------------------------------------------ ' Draws a normal or animated border rectangle to specified DC. '------------------------------------------------------------------------------ Function DrawOutline(ByVal hDC As THANDLE, _ ByVal rc As RECT, _ ByVal nThickness As TINT, _ ByVal nAnimated As TINT) As TINT Local i As TINT Local hPen As THANDLE Local hOldPen As THANDLE Local hBrush As THANDLE Local hOldBrush As THANDLE Local nDrawMode As TINT ' Must have DC and rectangle... If (hDC = %NULL) Or (IsRectEmpty(rc) <> %FALSE) Then Exit Function If nAnimated Then ' Draws a Win95 style animated border... For i = 1 To nThickNess DrawFocusRect hDc, rc InflateRect rc, 1, 1 Next i Else ' Draws an old fashioned border... ' Select GDI objects, etc, hPen = CreatePen(%PS_INSIDEFRAME, 0, 0) hOldPen = SelectObject(hDC, hPen) hBrush = GetStockObject(%NULL_BRUSH) hOldBrush = SelectObject(hDC, hBrush) nDrawMode = SetROP2(hDC, %R2_NOT) For i = 1 To nThickNess ' Draw rectangle Rectangle hDC, rc.nLeft, rc.nTop, rc.nRight, rc.nBottom InflateRect rc, 1, 1 Next i ' Restore DC SetROP2 hDC, nDrawMode SelectObject hDC, hOldBrush SelectObject hDC, hOldPen ' Delete GDI objects DeleteObject hPen End If Function = %TRUE End Function CallBack Function DLGPROC Select Case CbMsg Case %WM_INITDIALOG ' Select DC to draw into... #If %LOCALDC '##### Very fast on vista, but will not draw outside of window... gHDC = GetDC(CbHndl) #Else '##### All very slow on Vista... 'ghDC = GetDC(%NULL) 'ghDC = GetDC(GetDesktopWindow) ghDC = CreateDC("DISPLAY", ByVal %NULL, ByVal %NULL, ByVal %NULL) #EndIf Case %WM_MOUSEMOVE Static rcOld As RECT Local rc As RECT ' MAKE NEW GETCURSORPOS ByVal VarPtr(RC) ' Only needs first 8 bytes (left/top). #If %LOCALDC ScreenToClient CbHndl, ByVal VarPtr(RC) ' Only needs first 8 bytes (left/top). #EndIf RC.NRIGHT = RC.NLEFT + 100 RC.NBOTTOM = RC.NTOP + 100 ' NO DUPES If (RCOLD = RC) Then Exit Function ' CLEAR OLD DrawOutline ghDC, rcOld, %THICKNESS, %STYLE ' DRAW NEW DrawOutline ghDC, rc, %THICKNESS, %STYLE ' SAVE NEW RCOLD = RC Case %WM_DESTROY #If %LOCALDC ReleaseDC CbHndl, gHDC #Else DeleteDC gHDC #EndIf End Select End Function Function PBMain Local HDLG As Dword Dialog New 0, "DRAG TEST FOR VISTA", , , 400, 300, %WS_OVERLAPPEDWINDOW To HDLG Dialog Show Modal HDLG Call DLGPROC End Function
Comment