Jump to content

Leaderboard

Popular Content

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

  1. Yes, it is working. But we should use : Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_UpdateLayeredWindowEx($hGUI, -1, -1, $hBitmap) to ensure no memory leak. Also, I just noticed a small bug. _WinAPI_DeleteObject($hImage) is incorrect and should be replaced by : _GDIPlus_ImageDispose($hImage) and then add : _WinAPI_DeleteObject($hBitmap) EDIT : modified code above accordingly.
    3 points
  2. Great investigations. Seems we can force the position of the button inside $WM_WINDOWPOSCHANGING message (by setting X, Y, CX and CY). I still haven't found the elegant way to set the right position at the right time, though. Got to go for now... Edit : this is what I got best so far... #include <guiConstants.au3> #include <winapi.au3> #include <MenuConstants.au3> Opt("MustDeclareVars", True) Global $hGUI, $bRestore Example() Func Example() $hGUI = GUICreate("WM_NCHITTEST", 300, 200, -1, -1, $WS_OVERLAPPEDWINDOW) Local $idBtn = GUICtrlCreateButton("Button 1", 4, 4, 80, 80, $WS_CLIPSIBLINGS) Local $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) GUIRegisterMsg($WM_SYSCOMMAND, WM_SYSCOMMAND) 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) Else _WinAPI_SetWindowSubclass(GUICtrlGetHandle($idBtn), DllCallbackGetPtr($hDll), $idBtn, 0) _WinAPI_SetWindowSubclass(GUICtrlGetHandle($idBtn2), DllCallbackGetPtr($hDll), $idBtn2, 0) EndIf Case $idBtn, $idBtn2 ConsoleWrite("Click " & GUICtrlRead($iMsg) & @CRLF) Case $GUI_EVENT_RESTORE $bRestore = False EndSwitch WEnd GUIDelete() _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idBtn), DllCallbackGetPtr($hDll), $idBtn) _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($idBtn2), DllCallbackGetPtr($hDll), $idBtn2) DllCallbackFree($hDll) EndFunc ;==>Example Func ButtonMoveProc($hWnd, $iMsg, $wParam, $lParam, $iID, $iData) Local $tPos, $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 Case $WM_WINDOWPOSCHANGING If $bRestore Then ConsoleWrite("WM_WINDOWPOSCHANGING" & @CRLF) $tPos = DllStructCreate($tagWINDOWPOS, $lParam) $aPos = ControlGetPos($hGUI, "", $hWnd) ConsoleWrite($aPos[0] & "/" & $aPos[1] & "/" & $aPos[2] & "/" & $aPos[3] & @CRLF) $tPos.X = $aPos[0] $tPos.Y = $aPos[1] $tPos.CX = $aPos[2] $tPos.CY = $aPos[3] Return 0 EndIf EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>ButtonMoveProc Func WM_SYSCOMMAND($hWnd, $uMsg, $wParam, $lParam) If $wParam = $SC_RESTORE Then ConsoleWrite("---Start Restore---" & @CRLF) $bRestore = True EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_SYSCOMMAND
    2 points
  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.
    2 points
  4. Ok so here's a test to see whats going on with GUICtrlSetPos. I tried inspecting whats being sent to the button - Bear with me... So run this > mouse over the control (it will jump) > then minimise > restore > esc (Exit). Next on line 58, uncomment _WinAPI_SetWindowPos & comment out GUICtrlSetPos I found the end result is near identical - except _WinAPI_SetWindowPos sends a WM_CHILDACTIVATE when moving the control (I doubt this matters) and WM_WINDOWPOSCHANGING has different coordinates after restoring. OK next uncomment 16 & 17, Comment out 19 & 20. Repeat the experiment. _WinAPI_SetWindowPos now works properly for minimize/restore (buttons now created with _GUICtrlButton_Create), and GUICtrlSetPos breaks totally. So I'm guessing Auitoit is keeping track of the controls that it creates, and is manually telling them where to go during the restore procedure. And I figure if we wanted to go deeper we could probably just wite our own restore func to test this... But I haven't got around to that just yet! Edit: Then again this seems inconsistent with what @Nine found with the external window - so maybe I'm still missing something....
    1 point
  5. 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
  6. @rot3r wanted this: ; Special thanks to GaryFrost for updating this to work with AutoIt v3.2.12.0! ; Special thanks to argumentum for updating this to work with AutoIt v3.3.?.? =) #NoTrayIcon #include <GDIPlus.au3> ; this is where the magic happens, people #include <GuiComboBox.au3> #include <File.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <WinAPISysWin.au3> #include <WinAPISys.au3> Opt("MustDeclareVars", 0) Global Const $AC_SRC_ALPHA = 1 Global Const $ULW_ALPHA = 2 Global $old_string = "", $runthis = "" Global $launchDir = @DesktopDir ; Load PNG file as GDI bitmap _GDIPlus_Startup() $pngSrc = @ScriptDir & "\LaunchySkin.png" $hImage = _GDIPlus_ImageLoadFromFile($pngSrc) ; Extract image width and height from PNG $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) ; Create layered window $GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) SetBitmap($GUI, $hImage, 0) ; Register notification messages GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() WinSetOnTop($GUI, "", 1) ;fade in png background For $i = 0 To 255 Step 10 SetBitmap($GUI, $hImage, $i) Next ; create child MDI gui window to hold controls ; this part could use some work - there is some flicker sometimes... $controlGui = GUICreate("ControlGUI", $width, $height, 0, _WinAPI_GetSystemMetrics($SM_CYCAPTION), $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI) ; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and ; I think the way this works is the transparent window color is based on the image you set here: GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height) GUICtrlSetState(-1, $GUI_DISABLE) ; just a text label GUICtrlCreateLabel("Type the name of a file on your desktop and press Enter", 50, 12, 140, 50) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0xFFFFFF) ; combo box listing all items on desktop $Combo = GUICtrlCreateCombo("", 210, 12, 250, -1) GUICtrlSetFont($Combo, 12) ; set default button for Enter key activation - renders outside GUI window $goButton = GUICtrlCreateButton("Go", $width, $height, 10, 10, $BS_DEFPUSHBUTTON) GUISetState() ; get list of files on desktop, show in combobox $aFileList = _FileListToArray($launchDir) _ArraySort($aFileList, 0, 1) $FileList = _ArrayToString($aFileList, "|", 1) GUICtrlSetData($Combo, $FileList) ;~ AdlibEnable("GoAutoComplete", 1000); combo autocomplete every message loop = often incorrect AdlibRegister("GoAutoComplete", 1000) ; combo autocomplete every message loop = often incorrect While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $goButton $runthis = GUICtrlRead($Combo) ExitLoop EndSelect WEnd ;~ AdlibDisable() AdlibUnRegister("GoAutoComplete") If $runthis <> "" Then If FileExists($launchDir & "\" & $runthis) Then Beep(1000, 50) Beep(2000, 50) _ShellExecute($runthis, "", $launchDir) EndIf EndIf GUIDelete($controlGui) ;fade out png background For $i = 255 To 0 Step -10 SetBitmap($GUI, $hImage, $i) Next ; Release resources _WinAPI_DeleteObject($hImage) _GDIPlus_Shutdown() Func GoAutoComplete() _GUICtrlComboBox_AutoComplete($Combo) EndFunc ;==>GoAutoComplete ; ==================================================================================================== ; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image. ; ==================================================================================================== Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndFunc ;==>WM_NCHITTEST ; ==================================================================================================== ; SetBitMap ; ==================================================================================================== Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetBitmap ; I don't like AutoIt's built in ShellExec. I'd rather do the DLL call myself. Func _ShellExecute($sCmd, $sArg = "", $sFolder = "", $rState = @SW_SHOWNORMAL) $aRet = DllCall("shell32.dll", "long", "ShellExecute", _ "hwnd", 0, _ "string", "", _ "string", $sCmd, _ "string", $sArg, _ "string", $sFolder, _ "int", $rState) If @error Then Return 0 $RetVal = $aRet[0] If $RetVal > 32 Then Return 1 Else Return 0 EndIf EndFunc ;==>_ShellExecute to make lod3n_launcher ( from 2008 ) run in 2024.
    1 point
  7. I think that speaks for itself : $iArray1 = 400000 $iArray2 = 2 _ArrayCreate1() ConsoleWrite("---------------" & @CRLF) _ArrayCreate2() ConsoleWrite("---------------" & @CRLF) Func _ArrayCreate1() Local $aArray[$iArray1][$iArray2] $hTimer = TimerInit() For $i = 0 To $iArray1 - 1 For $j = 0 To $iArray2 - 1 ; $aArray[$i][$j] = "0000000000" Next Next $hTimer = TimerDiff($hTimer) ConsoleWrite(($hTimer / 1000) & @CRLF) $hTimer = TimerInit() For $j = 0 To $iArray2 - 1 For $i = 0 To $iArray1 - 1 ; $aArray[$i][$j] = "0000000000" Next Next $hTimer = TimerDiff($hTimer) ConsoleWrite(($hTimer / 1000) & @CRLF) EndFunc ;==>_ArrayCreateH Func _ArrayCreate2() Local $aArray[$iArray2][$iArray1] $hTimer = TimerInit() For $i = 0 To $iArray2 - 1 For $j = 0 To $iArray1 - 1 ; $aArray[$i][j] = "0000000000" Next Next $hTimer = TimerDiff($hTimer) ConsoleWrite(($hTimer / 1000) & @CRLF) $hTimer = TimerInit() For $j = 0 To $iArray1 - 1 For $i = 0 To $iArray2 - 1 ; $aArray[$i][j] = "0000000000" Next Next $hTimer = TimerDiff($hTimer) ConsoleWrite(($hTimer / 1000) & @CRLF) EndFunc ;==>_ArrayCreateV Results : 0.65700933651172 0.0324245133094954 --------------- 0.0336796450801218 0.654968878294266 --------------- It is not the way the array is created, but the way the loop uses the array. As you can imagine, there is more calculations involved when the short loop is second. When the long loop is second there is less calculation and faster result.
    1 point
  8. lolipop #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGUI = GUICreate('') GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_WINDOWPOSCHANGING, 'WM_WINDOWPOSCHANGING') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>Example Func WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Local $aWinGetPos = WinGetPos($hWnd) If @error Or $aWinGetPos[0] < -30000 Then Return $GUI_RUNDEFMSG Local $tWindowPos = DllStructCreate($tagWINDOWPOS, $lParam) DllStructSetData($tWindowPos, 'X', $aWinGetPos[0]) DllStructSetData($tWindowPos, 'Y', $aWinGetPos[1]) Return $GUI_RUNDEFMSG EndFunc ;==>WM_WINDOWPOSCHANGING
    1 point
×
×
  • Create New...