Jump to content
argumentum

Resize control

Recommended Posts

On my PC it's dots but that probably depends on the theme. 

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

Opt( "MustDeclareVars", 1 )

Global Const $SBS_SIZEBOX  = 0x08
Global Const $SBS_SIZEGRIP = 0x10

Global $hGui, $hSizebox

Example()


Func Example()
  $hGui = GUICreate( "Resize corner", 300, 200, -1, 300, $WS_OVERLAPPEDWINDOW )
  $hSizebox = _WinAPI_CreateWindowEx( 0, "Scrollbar", "", $WS_CHILD+$WS_VISIBLE+$SBS_SIZEBOX, 300-20, 200-20, 20, 20, $hGui ) ; $SBS_SIZEBOX or $SBS_SIZEGRIP

  GUIRegisterMsg( $WM_SIZE, "WM_SIZE" )

  GUISetState()

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd

  GUIDelete( $hGui )
  Exit
EndFunc

Func WM_SIZE( $hWnd, $iMsg, $wParam, $lParam )
  Local $aSize = WinGetClientSize( $hGui )
  WinMove( $hSizebox, "", $aSize[0] - 20, $aSize[1] - 20 )
EndFunc

 

Edited by LarsJ

Share this post


Link to post
Share on other sites

that is exactly what I was asking for but for some reason I get a blinking cursor in top of the control ( as shown in the pic. ) uc?export=view&id=0B4wbNI5yp94Sb1RnQnA1b

Is there a way to avoid that ?, I'm on v3.3.14.2 Win7 x64

Thanks.

As soon as I added a button ( or any control I'd guess ), the blinking goes away. =)

Share this post


Link to post
Share on other sites

..and hello again.
I'd like to add the cursor corresponding to the function of the grip control, but I've failed to find a way. Help =/

#include <GUIConstants.au3>
#include <WinAPI.au3> ; for _WinAPI_CreateWindowEx()
#include <WinAPIRes.au3> ; for _WinAPI_LoadCursor()
#include <WinAPISys.au3> ; for _WinAPI_SetClassLongEx()

Opt("MustDeclareVars", 1)

Global Const $SBS_SIZEBOX = 0x08
Global Const $SBS_SIZEGRIP = 0x10

Global $hGui, $hSizebox

Example()

Func Example()
    $hGui = GUICreate("Resize corner", 300, 200, -1, 300, $WS_OVERLAPPEDWINDOW)

    ; this shows what I'd like to see,
    ; but obviously covers $hSizebox, making it non-functional.
    GUICtrlCreateLabel("", 300 - 20, 200 - 20, 20, 20)
    GUICtrlSetCursor(-1, 12)

    $hSizebox = _WinAPI_CreateWindowEx(0, "Scrollbar", "", $WS_CHILD + $WS_VISIBLE + $SBS_SIZEBOX, 300 - 20, 200 - 20, 20, 20, $hGui) ; $SBS_SIZEBOX or $SBS_SIZEGRIP

    Local $hCursor = _WinAPI_LoadCursor(0,$IDC_SIZENWSE) ; this is supposed to assing the cursor, but does not   =/
    _WinAPI_SetClassLongEx($hSizebox, $GCL_HCURSOR, $hCursor)

    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGui)
    Exit
EndFunc   ;==>Example

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $aSize = WinGetClientSize($hGui)
    WinMove($hSizebox, "", $aSize[0] - 20, $aSize[1] - 20)
EndFunc   ;==>WM_SIZE

 

Share this post


Link to post
Share on other sites

I'm ok with this way around. If a better way is found, please post it :)

#include <GUIConstants.au3>
#include <WinAPI.au3> ; for _WinAPI_CreateWindowEx()

Opt("MustDeclareVars", 1)

Global Const $SBS_SIZEBOX = 0x08
Global Const $SBS_SIZEGRIP = 0x10

Global $hGui, $hSizebox

Example()

Func Example()
    $hGui = GUICreate("Resize corner", 300, 200, -1, -1, $WS_OVERLAPPEDWINDOW)

    Local $idResizeLabel = GUICtrlCreateLabel("", 300 - 20, 200 - 20, 22, 22)
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    GUICtrlSetCursor(-1, 12)

    $hSizebox = _WinAPI_CreateWindowEx(0, "Scrollbar", "", $WS_CHILD + $WS_VISIBLE + $SBS_SIZEBOX, 300 - 20, 200 - 20, 20, 20, $hGui) ; $SBS_SIZEBOX or $SBS_SIZEGRIP

    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    GUISetState()
    Local $iResize = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $GUI_EVENT_PRIMARYUP
                If $iResize Then
                    $iResize = 0 ; restore the default mouse behaviour
                    GUISetCursor(2, 0, $hGui)
                    GUICtrlSetState($idResizeLabel, $GUI_SHOW)
                EndIf

            Case $idResizeLabel
                $iResize = 1
                GUICtrlSetState($idResizeLabel, $GUI_HIDE)
                GUISetCursor(12, 1, $hGui)
                MouseDown("MAIN") ; ..now that the Ctrl is hidden, nothing is held down, so we fake it ;)

        EndSwitch
    WEnd

    GUIDelete($hGui)
    Exit
EndFunc   ;==>Example

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $aSize = WinGetClientSize($hGui)
    WinMove($hSizebox, "", $aSize[0] - 20, $aSize[1] - 20)
EndFunc   ;==>WM_SIZE

 

Edited by argumentum
found a better approach

Share this post


Link to post
Share on other sites
On 12/19/2016 at 4:23 AM, argumentum said:

I'd like to add the cursor corresponding to the function of the grip control, but I've failed to find a way. Help =/

 

On 12/19/2016 at 5:30 AM, argumentum said:

I'm ok with this way around. If a better way is found, please post it

@argumentum : the thread isn't new but I just found something that may be interesting, without the label and $GUI_EVENT_PRIMARYUP workaround.

It works with _WinAPI_LoadCursorFromFile (let's hope someone will have it work with _WinAPI_LoadCursor too) . You need the external AutoIt .cur file (or .ani file) to run the script, I'm uploading them at the end of this post.

#include <APISysConstants.au3>
#include <GUIConstants.au3>
#include <WinAPIRes.au3>
#include <WinAPISysWin.au3>

Opt("MustDeclareVars", 1)

Global Const $SBS_SIZEBOX = 0x08
Global Const $SBS_SIZEGRIP = 0x10

Global $hGui, $hSizebox, $hCursor

Example()

Func Example()
    $hGui = GUICreate("Resize corner", 250, 100, -1, 300, $WS_OVERLAPPEDWINDOW)

    $hSizebox = _WinAPI_CreateWindowEx(0, "Scrollbar", "", $WS_CHILD + $WS_VISIBLE + $SBS_SIZEBOX, _
        300 - 20, 200 - 20, 20, 20, $hGui) ; $SBS_SIZEBOX or $SBS_SIZEGRIP

    $hCursor = _WinAPI_LoadCursorFromFile(@ScriptDir & '\lens.cur') ; or horse.ani, dinosaur.ani etc...
    _WinAPI_SetClassLongEx($hSizebox, $GCL_HCURSOR, $hCursor)

    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGui)
    _WinAPI_DestroyCursor($hCursor)
    Exit
EndFunc   ;==>Example

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $aSize = WinGetClientSize($hGui)
    WinMove($hSizebox, "", $aSize[0] - 20, $aSize[1] - 20)
EndFunc   ;==>WM_SIZE

1946146897_resizecorner.png.c9ae97a3da679610107e301376427ba7.png

Now we just gotta find a cursor file containing the $IDC_SIZENWSE cursor :)
I'm joining below the .cur and 2 .ani files, as found in AutoIt folders

Lens.cur

horse.ani

dinosaur.ani

 

Share this post


Link to post
Share on other sites

thanks. interesting find.
The files are in my PC. Found them in "Extras"

$hCursor = _WinAPI_LoadCursorFromFile(_PathToExtras() & '\lens.cur') ; or horse.ani, dinosaur.ani etc...
Func _PathToExtras()
    Return StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1)) & "\Examples\Helpfile\Extras"
EndFunc

so you can remove them from the post :) 

Share this post


Link to post
Share on other sites

What a headache...
Here are the cursor shapes & values as shown in the help file, when we run the example found at topic GUISetCursor

2056743362_cursorsAutoIt.png.faa648aba9cd21fe46dd80585dbe92c6.png

The values seem to match the constants found in AutoItConstants.au3, except the strange $IDC_HAND = 32649 lost in this "0 to 15"  range :

; Mouse Constants
; Indicates current mouse cursor
Global Const $IDC_UNKNOWN = 0 ; Unknown cursor
Global Const $IDC_APPSTARTING = 1 ; Standard arrow and small hourglass
Global Const $IDC_ARROW = 2 ; Standard arrow
Global Const $IDC_CROSS = 3 ; Crosshair
Global Const $IDC_HAND = 32649 ; Hand cursor
Global Const $IDC_HELP = 4 ; Arrow and question mark
Global Const $IDC_IBEAM = 5 ; I-beam
Global Const $IDC_ICON = 6 ; Obsolete
Global Const $IDC_NO = 7 ; Slashed circle
Global Const $IDC_SIZE = 8 ; Obsolete
Global Const $IDC_SIZEALL = 9 ; Four-pointed arrow pointing N, S, E, and W
Global Const $IDC_SIZENESW = 10 ; Double-pointed arrow pointing NE and SW
Global Const $IDC_SIZENS = 11 ; Double-pointed arrow pointing N and S
Global Const $IDC_SIZENWSE = 12 ; Double-pointed arrow pointing NW and SE
Global Const $IDC_SIZEWE = 13 ; Double-pointed arrow pointing W and E
Global Const $IDC_UPARROW = 14 ; Vertical arrow
Global Const $IDC_WAIT = 15 ; Hourglass

I wanted to understand why argumentum couldn't use _WinAPI_LoadCursor() to load the cursor he needed, with a  handle returned = 0 when he used the variable $IDC_SIZENWSE, then _WinAPI_GetLastError() returning 1813 ("resource not found")

So I decided to create a loop, from 0 to 32767 to test each and every value, hoping something will happen :

Local $hCursor
For $i = 0 To 32767
    $hCursor = _WinAPI_LoadCursor(0, $i)
    If $hCursor <> 0 Then
        ConsoleWrite($i & "  $hCursor = " & $hCursor & @crlf)
         ExitLoop
    EndIf
Next

Good surprise : 1st handle <> 0 appeared when $i = 100, which means that the cursor constants found in AutoItConstants.au3 are wrong... as noticed by a user 5 years ago in this link

So there are 2 ranges of values (on my computer) where cursors are found : 100 to 116 and the 32000+ (as shown at msdn)

100 / 32512 => Arrow        ( 2)
101 / 32513 => IBeam        ( 5)
102 / 32514 => Wait         (15)
103 / 32515 => Cross        ( 3)
104 / 32516 => UpArrow      (14)
105 / 32642 => SizeNWSE     (12) for argumentum
106 / 32643 => SizeNESW     (10)
107 / 32644 => SizeWE       (13)
108 / 32645 => SizeNS       (11)
109 / 32646 => SizeAll      ( 9)
110 / 32648 => No           ( 7)
111 / 32650 => AppStarting  ( 1)
112 / 32651 => Help         ( 4)
113 / 32631 => Pen          ( ?)
114 / 32649 => Hand         ( 0)
115         => TV (?)       ( ?)
116 / 32663 => CD           ( ?)
    / 32652 => North-South  ( ?)
    / 32653 => West-East    ( ?)
    / 32654 => 4 Dir        ( ?)
    / 32655 => North        ( ?)
    / 32656 => South        ( ?)
    / 32657 => West         ( ?)
    / 32658 => East         ( ?)
    / 32659 => NW           ( ?)
    / 32660 => NE           ( ?)
    / 32661 => SW           ( ?)
    / 32662 => SE           ( ?)

The list above indicates the correct constants on the left, with the corresponding erroneous AutoIt constants on the right.
Here are the cursor shapes as found on my computer

964919146_cursors2.png.9fcee02f6287454d628e2a09a39bad2a.png

And the script for argumentum, using _WinAPI_LoadCursor() to load the SizeNWSE cursor

#include <GUIConstants.au3>
#include <WinAPI.au3> ; for _WinAPI_CreateWindowEx()
#include <WinAPIRes.au3> ; for _WinAPI_LoadCursor()
#include <WinAPISys.au3> ; for _WinAPI_SetClassLongEx()

Opt("MustDeclareVars", 1)

Global Const $SBS_SIZEBOX = 0x08
Global Const $SBS_SIZEGRIP = 0x10

Global $hGui, $hSizebox

Example()

Func Example()
    $hGui = GUICreate("Resize corner", 300, 200, -1, 300, $WS_OVERLAPPEDWINDOW)

    $hSizebox = _WinAPI_CreateWindowEx(0, "Scrollbar", "", $WS_CHILD + $WS_VISIBLE + $SBS_SIZEBOX, _
        300 - 20, 200 - 20, 20, 20, $hGui) ; $SBS_SIZEBOX or $SBS_SIZEGRIP

    Local $hCursor = _WinAPI_LoadCursor(0, 32642) ; SizeNWSE

    _WinAPI_SetClassLongEx($hSizebox, $GCL_HCURSOR, $hCursor)

    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGui)
    _WinAPI_DestroyCursor($hCursor)
    Exit
EndFunc   ;==>Example

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    Local $aSize = WinGetClientSize($hGui)
    WinMove($hSizebox, "", $aSize[0] - 20, $aSize[1] - 20)
EndFunc   ;==>WM_SIZE

We finally made it :)

Edited by pixelsearch

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...