Jump to content
TheAutomator

Resize window using picture control

Recommended Posts

Is there a (simple) way to make your script using a picture-control to resize the gui?
This would be useful for a transparant pop-up window with a custom made theme using picture controls:

$Form = GUICreate('', 301, 173, 5, 5, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))

GUICtrlCreatePic(@scriptdir & "\resize_win.bmp", 0, 73, 20, 51)
; some api call or code telling the os to use this picture as a resize border
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUISetState(@SW_SHOW)

While True
    if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit
WEnd

 

EDIT: to make it more clear what i wanna do, if you go with the mouse arrow over the border of a re-sizable window the arrow changes to a "resize" arrow, you click and drag the border and then the window size adjusts to the mouse position until you release the mouse button.
I want my picture control to be used the same way as the resize border to resize my window.

Edited by TheAutomator

Share this post


Link to post
Share on other sites

This may help:

 


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

If this is what you are looking for

;coded by UEZ
#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

AutoItSetOption("GUICoordMode", 2)

Global Const $STM_SETIMAGE = 0x0172
Global $sPathKey = "HKLM64\SOFTWARE\AutoIt v3\AutoIt\"
If @OSArch = "x64" Then $sPathKey = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt\"
Global $sImage = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\logo4.gif"

_GDIPlus_Startup()
Global $hBmp = _GDIPlus_BitmapCreateFromFile($sImage)
Global $iW = _GDIPlus_ImageGetWidth($hBmp), $iH = _GDIPlus_ImageGetHeight($hBmp), $iWG = 600, $iHG = 300

Global $hGUI = GUICreate("Test", $iWG, $iHG, -1, -1, -1, $WS_EX_COMPOSITED)
Global $idPic = GUICtrlCreatePic("", ($iWG - $iW) / 2, ($iHG - $iH) / 2, $iW, $iH, -1, $WS_EX_STATICEDGE)

Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
Global $hB = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
If $hB Then _WinAPI_DeleteObject($hB)
GUISetState(@SW_SHOW)

Global $aMPos, $aCPos = ControlGetPos($hGUI, "", $idPic)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_BitmapDispose($hBmp)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $GUI_EVENT_RESTORE
            ControlMove($hGUI, "", $idPic, $aCPos[0], $aCPos[1], $aCPos[2], $aCPos[3])
    EndSwitch
    $aMPos = GUIGetCursorInfo($hGUI)
    Switch $aMPos[4]
        Case $idPic
            $aCPos = ControlGetPos($hGUI, "", $idPic)
            If $aMPos[0] = $aCPos[0] Then ;border west
                GUISetCursor(13, 1, $hGUI)
                If $aMPos[2] Then
                    While $aMPos[2]
                        $aMPos = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $idPic, $aMPos[0], $aCPos[1], $aCPos[2] + $aCPos[0] - $aMPos[0], $aCPos[3])
                    WEnd
                EndIf
            ElseIf $aMPos[0] = $aCPos[0] + $aCPos[2] Then ;border east
                GUISetCursor(13, 1, $hGUI)
                If $aMPos[2] Then
                    While $aMPos[2]
                        $aMPos = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $idPic, $aCPos[0], $aCPos[1], $aMPos[0] - $aCPos[0], $aCPos[3])
                    WEnd
                EndIf
            ElseIf $aMPos[1] = $aCPos[1] + $aCPos[3] Then ;border north
                GUISetCursor(11, 1, $hGUI)
                If $aMPos[2] Then
                    While $aMPos[2]
                        $aMPos = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $idPic, $aCPos[0], $aCPos[1], $aCPos[2], $aMPos[1] - $aCPos[1])
                    WEnd
                EndIf
            ElseIf $aMPos[1] = $aCPos[1] Then ;border south
                GUISetCursor(11, 1, $hGUI)
                If $aMPos[2] Then
                    While $aMPos[2]
                        $aMPos = GUIGetCursorInfo($hGUI)
                        ControlMove($hGUI, "", $idPic, $aCPos[0], $aMPos[1], $aCPos[2], $aCPos[3] + $aCPos[1] - $aMPos[1])
                    WEnd
                EndIf
            Else
                GUISetCursor(2, 1, $hGUI)
            EndIf
        Case Else
            GUISetCursor(2, 1, $hGUI)
    EndSwitch
WEnd

then adding the 4 corners is homework for you. ;)

Edited by 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Another great one from UEZ :)

In case one finds it a bit difficult to grab exactly the desired edge, it should be possible to give him some space :

; If $aMPos[0] = $aCPos[0] Then ;border west
If $aMPos[0] >= $aCPos[0] - 3 And $aMPos[0] <= $aCPos[0] + 3 Then ;border west

; a little homework for the 3 other borders :)

 

Edited by pixelsearch

Share this post


Link to post
Share on other sites

its an interesting workaround for resizing a picture inside a window but i think you still not quite get what i meant..
i'm sorry if my question wasn't clear, i want to use the picture to resize the window
anyways, i maybe can alter the code so it resizes the window and not the picture

i thought the grip on the window edge was a control itself that could be placed anywhere on a window with some sort of api call, maybe a simple mousepos and winmove is the most simple solution?

Thanks for the example :)

 

Edited by TheAutomator

Share this post


Link to post
Share on other sites
12 hours ago, pixelsearch said:

In case one finds it a bit difficult to grab exactly the desired edge

Well, if you hold the lmb pressed and move the mouse cursor over the frames slowly it will automatically catch it.


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
10 hours ago, TheAutomator said:

i want to use the picture to resize the window

Sorry but I don't understand what you want exactly. 


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

When is the window enlarged ? When the picture hits the border ? At the moment the picture starts moving ?  How do you reduce the window ? How do we know what type of arrow cursor to use ?

I think this is the kind of questions...

Edited by Nine

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:

When is the window enlarged ? When the picture hits the border ? At the moment the picture starts moving ?  How do you reduce the window ? How do we know what type of arrow cursor to use ?

I think this is the kind of questions...

oh okay, well

i'm planning on using 4 pictures, top, bottom, left,right and they are on a transparent popup window.
hover over for example the right image and the horizontal resize arrow appears
when for example the mouse clicks and drags on the bottom picture, the form starts to change shape vertically at the bottom like it would if you would click-drag the bottom grip on a normal re sizable form.

the image is supposed to be saying at the bottom in this case

Edited by TheAutomator

Share this post


Link to post
Share on other sites

Use the picture to trigger a WinMove, you can use the picture like you would a button control.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Well like @BrewManNH said you can use winmove.  I modified @UEZ script to give you an idea how it can be done...

#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Opt ("MustDeclareVars", 1)

AutoItSetOption("GUICoordMode", 2)

Global $sPathKey = "HKLM64\SOFTWARE\AutoIt v3\AutoIt\"
If @OSArch = "x64" Then $sPathKey = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt\"
Global $sImage = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\logo4.gif"

_GDIPlus_Startup()
Global $hBmp = _GDIPlus_BitmapCreateFromFile($sImage)
Global $iW = _GDIPlus_ImageGetWidth($hBmp), $iH = _GDIPlus_ImageGetHeight($hBmp), $iWG = 600, $iHG = 300

Global $hGUI = GUICreate("Moving Pictures", $iWG, $iHG, -1, -1, -1, $WS_EX_COMPOSITED)
Global $idPic = GUICtrlCreatePic("", ($iWG - $iW) / 2, ($iHG - $iH) / 2, $iW, $iH)

Global $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
Global $hB = GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
If $hB Then _WinAPI_DeleteObject($hB)
GUISetState(@SW_SHOW)

Global $aMPos, $aCPos = ControlGetPos($hGUI, "", $idPic), $dx, $dy, $aWPos = WinGetPos ($hGUI)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($hHBitmap)
            _GDIPlus_BitmapDispose($hBmp)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $GUI_EVENT_RESTORE
            ControlMove($hGUI, "", $idPic, $aCPos[0], $aCPos[1], $aCPos[2], $aCPos[3])
    EndSwitch
    $aMPos = GUIGetCursorInfo($hGUI)
    if $aMPos[4] <> $idPic then ContinueLoop
    $aCPos = ControlGetPos($hGUI, "", $idPic)
    $dx = $aCPos[0]-$aMPos[0]
    $dy = $aCPos[1]-$aMPos[1]
    if $aMpos[2] then
        GUISetCursor($IDC_SIZEALL, $GUI_CURSOR_OVERRIDE, $hGUI)
        While $aMpos[2]
            $aMPos = GUIGetCursorInfo($hGUI)
            $aCPos = ControlGetPos($hGUI, "", $idPic)
            ControlMove($hGUI, "", $idPic, $aMPos[0]+$dx, $aMPos[1]+$dy, $aCPos[2], $aCPos[3])
            if $aCPos[0] < 0 then
                WinMove ($HGui, "", $aWPos[0]+$aCPos[0],$aWPos[1],$aWPos[2]-$aCPos[0],$aWPos[3])
                $aWPos = WinGetPos ($hGUI)
            endif
            if $aCPos[1] < 0 then
                WinMove ($HGui, "", $aWPos[0],$aWPos[1]+$aCPos[1],$aWPos[2],$aWPos[3]-$aCPos[1])
                $aWPos = WinGetPos ($hGUI)
            endif
        Wend
        GUISetCursor($IDC_ARROW, $GUI_CURSOR_OVERRIDE, $hGUI)
    endif
WEnd

Only done Left and Top edges, but you will be able to create the wanted script.

Share this post


Link to post
Share on other sites
16 minutes ago, Nine said:

Well like @BrewManNH said you can use winmove.  I modified @UEZ script to give you an idea how it can be done...

Only done Left and Top edges, but you will be able to create the wanted script.

the picture doesn't have to move
ill try to alter the code, i think the gdi stuff is not necessary
i post my code later

Share this post


Link to post
Share on other sites

If it doesn't have to move then you can do what I said, use the picture as a trigger for a function to resize the window. I didn't say it was a button, I said you can use it like a button. I don't understand why you keep saying click-drag and then saying it doesn't have to move. Either it's moving (being dragged i.e. click-drag) or it's stationary, pick one and stop moving the goals.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
9 hours ago, BrewManNH said:

If it doesn't have to move then you can do what I said, use the picture as a trigger for a function to resize the window. I didn't say it was a button, I said you can use it like a button. I don't understand why you keep saying click-drag and then saying it doesn't have to move. Either it's moving (being dragged i.e. click-drag) or it's stationary, pick one and stop moving the goals.

i didn't move the goal, if you resize a normal window you also press the main mouse button down while resizing the window, isn't that a click drag operation until you release the mouse button?

Edited by TheAutomator

Share this post


Link to post
Share on other sites

the code i end up with:

While True
    Local $win = WinGetPos($Form)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Left; image control on the left side of the form
            While GUIGetCursorInfo($Form)[2] = 1
                Local $y = MouseGetPos()[0] - 15; the image distance from the side of the form is 15 here
                WinMove($Form,'',$y,$win[1], $win[2] + $win[0] - $y,$win[3])
            WEnd
        Case $Top
            While GUIGetCursorInfo($Form)[2] = 1
                Local $x = MouseGetPos()[1] - 15
                WinMove($Form,'',$win[0], $x, $win[2],$win[3] + $win[0] - $x)
            WEnd
        Case $Right
            While GUIGetCursorInfo($Form)[2] = 1
                WinMove($Form,'',$win[0],$win[1], MouseGetPos()[0] - $win[0] + 15 ,$win[3])
            WEnd
        Case $Bottom
            While GUIGetCursorInfo($Form)[2] = 1
                WinMove($Form,'',$win[0],$win[1] , $win[2], MouseGetPos()[1] - $win[1] + 15)
            WEnd
    EndSwitch
WEnd

Again, sorry if i wasn't as clear as i thought, at the end i could use the code examples given by you guys and extract the necessary info from it :)

Thanks for the help!

Edited by TheAutomator

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

  • Similar Content

    • By nacerbaaziz
      hello sirs, please i created a tool witch get the focused control in a window and play a audio file linked with this controls
      e.g buttons, checkBoxes, radios, comboboxes, and others
      i know that their is a function that give us the control focus but it return the classNN
      i want to get the class name to use it with a switch and
      because their are more than class e.g button tbutton timagebutton tnewButton...
      please can any one help me to get the class name not the classnn
      thanks in advance
    • By nacerbaaziz
      Hello my friends
      Can we create a single context menu on more than one item?
      For example, a context menu includes standardized options on more than one control, such as buttons or check boxes
      to Create a context menu on one item am using this function
      GUICtrlCreateContextMenu ($ HWND)
      How to link it with more than one element please?
      or if we can't do that, please give me a solution
      so i tried to add an context menus to all the controls but the script will be long, for that if their are any solutions i hope to give it to me
      thanks in advanced
    • By ur
      An application is there which is created using vc++,mostly mfc.
       
      DOn't know the details completely.
       
      WHen I try to automate the control clicks for testing the UI.
      THe below control is not detected.
      As you can see, during UI operations I can click the elements one by one.
      But all the elements is selected as a whole set, when I use the Windowinfo tool.

       
      How to click this using AutoIT.?
       
      Please suggest.
    • By nacerbaaziz
      Hi dear
      This is the first include file I designed
      This work is especially directed to NVDA free screen reader users
      It contains a set of functions that enable you to control the program
      Such as forcing the program to read a custom text
      Force it to stop talking
      Find out if the program is running
      And show custom text in the Braille screen
      Available functions are
      _nvdaControllerClient_Load()
      to load the dll file
      _nvdaControllerClient_free()
      to UnLoad the dll file
      _nvdaControllerClient_SpeakText()
      to speak a custom text
      _nvdaControllerClient_brailleMessage()
      to show custom text in the Braille screen
      _nvdaControllerClient_cancelSpeech()
      to Force the NVDA  to stop talking
      _nvdaControllerClient_testIfRunning()
      to check if the NVDA is running
      important note :
      All of these functions depend on a nvdaControllerClient32.dll
      I've added it in the attachments, as well as a file for examples, and other files
      As the source and examples in other languages
      For those who wanted to download the free screen reader, this is the download link from the official website
      https://www.nvaccess.org/download/
      i hope you like this topic
      I hope you will try it and give me your opinions
      Thank you all members and administrators for their help
      now with the  Attachments
       
      nvdaControllerClient_UDF.zip
    • By therks
      I'm trying to create a simple clock widget that automatically scales the text to the size of the window. I came up with the following method, but it doesn't work as well as I'd like. It especially has trouble scaling to the width of the window for some reason (in the example, try resizing the window to be narrow and tall).
      Does anyone have a better method?
      #include <Misc.au3> #include <WinAPIConv.au3> #include <GUIConstants.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) Global $_FONT_FAMILY = 'Arial', $_LB_TEXT Main() Func Main() _GDIPlus_Startup() Local $hGUI GUIRegisterMsg($WM_SIZE, WM_SIZE) $hGUI = GUICreate('', 300, 100, Default, Default, $WS_OVERLAPPEDWINDOW, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $_LB_TEXT = GUICtrlCreateLabel('This is a string', 0, 0, 300, 100, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($_LB_TEXT, _MeasureString($hGUI, GUICtrlRead($_LB_TEXT), $_FONT_FAMILY), 0, 0, $_FONT_FAMILY, 5) GUISetState() Local $iGM While 1 $iGM = GUIGetMsg() Switch $iGM Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GDIPlus_Shutdown() EndFunc Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) GUICtrlSetFont($_LB_TEXT, _MeasureString($hWnd, GUICtrlRead($_LB_TEXT), $_FONT_FAMILY), 0, 0, $_FONT_FAMILY, 5) EndFunc Func _MeasureString($hWnd, $sString, $sFont = 'Arial') Local $iError, $aSize, $hGraphic, $hFormat, $hFamily, $tLayout, $iFontSize, $hFont, $aInfo If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) EndIf $aSize = WinGetClientSize($hWnd) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($sFont) $tLayout = _GDIPlus_RectFCreate(0, 0, $aSize[0], $aSize[1]) $iFontSize = 0 Do If Not $hFamily Then $iError = 1 $iFontSize = 10 ExitLoop EndIf $iFontSize += 1 $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_FontDispose($hFont) If $aInfo[1] = 0 Then ExitLoop Until DllStructGetData($aInfo[0], 3) >= $aSize[0] Or DllStructGetData($aInfo[0], 4) >= $aSize[1] $iFontSize -= 1 _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return SetError($iError, 0, $iFontSize) EndFunc
×
×
  • Create New...