Jump to content

Window flickering when resizing


Go to solution Solved by ioa747,

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

3 minutes ago, KaFu said:

Add a sleep(10) to the _ispressed loop?

The frame is still blinking. I want to make a frame without content and with the ability to resize. (sorry for English).

Link to comment
Share on other sites

Link to comment
Share on other sites

14 minutes ago, Nine said:

It does not flicker on me (maybe my comp is fast enough), but you could try to use $WS_EX_COMPOSITED in your main GUI creation.  See if that helps.

$WS_EX_COMPOSITED - unfortunately it didn't help (((((

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

  • Solution

Local $RM_mode = False ; * <-- try this option with True or False

what I noticed is that
when you drag it to the right or down, it becomes smooth.
When you drag left or up, it flickers

; https://www.autoitscript.com/forum/topic/212427-window-flickering-when-resizing/?do=findComment&comment=1538161
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>

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

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

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_PRIMARYDOWN
            ; Get the position and size of window
            Local $winPos = WinGetPos($hGUI)
            Local $winX = $winPos[0]
            Local $winY = $winPos[1]
            Local $winWidth = $winPos[2]
            Local $winHeight = $winPos[3]

            ; Get the current mouse position
            Local $mousePos = MouseGetPos()
            Local $mouseX = $mousePos[0]
            Local $mouseY = $mousePos[1]

            ; Check if mouse is in any window edge
            Local $iLeftEdge = Abs($mouseX - $winX) < $size
            Local $iRightEdge = Abs($mouseX - ($winX + $winWidth)) < $size
            Local $iTopEdge = Abs($mouseY - $winY) < $size
            Local $iBottomEdge = Abs($mouseY - ($winY + $winHeight)) < $size

            Local $RM_mode = False ; * <-- try this option with True or False

            ; If the Left  mouse button is pressed and we are in any window edge
            ; If _IsPressed("01") And ($iLeftEdge Or $iRightEdge Or $iTopEdge Or $iBottomEdge) Then
            If $iLeftEdge Or $iRightEdge Or $iTopEdge Or $iBottomEdge Then
                Local $resizeMode = 0

                ; Check the active edge
                If $iLeftEdge Then $resizeMode += 1
                If $iRightEdge Then $resizeMode += 2
                If $iTopEdge Then $resizeMode += 4
                If $iBottomEdge Then $resizeMode += 8

                Do  ; resizing mode
                    $mousePos = MouseGetPos()
                    $mouseX = $mousePos[0]
                    $mouseY = $mousePos[1]

                    ; resizing / moving mode
                    If $RM_mode Then
                        $winPos = WinGetPos($hGUI)
                        $winX = $winPos[0]
                        $winY = $winPos[1]
                    EndIf

                    ; Moves / resizes the window to mouse position
                    Switch $resizeMode
                        Case 1 ; Left edge
                            Local $aPos = [$mouseX, $winY, $winWidth + ($winX - $mouseX), $winHeight]
                        Case 2 ; Right edge
                            Local $aPos = [$winX, $winY, $mouseX - $winX, $winHeight]
                        Case 4 ; Top edge
                            Local $aPos = [$winX, $mouseY, $winWidth, $winHeight + ($winY - $mouseY)]
                        Case 8 ; Bottom edge
                            Local $aPos = [$winX, $winY, $winWidth, $mouseY - $winY]
                        Case 5 ; Top-left corner
                            Local $aPos = [$mouseX, $mouseY, $winWidth + ($winX - $mouseX), $winHeight + ($winY - $mouseY)]
                        Case 6 ; Top-right corner
                            Local $aPos = [$winX, $mouseY, $mouseX - $winX, $winHeight + ($winY - $mouseY)]
                        Case 9 ; Bottom-left corner
                            Local $aPos = [$mouseX, $winY, $winWidth + ($winX - $mouseX), $mouseY - $winY]
                        Case 10 ; Bottom-right corner
                            Local $aPos = [$winX, $winY, $mouseX - $winX, $mouseY - $winY]
                    EndSwitch

                    WinMove($hGUI, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3])
                    _Hole($hGUI, $size, $size, $aPos[2] - 2 * $size, $aPos[3] - 2 * $size, $aPos[2], $aPos[3])

                    Sleep(10)
                Until Not _IsPressed("01") ; Exit resizing mode when mouse button is released
            EndIf
            Sleep(10)

    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 _Exit()
    Exit
EndFunc   ;==>_Exit

 

Edited by ioa747

I know that I know nothing

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