Sign in to follow this  
Followers 0
dbzfanatic

[RESOLVED] Moving GUI without $WS_CAPTION not working?

13 posts in this topic

#1 ·  Posted (edited)

I have a GUI and it seems like it should work but it isn't. GUI isn't my specialty so could anyone help me? My code is:

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 512, 512, 193, 125, BitOR($WS_POPUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_LAYERED,$GUI_WS_EX_PARENTDRAG))
$Pic1 = GUICtrlCreatePic("moon transparent.gif", 0, 0, 512,512,0x0200)
GUICtrlSetState(-1,$GUI_DISABLE)
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 128, 288, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

    EndSwitch
WEnd

and I've attached the picture I'm using (yes I made the picture myself).

Edited by dbzfanatic

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Oh, thank you very much. I did mention GUI wasn't my strongest point and I suppose that was proven. Once again thank you ;).

Edit: Just moved it to the control, still can't move my GUI.

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 512, 512, 193, 125, BitOR($WS_POPUP,$WS_CLIPSIBLINGS), $WS_EX_LAYERED)
$Pic1 = GUICtrlCreatePic("moon transparent.gif", 0, 0, 512,512,0x0200, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetState(-1,$GUI_DISABLE)
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 128, 288, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

    EndSwitch
WEnd

Edit 2: I've also tried enabling the Pic by removing GUICtrlSetState but to no avail.

Edited by dbzfanatic

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh, thank you very much. I did mention GUI wasn't my strongest point and I suppose that was proven. Once again thank you ;).

Edit: Just moved it to the control, still can't move my GUI.

-snipped-

Edit 2: I've also tried enabling the Pic by removing GUICtrlSetState but to no avail.

According to the helpfile $GUI_WS_EX_PARENTDRAG should work with GUICtrlCreatePic() so I can't explain that, but you could try catching WM_NCHITTEST instead, it works. Example:

(note that i did some small edits and commented some other things I thought you maybe should think about in the future)

#include <GUIConstantsEx.au3>;GUIConstantsEx.au3 should be used on 3.2.12.0 and forward
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 512, 512, 193, 125, BitOR($WS_POPUP, $WS_CLIPSIBLINGS), $WS_EX_LAYERED)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "/moon_transparent.gif", 0, 0, 512, 512, $SS_CENTERIMAGE) ;why use the hex when you already included the variable?
GUICtrlSetState(-1,$GUI_DISABLE)
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25);the zero here doesn't make any sense at all
$Button2 = GUICtrlCreateButton("Button2", 128, 288, 65, 25);the zero here doesn't make any sense at all
GUISetState();@SW_SHOW is the default value so no need to write it down
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
#EndRegion ### END Koda GUI section ###

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

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $frmCustomGUI) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc
Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

$GUI_WS_EX_PARENTDRAG works fine for me with a GUICtrlCreatePic.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 464, 464, 193, 125, $WS_POPUP)
$hTitleBar = GUICtrlCreatePic("pic.jpg", 0, 0, 464, 26, -1, $GUI_WS_EX_PARENTDRAG)
$hTitleText = GUICtrlCreateLabel("This is a Window Test", 6, 6, 464)
GUICtrlSetBkColor($hTitleText, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor($hTitleText, 0xFFFFFF)
GUICtrlSetFont($hTitleText, 9)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

    EndSwitch
WEnd

And the Pic:

Posted Image

(I was messing with a colored Title bar)

Share this post


Link to post
Share on other sites

I tried both methods and nothing worked. I tried AdmiralAlkex's code and it didn't even show the image. I tried setting the normal options in my original code to -1 and the image showed but still I couldn't move the window. I'm running under Vista so could that be the problem? Also as a bit of an exposition I included the hex and not the variable because I added the includes after I wrote the code since I wansn't aware I needed anything other than GUIConstants.au3.

Share this post


Link to post
Share on other sites

I tried both methods and nothing worked. I tried AdmiralAlkex's code and it didn't even show the image. I tried setting the normal options in my original code to -1 and the image showed but still I couldn't move the window. I'm running under Vista so could that be the problem? Also as a bit of an exposition I included the hex and not the variable because I added the includes after I wrote the code since I wansn't aware I needed anything other than GUIConstants.au3.

If you convert your image to bmp then this works

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 512, 512, 193, 125, $WS_POPUP, $WS_EX_LAYERED)
$Pic1 = GUICtrlCreatePic("moon transparent.bmp", 0,0, 512,512,-1,$GUI_WS_EX_PARENTDRAG); -1 or $SS_NOTIFY but not 0x0200
;GUICtrlSetState(-1,$GUI_DISABLE);don't disable the pic
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 128, 288, 65, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I tried saving as a bmp but when I do the transparency doesn't display properly nor does the overall image. Since I created the image I'm saving directly and not converting so it's not a converter issue. I've also tried .png and .jpg and they don't work either. The only reason I disabled the image was to test if that was the problem,which it isn't, and I've already stated I've tried with and without disabling the picture.

Edit: Nevermind I got it working, not sure what I did...but now when I move it the background shows through but is repainted every time so you can see the edges in manner of speaking. Is this a bug or just the delay between paints?

Edit 2: Also just remembered that the helpfile recommends disabling a "background" image since other controls will be on top. If I disable the image I can't move my window, if I enable the image I can't use my buttons. Ideas?

Edited by dbzfanatic

Share this post


Link to post
Share on other sites

I tried saving as a bmp but when I do the transparency doesn't display properly nor does the overall image. Since I created the image I'm saving directly and not converting so it's not a converter issue. I've also tried .png and .jpg and they don't work either. The only reason I disabled the image was to test if that was the problem,which it isn't, and I've already stated I've tried with and without disabling the picture.

If you run the script I posted and use this image

then it should work for you the same as it works for me I hope.


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.

Share this post


Link to post
Share on other sites

Please read my two edits. I completely removed the disabling line and added $WS_CLIPSIBLINGS the to image creation and now my controls work but I still am unable to move my GUI. Here's my new code:

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 512, 512, 193, 125, $WS_POPUP, $WS_EX_LAYERED)
$Pic1 = GUICtrlCreatePic("moon transparent.gif", 0, 0, 512,512, BitOR($SS_CENTERIMAGE,$WS_CLIPSIBLINGS), $GUI_WS_EX_PARENTDRAG)
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25, 0)
$Button2 = GUICtrlCreateButton("X", 128, 288, 15, 15, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

Share this post


Link to post
Share on other sites

Please read my two edits. I completely removed the disabling line and added $WS_CLIPSIBLINGS the to image creation and now my controls work but I still am unable to move my GUI. Here's my new code:

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 512, 512, 193, 125, $WS_POPUP, $WS_EX_LAYERED)
$Pic1 = GUICtrlCreatePic("moon transparent.gif", 0, 0, 512,512, BitOR($SS_CENTERIMAGE,$WS_CLIPSIBLINGS), $GUI_WS_EX_PARENTDRAG)
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25, 0)
$Button2 = GUICtrlCreateButton("X", 128, 288, 15, 15, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit
    EndSwitch
WEnd
I had made a note in my post about the style to set for the pic which you haven't followed.

There are a few ways to do what you want. If you want the buttons to work then you must disable the pic and don't use the parent drag style. Then you could detect the primary mouse button down, use GuiGetCursorInfo to see if it's on the pic then move the gui accordingly.

Or search for NC_HITTEST as a way to drag a gui.


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.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Just because I didn't post the suggestions in my code does not mean I didn't try them. In fact I did and they didn't work either. I've already tried AdmiralAlkex's method about using the hittest method, which if you read, didn't work. I'm trying to use a picture over a picture to get the effect I want, which may work,it may not, I'm not sure as of yet.

Edit: It works. Here's the code:

#include <GUIConstants.au3>
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmCustomGUI = GUICreate("Custom GUI", 382, 382, 193, 125, $WS_POPUP, $WS_EX_LAYERED)
$Pic1 = GUICtrlCreatePic("moon transparent.bmp", 0, 0, 382,382, -1, $GUI_WS_EX_PARENTDRAG)
$Overlay = GUICtrlCreatePic("",0,0,382,382,-1)
GUICtrlSetState(-1,$GUI_DISABLE)
$Button1 = GUICtrlCreateButton("Button1", 32, 288, 57, 25, -1)
GUICtrlSetState(-1,$GUI_ONTOP)
$Button2 = GUICtrlCreateButton("X", 365, 0, 15, 15, -1)
GUICtrlSetState(-1,$GUI_ONTOP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            Exit
    EndSwitch
WEnd
Edited by dbzfanatic

Share this post


Link to post
Share on other sites

Just because I didn't post the suggestions in my code does not mean I didn't try them. In fact I did and they didn't work either. I've already tried AdmiralAlkex's method about using the hittest method, which if you read, didn't work. I'm trying to use a picture over a picture to get the effect I want, which may work,it may not, I'm not sure as of yet.

Ok, I'll sod off then.

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.

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
Sign in to follow this  
Followers 0