Jump to content

Detect mouse click anywhere on window


Recommended Posts

Hello I have a custom gui I am making with no actual titlebar, I need to be able to allow users to move the window by clicking anywhere in the window and dragging. To do this I need to detect if they clicked anywhere in the window, and where.

Though I'm not 100% sure how I'm going to calculate where to move the window based on where they clicked.

Link to comment
Share on other sites

register the WM_NCHITTEST message like this:

GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

credits to guinness (i can't recall the original post though).

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

care to post your script (or an extract for replication)?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

please check your download link, when i follow it i'm redirected to:

http://w101531.blob3.ge.tt/streams/8SvM5KK1/Animatedgui.zip?sig=-URBRV4hLMvXZs5iqgrL3oxZLlb5Val0u-4&type=download

and i get blank screen and nothing happens.

that snippet i tested with a GUI completely covered by an image (.jpg file) and it works fine. download the attached image and save this script in the same folder:

(EDIT: it is working because i disabled the background image. disable yours.)

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>

$hGUI=GuiCreate("MyGUI",290,500,Default,Default,$WS_POPUP)
_GuiRoundCorners($hGUI, 0, 0, 40, 40)
GUICtrlCreatePic("background-w-icons(7.7x13.3).jpg", 0, 0, 290, 500)    ; crop : botton 153, right 631
GUICtrlSetState(-1,$GUI_DISABLE)

; button
$gHeadButtonDropdown=GUICtrlCreateLabel('',80,0,15,19,$SS_CENTER)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1,0)
GUICtrlSetTip(-1,'Menu')
$gHeadButtonPaddingTop=GUICtrlCreateLabel('',95,0,100,2,$SS_CENTER)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1,0)
$gHeadButtonLabel=GUICtrlCreateLabel('My App Title',95,2,100,17,$SS_CENTER)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1,0)
GUICtrlSetFont(-1,Default,800);,Default,'Tahoma')
$gHeadButtonMinimize=GUICtrlCreateLabel('',195,0,15,19,$SS_CENTER)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1,0)
GUICtrlSetTip(-1,'Minimize')

GuiSetState()
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

While True
    $msg=GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $gHeadButtonDropdown,$gHeadButtonLabel,$gHeadButtonPaddingTop
            MsgBox(0,'','Head Button pressed for Menu')
        Case $gHeadButtonMinimize
            MsgBox(0,'','Head Button pressed for Minimize')
    EndSwitch
WEnd

Exit

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
   Dim $pos, $ret, $ret2
   $pos = WinGetPos($h_win)
   $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3)
   If $ret[0] Then
      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
      If $ret2[0] Then
         Return 1
      Else
         Return 0
      EndIf
   Else
      Return 0
   EndIf
EndFunc  ;==>_GuiRoundCorners

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

post-47848-0-04212300-1392664312_thumb.j

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

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