Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How To] Enable Drag for a GUI without a Titlebar


  • Please log in to reply
4 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

In his reply to this post, Laszlo wrote:

"Goyyah, you could add a note to the original post, that a window w/o title bar can still be moved in the traditional way (with the arrow keys), by selecting Move from the Alt-Space activated context menu."

As Mr.Laszlo said: The simple way to move any window is to press ALT+Space (when the Window has the focus), and the System menu of the window will be displayed. Selecting Move will allow the user to move the window with Up/Down/Left/Right arrow keys.

In case, you want to keep a Hotkey handy in your "always-running-master-script" - The following one-liner would suffice:

<Your Hotkey>::PostMessage, 0x112, 0xF010,,, A


This quote was added on: 31-Jul-2006


How to enable Drag for a GUI without a Titlebar ?
http://www.autohotke...p?p=64185#64185

Foreword:

I am not sure whether the technique I am posting now has already been documented.

All I could find from forum search is the workaround Solution posted by Chris in
Ask for Help topic Movable "Borderless" SplashText or GUI- Feature

Credit: Adapted from VB example posted as Dragging a Form Without a Title Bar


How to?
[*:3bdjbzsf]Create a GUI without caption: Gui, -Caption.
[*:3bdjbzsf]Add a control (that is not input capable*) and assign a gLabel.
[*:3bdjbzsf]The gLabel routine should have the following line:

- PostMessage, 0xA1, 2,,, A Thats it .... Now a user can click on the defined control to drag the GUI as required. :D[/list]

Important Note: This postmessage requires that the Left Mouse Button is down when being posted!
We cannot do this with a push button ( and other buttons having on/off state) because the gLabel will never get executed until we release the mouse button. So it is ideal to associate the gLabel to a static control.



How it works?

When the Left Mouse Button is down on the Titlebar, WM_NCLBUTTONDOWN ( 0xA1 ) message gets posted and that enables the window to be dragged. We are simulating the exact condition by posting WM_NCLBUTTONDOWN to the GUI.

"Exact condition" means that the drag can be cancelled with <Esc> which relocates the GUI to its previous postion.


Here is a Copy / Paste / Try example - Enabling drag with a text control :
Gui, -Caption +ToolWindow +0x400000
Gui, Font, S14 Bold, Verdana
Gui, Add, Text, w200 h27 Border Center GuiMove, Click Here `&& Drag
Gui, Show, AutoSize
Return

uiMove:
PostMessage, 0xA1, 2,,, A 
Return

GuiEscape:
Exitapp

Result of above code - Snapshot:

Posted Image

The above is just a snapshot ...
DO NOT TRY TO DRAG IT - :wink: An another Copy / Paste / Try example - Enabling drag with a Picture control used as a Titlebar :
IfNotExist, bg.bmp
    URLDownloadToFile
    ,https://ahknet.autohotkey.com/~goyyah/Tips-N-Tricks/Gradients/Caption.bmp
    ,bg.bmp

Gui, -Caption +ToolWindow +0x400000
Gui, Margin, 0, 0
Gui, Add, Picture, w400 h16 Border Center GuiMove, bg.bmp
Gui, Add, Text, y+1 w402 h280 Border
Gui, Show, AutoSize
Return

uiMove:
PostMessage, 0xA1, 2,,, A 
Return

GuiEscape:
Exitapp

Result of above code - Snapshot:

Posted Image
Some ideas!

Advantages in removing the default Titlebar and enabling the drag with a control.

[*:3bdjbzsf]It gives the developer flexibility in declaring conditions on when the GUI can be moved or stay freezed in the current postion.
[*:3bdjbzsf]The GUI can equal the size of a Titlebar or may even be smaller. Full freedom in deciding the size of the GUI.
[*:3bdjbzsf]Enables a developer to Skin his application so that the GUI looks uniform in different Windows OSes.
[*:3bdjbzsf]With a simulated Titlebar it is easier to add other buttons (Its hard to mess with the regular titlebar).
Experiment 1: Posted Image

[*:3bdjbzsf]Download TinyClock.zip
[*:3bdjbzsf]The Clock can be dragged to a suitable position on the screen and be frozen there.
[*:3bdjbzsf]The Clock by default is Always on Top and can be set to be Always @ Bottom
[*:3bdjbzsf]GUI consists only a single button and it is g-labelled to show the Traymenu.
Experiment 2 : Posted Image

[*:3bdjbzsf]Download Media.zip
[*:3bdjbzsf]A "Titlebar sized" - "Drag-enabled" GUI that has a Traymenu Icon, Menu bar, Media buttons and System buttons all in one line!
[*:3bdjbzsf]Menu will always be shown on the top-left of the GUI occupying the WHOLE LINE!. The menu seen in the snapshot is actually a seperate GUI. The effect is made possible with a workaround involving two GUI's.
[*:3bdjbzsf]All pictures are icons bound into a single Library (ICL file).Experiment 3 : How to Simulate a GUI Titlebar ? (or) How to user define a GUI Caption ?

Snapshot of an experimental GUI Application with an user-defined caption bar.

Posted Image

[*:3bdjbzsf]Download AHK-SE.zip

[*:3bdjbzsf]The grey colored Titlebar is a vertical Linear Gradient simulated with a 2 pixel Bitmap.
See: How to Simulate a Linear Gradient ?

[*:3bdjbzsf]The carved-out effect of the Caption text is simulated by Superimposing two text controls.
See: How to Display Shadowed Text in a GUI ?

[*:3bdjbzsf]Most windows just display the Icon on the left side of the Titlebar. I have attached the Traymenu to it! That is how a Titlebar should be when AHK-ites develop a GUI. 8)

[*:3bdjbzsf]This GUI does not maximize. So, I have used that button to toggle "Always On Top" setting. I never had a requirement for resizeable GUIs. If your GUI requires maximizing, it will be cool to enable double-click-on-titlebar maximizing for your GUI. I have not tried this, but should be possible.

[*:3bdjbzsf]One might have a need for a Menu bar. See Experiment 2 for a possible workaround.

[*:3bdjbzsf]Well! I am not sure how many people have this habit, but I do!

My habit: When there is a situation of too many open windows and I am closing unwanted windows fastly! I first click on the Close button and without releasing the left mouse button I browse the window's contents. If the window has to be closed - I release the left mouse button... and if not - I move the cursor away from the Close button and the Close gets cancelled!

I have enabled the Titlebar buttons to mimic this functionality.[/list][/list]


Edit: Added 30-Jul-2006

How to simulate the activated/deactivated status for a simulated Titlebar?

A window`s Title bar/Caption (sort of) greys-out when it is Not Active and looks bright
when it is the Active window!.

The current utility I am developing requires a Always-On-Top GUI with a simulated Titlebar.
The gui looks pretty neat - however with one limitation. The user would never be able to guess
(by looking at the titlebar), whether the GUI is having focus or not

My immediate solution was to use a IfWinActive in Timer routine to change the color of the Caption text.
Then did some research and found an answer to this: How to Detect Activation/Deactivation of a GUI?

Here is a Copy / Paste / Try Example:

OnMessage(0x06 , "WM_ACTIVATE")

Gui -Caption +0x800000 +AlwaysOnTop +ToolWindow
Gui, Color, FFFFE7
Gui, Margin, 0,0
Gui, Font, s9 , Verdana
Gui, Add, Text, x0 y0 +0x4   w400 h19
Gui, Add, Text, x0 y0 +0x200 w400 h19 cFFFF80 Backgroundtrans vCaption guiMove
   , % A_Space " Simulated Titlebar"
Gui, Show, h300

Return

WM_ACTIVATE(wParam, lParam) {
 IfGreaterOrEqual,wParam,1, Gui,Font,cFFFF80
 IfLessOrEqual   ,wParam,0, Gui,Font,c808080
 GuiControl, Font, Caption
}

uiMove: 
  PostMessage, 0xA1, 2,,, A
Return

GuiEscape:
  ExitApp


kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Goyyah, you could add a note to the original post, that a window w/o title bar can still be moved in the traditional way (with the arrow keys), by selecting Move from the Alt-Space activated context menu.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Goyyah, you could add a note to the original post......

Done Sir! ... Here :D

Regards, :)

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Some really nice tips here, thanks Skan. :)

Re: How to enable Drag for a GUI without a Titlebar?, I thought I'd mention you can also use OnMessage to capture LButton anywhere in the gui. I used this method for a moveable "tooltip", like the download bar in uTorrent:

Gui, -Caption +Border +ToolWindow +AlwaysOnTop
Gui, Show, w200 h13
OnMessage( 0x200, "WM_MOUSEMOVE" ) 
return

WM_MOUSEMOVE( wparam, lparam, msg, hwnd )
{
	if wparam = 1 ; LButton
		PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Some really nice tips here, thanks Skan. :)


Thanks for the WM_MouseMove tip.
kWo4Lk1.png