Jump to content
Sign in to follow this  
nullschritt

Detect mouse click anywhere on window

Recommended Posts

nullschritt

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.

Share this post


Link to post
Share on other sites
nullschritt

This doesn't work..... with my script. The message is never sent because an animated control covers the whole window. I need to know how to do it via wm_notify.

Thanks though.

Share this post


Link to post
Share on other sites
orbs

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

Share this post


Link to post
Share on other sites
orbs

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.