Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/19/2024 in all areas

  1. There is definitely room for improvement (exploring the scrolling) and that's why I said it as an idea. The idea where you can use one of this type (auto-hide) where no extra space is needed (as its purpose is only to call a command) #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> Global $g_bAutoHide = True Global $idBtnAutoHide Global $g_hTriggerGUI, $g_hRibonGUI ;~ $g_hTriggerGUI = TriggerGUI() $g_hTriggerGUI = TriggerGUI(0xF0F0F0, 15, 100, 250) $g_hRibonGUI = RibonGUI() ;********************************** While Sleep(50) TriggerCheck() WEnd ;********************************** ;---------------------------------------------------------------------------------------- Func GoToExit() ; exit Exit EndFunc ;==>GoToExit ;---------------------------------------------------------------------------------------- Func TriggerGUI($BkColor = 0xF0F0F0, $Width = 12, $Height = 50, $Trans = 50) Local $hWnd = GUICreate("TriggerGUI", $Width, $Height, -7, (@DesktopHeight - $Height) * 0.4, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor($BkColor) WinSetTrans($hWnd, "", $Trans) GUICtrlCreateLabel("", 0, 0, $Width, $Height) WinSetState($hWnd, "", @SW_SHOW) Return $hWnd EndFunc ;==>TriggerGUI ;---------------------------------------------------------------------------------------- Func TriggerCheck() ;if mouse over Trigger Local $aTrigger = GUIGetCursorInfo($g_hTriggerGUI) If $aTrigger[4] Then ;Make the RibonGUI Local $WinPos = WinGetPos($g_hRibonGUI) Local $BakPos = $WinPos WinMove($g_hRibonGUI, "", $WinPos[0], $WinPos[1], $WinPos[2], $WinPos[3]) GUISetState(@SW_SHOW, $g_hRibonGUI) ;Show the RibonGUI For $i = 1 To $WinPos[2] Step 5 WinMove($g_hRibonGUI, "", $WinPos[0], $WinPos[1], $i, $WinPos[3]) Next Local $aRibon ;********************************** While 1 $aRibon = GUIGetCursorInfo($g_hRibonGUI) If $aRibon[4] = 0 And $g_bAutoHide = True Then ExitLoop Sleep(100) WEnd ;********************************** ;Hide the RibonGUI For $i = $WinPos[2] To 1 Step -5 WinMove($g_hRibonGUI, "", $WinPos[0], $WinPos[1], $i, $WinPos[3]) Next GUISetState(@SW_HIDE, $g_hRibonGUI) WinMove($g_hRibonGUI, "", $BakPos[0], $BakPos[1], $BakPos[2], $BakPos[3]) EndIf EndFunc ;==>TriggerCheck ;---------------------------------------------------------------------------------------- Func RibonGUI() ; Ribon make Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled GUISetOnEvent($GUI_EVENT_CLOSE, "GoToExit") ConsoleWrite("@DesktopWidth=" & @DesktopWidth & @CRLF) ConsoleWrite("@DesktopHeight=" & @DesktopHeight & @CRLF) ConsoleWrite("@OSVersion=" & @OSVersion & @CRLF) ConsoleWrite("@AutoItX64=" & @AutoItX64 & @CRLF) Local $Width = 320 Local $Height = @DesktopHeight - 40 ; $DTs[1] Local $hWnd = GUICreate("RibonGUI", $Width, $Height, -7, -1, $WS_POPUPWINDOW, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ; $idLblHead = GUICtrlCreateLabel("", 0, 0, $Width, 32) ; GUICtrlSetBkColor(-1, 0x004A7F) Local $iStep = 2 $idBtnAutoHide = GUICtrlCreateButton("◀", $Width - 30, $iStep, 28, 28) GUICtrlSetFont(-1, 14) GUICtrlSetTip(-1, "Auto Hide ") GUICtrlSetOnEvent(-1, "Ribon_BtnAutoHide") $iStep += 50 GUICtrlCreateLabel("$idInput1", 10, $iStep, 300, 15) $iStep += 15 $idInput1 = GUICtrlCreateInput("Tex1", 10, $iStep, 305, 22) GUICtrlSetFont(-1, 12, 400, 0, "DejaVuSansMono") $iStep += 40 GUICtrlCreateLabel("$idInput2", 10, $iStep, 300, 15) $iStep += 15 $idInput2 = GUICtrlCreateInput("Tex2", 10, $iStep, 305, 22) GUICtrlSetFont(-1, 12, 400, 0, "DejaVuSansMono") $iStep += 40 GUICtrlCreateLabel("$idInput3", 10, $iStep, 300, 15) $iStep += 15 $idInput3 = GUICtrlCreateInput("Tex3", 10, $iStep, 305, 22) GUICtrlSetFont(-1, 12, 400, 0, "DejaVuSansMono") $iStep += 40 GUICtrlCreateLabel("$idInput4", 10, $iStep, 300, 15) $iStep += 15 $idInput4 = GUICtrlCreateInput("Tex4", 10, $iStep, 305, 22) GUICtrlSetFont(-1, 12, 400, 0, "DejaVuSansMono") GUICtrlCreateLabel("", 0, 0, $Width, $Height, $SS_GRAYFRAME) Return $hWnd EndFunc ;==>RibonGUI ;---------------------------------------------------------------------------------------- Func Ribon_BtnAutoHide() If $g_bAutoHide = True Then $g_bAutoHide = False GUICtrlSetData($idBtnAutoHide, "⏸️") Else $g_bAutoHide = True GUICtrlSetData($idBtnAutoHide, "◀️") EndIf EndFunc ;==>Ribon_BtnAutoHide ;----------------------------------------------------------------------------------------
    2 points
  2. Hi all, I've just been playing with window messages that are sent to win32 controls themselves (rather than to the parent GUI), and it looks like you can do some cool stuff. So I thought I'd share some things that I found interesting. And yeah I know the code probably needs a cleanup - but I figure its good enough to get the point across... Anyway what I have is: while the "lock" checkbox is selected, the buttons behave normally. Otherwise you can drag them around and/or resize them. Because you're essentially dragging the buttons by their "Caption" bar, double clicking will also maximise them. #include <guiConstants.au3> #include <winapi.au3> Global Const $DLGC_BUTTON = 0x2000 Global Const $DLGC_WANTTAB = 0x0002 Global $hGui = GUICreate("", 300, 200) Global $idBtn = GUICtrlCreateButton("Button 1", 4, 4, 80, 80) Global $idBtn2 = GUICtrlCreateButton("Button 2", 90, 4, 80, 80) Global $idLockButtons = GUICtrlCreateCheckbox("Lock Buttons", 200, 20, 80, 20) Global $hCursor = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, $OCR_CROSS)) Global $hBtnMoveProc = DllCallbackRegister("ButtonMoveProc", "long", "hwnd;uint;wparam;lparam") Global $pBtnMoveProc = DllCallbackGetPtr($hBtnMoveProc) Global $hBtn = GUICtrlGetHandle($idBtn) Global $hBtn2 = GUICtrlGetHandle($idBtn2) Global $pOrigBtnProc = _WinAPI_SetWindowLong($hBtn, $GWL_WNDPROC, $pBtnMoveProc) _WinAPI_SetWindowLong($hBtn2, $GWL_WNDPROC, $pBtnMoveProc) GUISetState() While 1 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $idLockButtons _WinAPI_SetWindowLong($hBtn, $GWL_WNDPROC, (GUICtrlRead($iMsg) = $GUI_CHECKED) ? $pOrigBtnProc : $pBtnMoveProc) _WinAPI_SetWindowLong($hBtn2, $GWL_WNDPROC, (GUICtrlRead($iMsg) = $GUI_CHECKED) ? $pOrigBtnProc : $pBtnMoveProc) Case $idBtn, $idBtn2 ConsoleWrite("Click " & GUICtrlRead($iMsg) & @CRLF) EndSwitch WEnd Func ButtonMoveProc($hWnd, $uMsg, $wParam, $lParam) Local $aPos, $iRet, $aPoint[2], $iSrc, $iEvent Local $aRes = DllCallAddress("long", $pOrigBtnProc, "hwnd", $hWnd, "uint", $uMsg, "wparam", $wParam, "lparam", $lParam) Switch $uMsg Case $WM_NCHITTEST $aPos = WinGetPos($hWnd) $aPoint[0] = BitAND($lParam, 0xFFFF) $aPoint[1] = BitShift($lParam, 16) $iRet = $HTCAPTION If $aPoint[0] - $aPos[0] < 10 Then $iRet = $HTLEFT If $aPoint[0] - $aPos[0] > ($aPos[2] - 10) Then $iRet = $HTRIGHT If $aPoint[1] - $aPos[1] < 10 Then Switch $iRet Case $HTLEFT $iRet = $HTTOPLEFT Case $HTRIGHT $iRet = $HTTOPRIGHT Case Else $iRet = $HTTOP EndSwitch ElseIf $aPoint[1] - $aPos[1] > ($aPos[3] - 10) Then Switch $iRet Case $HTLEFT $iRet = $HTBOTTOMLEFT Case $HTRIGHT $iRet = $HTBOTTOMRIGHT Case Else $iRet = $HTBOTTOM EndSwitch EndIf Return $iRet Case $WM_SETCURSOR $iSrc = BitAND($lParam, 0xFFFF) $iEvent = BitShift($lParam, 16) If $iSrc = $HTCAPTION And $iEvent = $WM_LBUTTONDOWN Then _WinAPI_SetCursor($hCursor) Return True EndIf Case Else EndSwitch Return $aRes[0] ;~ Return _WinAPI_DefWindowProcW($hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>ButtonProc
    1 point
  3. @Nine does this work for you ? ; SetBitmap($hGUI, $hImage, 255) _WinAPI_UpdateLayeredWindowEx($hGUI, -1, -1, _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)) If it works, then we shouldn't need Function SetBitmap() and its 18 lines.
    1 point
  4. Here modern coding (removed useless code) : #include <WinAPISysWin.au3> #include <WinAPIConstants.au3> #include <GDIPlus.au3> #include <GuiComboBox.au3> #include <File.au3> #include <WindowsConstants.au3> #include <GuiConstants.au3> #include <ButtonConstants.au3> Opt("MustDeclareVars", True) Global Const $AC_SRC_ALPHA = 1 Example() Func Example() ; Load PNG file as GDI bitmap _GDIPlus_Startup() Local $sPngSrc = @ScriptDir & "\LaunchySkin.png" Local $hImage = _GDIPlus_ImageLoadFromFile($sPngSrc) ; Extract image width and height from PNG Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) ; Create layered window Local $hGUI = GUICreate("", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_UpdateLayeredWindowEx($hGUI, -1, -1, $hBitmap) ; Register notification messages GUIRegisterMsg($WM_NCHITTEST, WM_NCHITTEST) GUISetState() WinSetOnTop($hGUI, "", $WINDOWS_ONTOP) ; As per help file : ; When using $WS_EX_MDICHILD the position is relative to client area of the parent window. ; With $WS_EX_LAYERED it is possible to have a transparent picture on a background picture defined in the parent window. ; To have a transparent picture, create the GUI with the WS_EX_LAYERED extended style. ; The left-top pixel will be used as the transparency color. ; If several pictures are created the last picture defines the transparent color. GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI) GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $iWidth, $iHeight) ; makes the whole child GUI transparent GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel("Type the name of a file on" & @CR & "your desktop and press Enter", 50, 30, 140, 60) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) ; combo box listing all items on desktop Local $idCombo = GUICtrlCreateCombo("", 210, 30, 250, -1, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetFont($idCombo, 10) ; set default button for Enter key activation - renders outside GUI window Local $idButton = GUICtrlCreateButton("", 0, 0, 0, 0, $BS_DEFPUSHBUTTON) GUISetState() ; get list of files on desktop, show in combobox Local $aFileList = _FileListToArray(@DesktopDir), $sRun _ArraySort($aFileList, 0, 1) GUICtrlSetData($idCombo, _ArrayToString($aFileList, "|", 1)) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton $sRun = GUICtrlRead($idCombo) ExitLoop EndSwitch WEnd If $sRun And FileExists(@DesktopDir & "\" & $sRun) Then Beep(2000, 50) ShellExecute($sRun, "", @DesktopDir) EndIf _WinAPI_DeleteObject($hBitmap) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndFunc ;==>Example Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) Return $HTCAPTION EndFunc ;==>WM_NCHITTEST
    1 point
  5. ..where's the zip ? Here: lod3n_launcher.zip . Do add the edit from the above post.
    1 point
  6. I tried the traditional method of applying resize ... but it overflowed a little #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> Example() Func Example() Local $hGui = GUICreate("", 300, 200, -1, -1, $WS_OVERLAPPEDWINDOW) Local $idBtn1 = GUICtrlCreateButton("Button 1", 10, 40, 80, 80, $WS_CLIPSIBLINGS) Local $idBtn2 = GUICtrlCreateButton("Button 2", 100, 40, 80, 80, $WS_CLIPSIBLINGS) Local $idInput = GUICtrlCreateInput("Test 123 Text", 10, 10, 170, 20, BitOR($ES_CENTER, $WS_CLIPSIBLINGS)) Local $idLockButtons = GUICtrlCreateCheckbox("Lock Buttons", 200, 20, 80, 20, $WS_CLIPSIBLINGS) Local $bLock = False GUISetState() Local $iMsg, $aInfo While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $idLockButtons $bLock = (GUICtrlRead($iMsg) = $GUI_CHECKED) ConsoleWrite("- Lock Buttons is " & _ (GUICtrlRead($iMsg) = 1 ? "Checked" : "Un-Checked") & @CRLF) Case $idBtn1 If Not $bLock Then ContinueLoop ConsoleWrite("- Button 1 is pressed" & @CRLF) Case $idBtn2 If Not $bLock Then ContinueLoop ConsoleWrite("- Button 2 is pressed" & @CRLF) Case $GUI_EVENT_PRIMARYDOWN If $bLock Then ContinueLoop $aInfo = GUIGetCursorInfo($hGui) If (Not @error) And ($aInfo[4] = $idBtn1 Or $aInfo[4] = $idBtn2 Or $aInfo[4] = $idInput) Then _Resize($hGui) EndIf EndSwitch WEnd EndFunc ;==>Example Func _Resize($hWnd, $iGrid = 5) If Not WinActive($hWnd) Then Return Local $aInfo = GUIGetCursorInfo($hWnd) Local $idControl = $aInfo[4] If $idControl = 0 Then Return If $iGrid < 1 Then $iGrid = 1 Local $iEdge = 5 Local $CtrlPos = ControlGetPos($hWnd, "", $idControl) Local $CtrlX = $CtrlPos[0] Local $CtrlY = $CtrlPos[1] Local $CtrlW = $CtrlPos[2] Local $CtrlH = $CtrlPos[3] Local $MouseX = $aInfo[0] Local $MouseY = $aInfo[1] Local $LeftEdge = Abs($MouseX - $CtrlX) < $iEdge Local $RightEdge = Abs($MouseX - ($CtrlX + $CtrlW)) < $iEdge Local $TopEdge = Abs($MouseY - $CtrlY) < $iEdge Local $BottomEdge = Abs($MouseY - ($CtrlY + $CtrlH)) < $iEdge _WinAPI_SetWindowPos(GUICtrlGetHandle($idControl), $HWND_TOP, 0, 0, 0, 0, $SWP_NOMOVE + $SWP_NOSIZE) Local $iCursorId = MouseGetCursor() Local $aInfoNew = $aInfo If $LeftEdge Or $RightEdge Or $TopEdge Or $BottomEdge Then ; ## Resizing ## Local $resizeMode = 0 If $LeftEdge Then $resizeMode += 1 If $RightEdge Then $resizeMode += 2 If $TopEdge Then $resizeMode += 4 If $BottomEdge Then $resizeMode += 8 ; Set cursor for resizing Switch $resizeMode Case 1, 2 ; Left, Right edge GUISetCursor(13, 1, $hWnd) Case 4, 8 ; Top, Bottom edge GUISetCursor(11, 1, $hWnd) Case 5, 10 ; Top-left, Bottom-right corner GUISetCursor(12, 1, $hWnd) Case 6, 9 ; Top-right, Bottom-left corner GUISetCursor(10, 1, $hWnd) EndSwitch Do $aInfo = GUIGetCursorInfo($hWnd) If $aInfoNew[0] <> $aInfo[0] Or $aInfoNew[1] <> $aInfo[1] Then $MouseX = $aInfo[0] $MouseY = $aInfo[1] Switch $resizeMode Case 1 ; Left edge $CtrlW += $CtrlX - $MouseX $CtrlX = $MouseX Case 2 ; Right edge $CtrlW = $MouseX - $CtrlX Case 4 ; Top edge $CtrlH += $CtrlY - $MouseY $CtrlY = $MouseY Case 8 ; Bottom edge $CtrlH = $MouseY - $CtrlY Case 5 ; Top-left corner $CtrlW += $CtrlX - $MouseX $CtrlX = $MouseX $CtrlH += $CtrlY - $MouseY $CtrlY = $MouseY Case 6 ; Top-right corner $CtrlW = $MouseX - $CtrlX $CtrlH += $CtrlY - $MouseY $CtrlY = $MouseY Case 9 ; Bottom-left corner $CtrlW += $CtrlX - $MouseX $CtrlX = $MouseX $CtrlH = $MouseY - $CtrlY Case 10 ; Bottom-right corner $CtrlW = $MouseX - $CtrlX $CtrlH = $MouseY - $CtrlY EndSwitch ; Snap to grid $CtrlX = Round($CtrlX / $iGrid) * $iGrid $CtrlY = Round($CtrlY / $iGrid) * $iGrid $CtrlW = Round($CtrlW / $iGrid) * $iGrid $CtrlH = Round($CtrlH / $iGrid) * $iGrid ; minimum size If $CtrlW < 15 Then $CtrlW = 15 If $CtrlH < 15 Then $CtrlH = 15 GUICtrlSetPos($idControl, $CtrlX, $CtrlY, $CtrlW, $CtrlH) EndIf Sleep(10) Until Not $aInfo[2] ElseIf $MouseX > $CtrlX + $iEdge And $MouseX < ($CtrlX + $CtrlW - $iEdge) And _ $MouseY > $CtrlY + $iEdge And $MouseY < ($CtrlY + $CtrlH - $iEdge) Then ; ## Moving ## GUISetCursor(0, 1, $hWnd) Local $OffsetX = $MouseX - $CtrlX Local $OffsetY = $MouseY - $CtrlY Do $aInfo = GUIGetCursorInfo($hWnd) If $aInfoNew[0] <> $aInfo[0] Or $aInfoNew[1] <> $aInfo[1] Then Local $NewX = Round(($aInfo[0] - $OffsetX) / $iGrid) * $iGrid Local $NewY = Round(($aInfo[1] - $OffsetY) / $iGrid) * $iGrid GUICtrlSetPos($idControl, $NewX, $NewY, $CtrlW, $CtrlH) EndIf Sleep(10) Until Not $aInfo[2] EndIf GUISetCursor($iCursorId, 0, $hWnd) EndFunc ;==>_Resize ... and since I did it, I want to share it Edit: I entered the grid parameter.
    1 point
  7. Success! Admittedly I wasn't looking to use a hidden gui window but would save me some desktop space. Thanks.
    1 point
  8. Take a look for an idea. 209312-side-scrollribon
    1 point
  9. @MattyD Sorry if we've been hijacking your thread, but in a sense it is all your fault. Making such an innovative example will certainly attract some members of the community, right ? Anyway, here my take to solve the minimize issue : #include <guiConstants.au3> #include <winapi.au3> Opt("MustDeclareVars", True) Global Const $tagMOUSEHOOKSTRUCT = "dword X;dword Y;hwnd hwnd;uint wHitTestCode;ulong_ptr dwExtraInfo;" Global $hGUI, $idBtn, $idBtn2, $hHook Example() Func Example() $hGUI = GUICreate("WM_NCHITTEST", 300, 200, -1, -1, $WS_OVERLAPPEDWINDOW) $idBtn = GUICtrlCreateButton("Button 1", 4, 4, 80, 80, $WS_CLIPSIBLINGS) $idBtn2 = GUICtrlCreateButton("Button 2", 90, 4, 80, 80, $WS_CLIPSIBLINGS) Local $idLockButtons = GUICtrlCreateCheckbox("Lock Buttons", 200, 20, 80, 20) Local $hDll = DllCallbackRegister(ButtonMoveProc, 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr') _WinAPI_SetWindowSubclass(GUICtrlGetHandle($idBtn), DllCallbackGetPtr($hDll), $idBtn) _WinAPI_SetWindowSubclass(GUICtrlGetHandle($idBtn2), DllCallbackGetPtr($hDll), $idBtn2) Local $hStub = DllCallbackRegister(WM_MOUSE, "LRESULT", "int;wparam;lparam") $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE, DllCallbackGetPtr($hStub), 0, _WinAPI_GetCurrentThreadId()) GUISetState() Local $iMsg While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idLockButtons If GUICtrlRead($iMsg) = $GUI_CHECKED Then _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idBtn), DllCallbackGetPtr($hDll), $idBtn) _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idBtn2), DllCallbackGetPtr($hDll), $idBtn2) _WinAPI_UnhookWindowsHookEx($hHook) Else _WinAPI_SetWindowSubclass(GUICtrlGetHandle($idBtn), DllCallbackGetPtr($hDll), $idBtn, 0) _WinAPI_SetWindowSubclass(GUICtrlGetHandle($idBtn2), DllCallbackGetPtr($hDll), $idBtn2, 0) $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE, DllCallbackGetPtr($hStub), 0, _WinAPI_GetCurrentThreadId()) EndIf Case $idBtn, $idBtn2 ConsoleWrite("Click " & GUICtrlRead($iMsg) & @CRLF) EndSwitch WEnd GUIDelete() _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idBtn), DllCallbackGetPtr($hDll), $idBtn) _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idBtn2), DllCallbackGetPtr($hDll), $idBtn2) DllCallbackFree($hDll) _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub) EndFunc ;==>Example Func ButtonMoveProc($hWnd, $iMsg, $wParam, $lParam, $iID, $iData) Local $aPos, $iRet, $aPoint[2], $iSrc, $iEvent, $hCursor Switch $iMsg Case $WM_NCHITTEST $aPos = WinGetPos($hWnd) $aPoint[0] = BitAND($lParam, 0xFFFF) $aPoint[1] = BitShift($lParam, 16) $iRet = $HTCAPTION If $aPoint[0] - $aPos[0] < 10 Then $iRet = $HTLEFT If $aPoint[0] - $aPos[0] > ($aPos[2] - 10) Then $iRet = $HTRIGHT If $aPoint[1] - $aPos[1] < 10 Then Switch $iRet Case $HTLEFT $iRet = $HTTOPLEFT Case $HTRIGHT $iRet = $HTTOPRIGHT Case Else $iRet = $HTTOP EndSwitch ElseIf $aPoint[1] - $aPos[1] > ($aPos[3] - 10) Then Switch $iRet Case $HTLEFT $iRet = $HTBOTTOMLEFT Case $HTRIGHT $iRet = $HTBOTTOMRIGHT Case Else $iRet = $HTBOTTOM EndSwitch EndIf Return $iRet Case $WM_SETCURSOR $iSrc = BitAND($lParam, 0xFFFF) $iEvent = BitShift($lParam, 16) If $iSrc = $HTCAPTION And $iEvent = $WM_LBUTTONDOWN Then _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_INVALIDATE + $RDW_FRAME) $hCursor = _WinAPI_LoadCursor(0, $OCR_SIZEALL) _WinAPI_SetCursor($hCursor) Return True EndIf EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>ButtonMoveProc Func WM_MOUSE($iMsg, $wParam, $lParam) If $iMsg < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iMsg, $wParam, $lParam) If $wParam = $WM_LBUTTONUP Then Local $tMouse = DllStructCreate($tagMOUSEHOOKSTRUCT, $lParam) If $tMouse.hwnd = GUICtrlGetHandle($idBtn) Or $tMouse.hwnd = GUICtrlGetHandle($idBtn2) Then Local $idCtrl = _WinAPI_GetDlgCtrlID($tMouse.hwnd) Local $aPos = ControlGetPos($hGUI, "", $idCtrl) GUICtrlSetPos($idCtrl, $aPos[0], $aPos[1]) EndIf EndIf Return _WinAPI_CallNextHookEx($hHook, $iMsg, $wParam, $lParam) EndFunc ;==>WM_MOUSE ps. I converted it to subclassing
    1 point
  10. Hope this script will work for you as it works for me, no callback, no subclassing, no redraw, no nothing Both buttons seem to be draggable fluently, fingers crossed. #include <GUIConstantsEx.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Global $g_hGui Example() ;============================================== Func Example() Local $idBtn, $idBtn2, $aInfo $g_hGui = GUICreate("Drag Buttons", 300, 200, -1, -1, $WS_OVERLAPPEDWINDOW) $idBtn = GUICtrlCreateButton("Button 1", 4, 4, 80, 80, $WS_CLIPSIBLINGS) $idBtn2 = GUICtrlCreateButton("Button 2", 90, 4, 80, 80, $WS_CLIPSIBLINGS) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $aInfo = GUIGetCursorInfo($g_hGui) If (Not @error) And ($aInfo[4] = $idBtn Or $aInfo[4] = $idBtn2) Then _WinAPI_SetWindowPos(GUICtrlGetHandle($aInfo[4]), $HWND_TOP , 0, 0, 0, 0, $SWP_NOMOVE + $SWP_NOSIZE) _ControlMove() EndIf EndSwitch WEnd EndFunc ;==>Example ;============================================== Func _ControlMove() Local $aInfo, $idControl, $hControl, $aPos, $iSubtractX, $iSubtractY $aInfo = GUIGetCursorInfo($g_hGui) $idControl = $aInfo[4] ; +++ $hControl = GUICtrlGetHandle($idControl) $aPos = ControlGetPos($g_hGui, "", $idControl) $iSubtractX = $aInfo[0] - $aPos[0] $iSubtractY = $aInfo[1] - $aPos[1] Do $aInfo = GUIGetCursorInfo($g_hGui) ; ConsoleWrite($aInfo[4] & @crlf) ; varies from 3 => 4 => 3 => 4 ... while dragging ; https://www.autoitscript.com/forum/topic/211959-drag-and-drop-items-labels-vertically-among-themselves/?do=findComment&comment=1534654 ; ControlMove($g_hGui, "", $idControl, $aInfo[0] - $iSubtractX, $aInfo[1] - $iSubtractY) ; issue on Minimize GUICtrlSetPos($idControl, $aInfo[0] - $iSubtractX, $aInfo[1] - $iSubtractY) _WinAPI_SetWindowPos($hControl, $HWND_TOP, 0, 0, 0, 0, $SWP_NOMOVE + $SWP_NOSIZE) Sleep(10) Until Not $aInfo[2] EndFunc ;==>_ControlMove
    1 point
×
×
  • Create New...