Jump to content

_WinAPI_RedrawWindow does not seem to work in Windows 8.1


ahha
 Share

Go to solution Solved by ahha,

Recommended Posts

Upgraded to Windows 8.1 and dual monitor.
Have a program that uses _WinAPI_RedrawWindow that does not seem to work.  Tried example in help file and it does not erase cross.  See notation below.  What am I doing wrong?

(forgot how to include code in a separate window - sorry)

#include <WindowsConstants.au3>
#include <WinAPI.au3>

ShowCross(@DesktopWidth / 2, @DesktopHeight / 2, 20, 2, 0xFF, 3000)

Func ShowCross($start_x, $start_y, $length, $width, $color, $time)
    Local $hDC, $hPen, $obj_orig

    $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    $hPen = _WinAPI_CreatePen($PS_SOLID, $width, $color)
    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)

    _WinAPI_DrawLine($hDC, $start_x - $length, $start_y, $start_x - 5, $start_y) ; horizontal left
    _WinAPI_DrawLine($hDC, $start_x + $length, $start_y, $start_x + 5, $start_y) ; horizontal right
    _WinAPI_DrawLine($hDC, $start_x, $start_y - $length, $start_x, $start_y - 5) ; vertical up
    ;    _WinAPI_DrawLine($hDC, $start_x, $start_y + $length, $start_x, $start_y + 5) ; vertical down
    _WinAPI_MoveTo($hDC, $start_x, $start_y + $length)
    _WinAPI_LineTo($hDC, $start_x, $start_y + 5)

    Sleep($time) ; show cross over screen for defined seconds

    ; refresh desktop (clear cross)
    _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)    ;<<<<<< does not seem to work

    ; clear resources
    _WinAPI_SelectObject($hDC, $obj_orig)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>ShowCross

Edited by ahha
Link to comment
Share on other sites

Try this one:

#include <WindowsConstants.au3>
#include <WinAPI.au3>

ShowCross(@DesktopWidth / 2, @DesktopHeight / 2, 20, 2, 0xFF, 3000)

Func ShowCross($start_x, $start_y, $length, $width, $color, $time)
    Local $hDC, $hPen, $obj_orig

    $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    $hPen = _WinAPI_CreatePen($PS_SOLID, $width, $color)
    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)

    _WinAPI_DrawLine($hDC, $start_x - $length, $start_y, $start_x - 5, $start_y) ; horizontal left
    _WinAPI_DrawLine($hDC, $start_x + $length, $start_y, $start_x + 5, $start_y) ; horizontal right
    _WinAPI_DrawLine($hDC, $start_x, $start_y - $length, $start_x, $start_y - 5) ; vertical up
    ;    _WinAPI_DrawLine($hDC, $start_x, $start_y + $length, $start_x, $start_y + 5) ; vertical down
    _WinAPI_MoveTo($hDC, $start_x, $start_y + $length)
    _WinAPI_LineTo($hDC, $start_x, $start_y + 5)

    Sleep($time) ; show cross over screen for defined seconds

    ; refresh desktop (clear cross)
    _WinAPI_RedrawWindow(WinGetHandle("[active]"), 0, 0, BitOR($RDW_INVALIDATE, $RDW_ALLCHILDREN)) ;<<<<<< does not seem to work

    ; clear resources
    _WinAPI_SelectObject($hDC, $obj_orig)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>ShowCross
Edited by Unc3nZureD
Link to comment
Share on other sites

Unc3nZureD, - No difference.  It clearly is an issue with _WinAPI_RedrawWindow

I'm wondering if in Windows 8.1 the desktop or "active window" is somehow different.

Can anyone else run these scripts and verify behaviour? 

Link to comment
Share on other sites

  • Solution

Okay found a similiar thread but with a rectangle issue here:

It looks like calling _WinAPI_RedrawWindow like this takes care of the desktop

_WinAPI_RedrawWindow(ControlGetHandle("[Class:WorkerW]", "", "SysListView321"), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)

Malkey notes this works for windows 7 and it also seems to work for windows 8.1, as does this

_WinAPI_RedrawWindow(ControlGetHandle("[Class:SysListView32]", "", "SysListView321"), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)

I'll check it out furhter and report back - looks like _WinAPI_GetDesktopWindow() or getting the handle to the desktop may be the issue.

Link to comment
Share on other sites

Well, if you compare the handles than you will see that they are different:
 

#include <WinAPI.au3>

ConsoleWrite(_WinAPI_GetDesktopWindow() & @CRLF)
ConsoleWrite(WinGetHandle("[active]") & @CRLF)

That means _WinAPI_GetDesktopWindow() isn't working for Win8. Why? Good question. MSDN needs to be asked...

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...