Jump to content

Send GUICrtlSetImage command change icon placement


claude21
 Share

Recommended Posts

I've a problem with icon placement changing when I send command GUICrtlSetImage to change the icon image, but only when the main window has been maximized first.

here a simple example code :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 300, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("icon should stay in right corner", 10, 200, 380, 17, $WS_GROUP)
$Label2 = GUICtrlCreateLabel("1st maximize the window, then, click update", 10, 180, 250, 17)
$Icon1 = GUICtrlCreateIcon(@SystemDir & "\shell32.dll", -14, 376, 264, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))
$Button1 = GUICtrlCreateButton("Update icon", 32, 272, 100, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1

            GUICtrlSetImage($Icon1, @SystemDir & "\shell32.dll", -12)
            GUICtrlSetData($Label1, "Why the icon moved when Label stay in his original position ? ")

    EndSwitch
WEnd

What should I do to prevent icon changing her position when window is maximized ? I searched but found nothing so far.

Link to comment
Share on other sites

Use the GUICtrlSetResizing() function for each control.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("icon should stay in right corner", 10, 200, 380, 17, $WS_GROUP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Label2 = GUICtrlCreateLabel("1st maximize the window, then, click update", 10, 180, 250, 17)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Icon1 = GUICtrlCreateIcon(@SystemDir & "\shell32.dll", -14, 376, 264, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Button1 = GUICtrlCreateButton("Update icon", 32, 272, 100, 25, $WS_GROUP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetImage($Icon1, @SystemDir & "\shell32.dll", -12)
            GUICtrlSetData($Label1, "Why the icon moved when Label stay in his original position ? ")
    EndSwitch
WEnd
Edited by Yashied
Link to comment
Share on other sites

Hi

GUICtrlSetResizing for each controls doesn't work either, I've just run the script and the icon doesn't stay in where it should be. Any working solution ?

Use the GUICtrlSetResizing() function for each control.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("icon should stay in right corner", 10, 200, 380, 17, $WS_GROUP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Label2 = GUICtrlCreateLabel("1st maximize the window, then, click update", 10, 180, 250, 17)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Icon1 = GUICtrlCreateIcon(@SystemDir & "\shell32.dll", -14, 376, 264, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Button1 = GUICtrlCreateButton("Update icon", 32, 272, 100, 25, $WS_GROUP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetImage($Icon1, @SystemDir & "\shell32.dll", -12)
            GUICtrlSetData($Label1, "Why the icon moved when Label stay in his original position ? ")
    EndSwitch
WEnd

Link to comment
Share on other sites

Hi

GUICtrlSetResizing for each controls doesn't work either, I've just run the script and the icon doesn't stay in where it should be. Any working solution ?

Yes, that is a problem with sending that message because the design position is used to redraw the image. The fix I use is like this

#include <ButtonConstants.au3>#include <GUIConstantsEx.au3>#include <StaticConstants.au3>#include <WindowsConstants.au3>#Region ### START Koda GUI section ### Form=$Form2 = GUICreate("Form1", 413, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX,$WS_SIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))$Label1 = GUICtrlCreateLabel("icon should stay in right corner", 10, 200, 380, 17, $WS_GROUP)GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))$Label2 = GUICtrlCreateLabel("1st maximize the window, then, click update", 10, 180, 250, 17)GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))$Icon1 = GUICtrlCreateIcon(@SystemDir & "\shell32.dll", -14, 376, 264, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))$Button1 = GUICtrlCreateButton("Update icon", 32, 272, 100, 25, $WS_GROUP)GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))GUISetState(@SW_SHOW)#EndRegion ### END Koda GUI section ###While 1  $nMsg = GUIGetMsg() Switch $nMsg    Case $GUI_EVENT_CLOSE   Exit    Case $Button1           Local $IconPos = ControlGetPos($Form2,"",$Icon1)    GUICtrlSetImage($Icon1, @SystemDir & "\shell32.dll", -12)           ControlMove($Form2,"",$Icon1,$IconPOs[0],$IconPos[1])   GUICtrlSetData($Label1, "Why the icon moved when Label stay in his original position ? ")   EndSwitchWEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks Martin for your tip, it work that way (but the move cause some flickering when many icons are present) !

Strangely, if I replace the function GUICtrlCreateIcon by GUICtrlCreatePic (and use some images files instead of pointing to an icon in a dll), all is working great ! the image stay in position even when the window has been maximized. The problem is that I can't use GUICtrlCreatePic because I need icons from a dll.

So, it seem's the problem is with GUICtrlCreateIcon witch doesn't get informed by the new window dimensions. Is this a bug or a feature ?

here the code with GUICtrlCreatePic, replace 1.gif and 2.gif with images in your path

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 353, 345, 346, 400, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS) )
$Button1 = GUICtrlCreateButton("update image", 48, 296, 75, 25, $WS_GROUP)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\1.gif", 296, 288, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            GUICtrlSetImage($Pic1, @ScriptDir & "\2.gif")
    EndSwitch
WEnd
Link to comment
Share on other sites

I think the problem is probably more to do with GuiCtrlSetImage than with GuiCtrlCreateIcon.

Try Yashied's icons udf, like this

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "G:\icons\icons.au3";<------------------set to correct path for you
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 413, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX,$WS_SIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("icon should stay in right corner", 10, 200, 380, 17, $WS_GROUP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Label2 = GUICtrlCreateLabel("1st maximize the window, then, click update", 10, 180, 250, 17)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Icon1 = GUICtrlCreateIcon(@SystemDir & "\shell32.dll", -14, 376, 264, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
$Button1 = GUICtrlCreateButton("Update icon", 32, 272, 100, 25, $WS_GROUP)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKBOTTOM, $GUI_DOCKSIZE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
            _SetIcon($Icon1, @SystemDir & "\shell32.dll", -12);<--------------works without repositioning
    GUICtrlSetData($Label1, "Why the icon moved when Label stay in his original position ? ")
    EndSwitch
WEnd
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Perhaps your right, it's more like a problem with GuiCtrlSetImage... Hopefully, it will be fixed in the future.

Still, I keep the solution you provided first, because I don't want to include about 600k of useless stuff just for 1 function, and I prefer not to use udf's when possible. Thanks anyway ;) !

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