Jump to content

Window flickering when resizing


SEKOMD
 Share

Recommended Posts

(sorry, I use google translator)

Is there any way to get rid of the window flickering when resizing? (pull upper left corner)

 

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

HotKeySet("{ESC}", "_Exit")

Local $hGUI = GUICreate("", 400, 400, -1, -1, $WS_POPUP)
Local $hLabel = GUICtrlCreateLabel("", 0, 0, 400, 400)
Local $aPos = WinGetPos($hGUI)
_Hole($hGUI, 20, 20, $aPos[2] - 2 * 20, $aPos[3] - 2 * 20, $aPos[2], $aPos[3])
GUISetBkColor(0x000000)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_PRIMARYDOWN
            $iX = WinGetPos($hGUI)[0]
            $iY = WinGetPos($hGUI)[1]
            $iWidth = WinGetPos($hGUI)[2]
            $iHeight = WinGetPos($hGUI)[3]

            $temp_x = MouseGetPos(0)-$iX
            $temp_y = MouseGetPos(1)-$iY
            $MouseGetPos_X_Start = MouseGetPos(0)
            $MouseGetPos_Y_Start = MouseGetPos(1)

            While _IsPressed('01')
                $MouseGetPos_X = MouseGetPos(0)
                $MouseGetPos_Y = MouseGetPos(1)

                $iWidth_New = ($MouseGetPos_X_Start-$MouseGetPos_X)+$iWidth
                $iHeight_New = ($MouseGetPos_Y_Start-$MouseGetPos_Y)+$iHeight

                WinMove($hGUI,'', $MouseGetPos_X-$temp_x, $MouseGetPos_Y-$temp_y, $iWidth_New, $iHeight_New) ;flickering

                ;=======================================================
                $aPos = WinGetPos($hGUI)
                $size = 20
                _Hole($hGUI, $size, $size, $aPos[2] - 2 * $size, $aPos[3] - 2 * $size, $aPos[2], $aPos[3])
            WEnd

            ;Drag_Window()
    EndSwitch
WEnd


Func _Hole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $Height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $Height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($h_win, $combined_rgn)
EndFunc   ;==>_Hole

Func Drag_Window()
    _SendMessage($hGUI, $WM_SYSCOMMAND, 0xF012, 0)
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Here my attempt on it (finally saw what you are seeing although it is quite lite on me) :

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

Opt("MustDeclareVars", True)

HotKeySet("{ESC}", Terminate)

Local $hMainGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
WinSetTrans($hMainGUI, "", 60)
GUISetState()

Local $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

Local $nLeft = @DesktopWidth / 2 - 200, $nTop = @DesktopHeight / 2 - 200, $nWidth = 400, $nHeight = 400
Rect($hGUI, $nLeft, $nTop, $nWidth, $nHeight)
GUISetBkColor(0x000000)
GUISetState()

Local $iMouseX, $iMouseY, $iMouseNewX, $iMouseNewY

While True
  Switch GUIGetMsg()
    Case $GUI_EVENT_PRIMARYDOWN
      $iMouseX = MouseGetPos(0)
      $iMouseY = MouseGetPos(1)

      ; based on mouse pos you should decide what will be the drag type
      ; only done bottom - right (everywhere)
      GUISetCursor($MCID_SIZENWSE , $GUI_CURSOR_OVERRIDE, $hMainGUI)

      While _IsPressed('01')
        $iMouseNewX = MouseGetPos(0)
        $iMouseNewY = MouseGetPos(1)

        ;$nLeft = $iMouseNewX - $iMouseX + $nLeft
        ;$nTop = $iMouseNewY - $iMouseY + $nTop
        $nWidth = $iMouseNewX - $iMouseX + $nWidth
        $nHeight = $iMouseNewY - $iMouseY + $nHeight

        Rect($hGUI, $nLeft, $nTop, $nWidth, $nHeight)
        $iMouseX = $iMouseNewX
        $iMouseY = $iMouseNewY
      WEnd
      GUISetCursor()
  EndSwitch
WEnd

Func Rect($hWnd, $iX, $iY, $iWidth, $iHeight)
  Local $hMain = _WinAPI_CreateRectRgn(0, 0, 0, 0)
  Local $hMask = _WinAPI_CreateRectRgn($iX, $iY, $iX + $iWidth, $iY + $iHeight)
  _WinAPI_CombineRgn($hMain, $hMask, $hMain, $RGN_OR)
  _WinAPI_DeleteObject($hMask)
  $hMask = _WinAPI_CreateRectRgn($iX + 5, $iY + 5, $iX + $iWidth - 5, $iY + $iHeight - 5)
  _WinAPI_CombineRgn($hMain, $hMain, $hMask, $RGN_DIFF)
  _WinAPI_DeleteObject($hMask)
  _WinAPI_SetWindowRgn($hWnd, $hMain)
EndFunc   ;==>Rect

Func Terminate()
  Exit
EndFunc   ;==>Terminate

As mentioned in the script I only done bottom right drag...

Edited by Nine
better code
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...