Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/29/2015 in all areas

  1. Two tiny, simple scripts (secondDesktop & desktopSwitch) that elaborate (slightly) on _WinAPI_CreateDesktop() to create a second workspace with some interesting features: Startup: define any number of programmes to be auto-started on the second desktop, hard-coded (by you, in desktopSwitch.au3) or parsed as parameters (from secondDesktop.au3);Full desktop mode: provides acccess to all your desktop shortcuts, start menu (Win7), taskbar, plus a one-button switch in both desktops;Kiosk mode: provides an empty workspace where only your designated startup entries will run; Switch button/GUI is absent; an unadvertised hotkey provides switching to the original desktop (Ctrl-Alt-Del still works, but a task manager started on the second desktop will appear on the original desktop). To enable kiosk mode, set flag $kioskmode=True in secondDesktop.au3;Security: software keyloggers running in your regular environment cannot capture keystrokes on the second desktop, and windows messages cannot be sent between desktops, so your apps won't be hijacked easily through remote control. (NB not extensively tested; use at your own risk!) In full desktop mode, the (red or green) background colour of the Switch GUI shows you whether you are on the exposed or secure desktop.I SecondDesktop.v0.8.7z (first beta release) Important: you'll need to compile desktopSwitch before running secondDesktop. You can test your edited version of desktopSwitch.au3 "dry," as a script on your regular desktop first, by setting its internal flag $testing=True; but don't forget to reset that flag again before compiling.
    1 point
  2. You don't need a so complicated thing... Please try this #include <WindowsConstants.au3> #include <GUIConstants.au3> Global $mainGUI = GUICreate("", 410, 75, -1, -1) GUICtrlCreateLabel("Quantity at morning",5,8,130,33,$ES_CENTER) Local $firstnumber = GUICtrlCreateInput("", 5, 30, 130, 35, BitOR($ES_NUMBER, $ES_CENTER)) GUICtrlSetFont(-1, 16, 700) GUICtrlCreateLabel("Quantity at night",140,8,130,33,$ES_CENTER) Local $secondnumber = GUICtrlCreateInput("", 140, 30, 130, 35, BitOR($ES_NUMBER, $ES_CENTER)) GUICtrlSetFont(-1, 16, 700) GUICtrlCreateLabel("Pieces produced today",275,8,130,33,$ES_CENTER) Local $lastnumber = GUICtrlCreateInput("", 275, 30, 130, 35, BitOR($ES_READONLY, $ES_CENTER)) GUICtrlSetFont(-1, 16, 700) GUICtrlSetBkColor(-1, 0xffffff) GUISetState(@SW_SHOW, $mainGUI) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ;============================================= Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord Local $iCode = BitShift($wParam, 16) ;HiWord If $iCode = $EN_CHANGE Then If $iIDFrom = $firstnumber Then $sInput = GUICtrlRead($firstnumber) GUICtrlSetData($firstnumber, StringRegExpReplace(StringReplace($sInput, " ", ""), '(?<=\d)(?=(\d{3})+(?!\d))', " ")) EndIf If $iIDFrom = $secondnumber Then $sInput = GUICtrlRead($secondnumber) GUICtrlSetData($secondnumber, StringRegExpReplace(StringReplace($sInput, " ", ""), '(?<=\d)(?=(\d{3})+(?!\d))', " ")) EndIf $first = Number(StringReplace(GUICtrlRead($firstnumber), " ", "")) $second = Number(StringReplace(GUICtrlRead($secondnumber), " ", "")) If $second >= $first Then $diff = $second - $first GUICtrlSetData($lastnumber, StringRegExpReplace($diff, '(?<=\d)(?=(\d{3})+(?!\d))', " ")) Else GUICtrlSetData($lastnumber, "0") EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND
    1 point
  3. Is it me or do i see many times the word game in that posted source? jos
    1 point
  4. GUICtrlSendMsg returns in this case afaik a GDI bitmap handle which needs to be released to avoid memory leak. What you can do also is to clean up the resources when closing the script. Also all controls have a sort on the z-axis thus who is on the top depends on the creation of the controls. Last control seems to win and will be topmost. Just put GUICtrlSetBkColor(-1, 0x808080) just after the $lMarker = GUICtrlCreateLabel line and you will see what happens. I discovered another odd thing: after moved some of the controls, minimized the GUI and restored it again all controls we moved to their initial positions. Of course you can check during the movement that a control is not moving outside a defined area. Something like this here: #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> AutoItSetOption("MouseCoordMode", 2) Global $g_hGUI, $g_hImage, $g_hGDIBitmap, $g_aCtrls[4][7] Example() Func Example() AutoItSetOption("GUIOnEventMode", 1) ; X64 running support Local $sWow64 = "" If @AutoItX64 Then $sWow64 = "\Wow6432Node" ;get AutoIt install dir Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt" Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif" If Not FileExists($sFile) Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30) Exit EndIf Local $i _GDIPlus_Startup() $g_hImage = _GDIPlus_ImageLoadFromFile($sFile) $g_hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_hImage) $g_hGUI = GUICreate("GDI+", 800, 600) Local $iPic1 = GUICtrlCreatePic("", 20, 50, 169, 68) For $i = 0 To UBound($g_aCtrls) - 1 $g_aCtrls[$i][1] = 100 + $i * 150 ;x pos $g_aCtrls[$i][2] = 100 + $i * 120 ;y pos $g_aCtrls[$i][0] = GUICtrlCreatePic("", $g_aCtrls[$i][1], $g_aCtrls[$i][2], 169, 68) ;ctrl id $g_aCtrls[$i][3] = 50 ;min x pos $g_aCtrls[$i][4] = $g_aCtrls[$i][2] - 20 ;min y pos $g_aCtrls[$i][5] = 600 ;max x pos $g_aCtrls[$i][6] = $g_aCtrls[$i][2] + 20 ;max y pos GUICtrlCreateLabel("", 0, $g_aCtrls[$i][4], 800, 1) GUICtrlSetBkColor(-1, 0x0000FF) GUICtrlCreateLabel("", 0, $g_aCtrls[$i][4] + 107, 800, 1) GUICtrlSetBkColor(-1, 0x0000FF) _WinAPI_DeleteObject(GUICtrlSendMsg($g_aCtrls[$i][0], 0x0172, $IMAGE_BITMAP, $g_hGDIBitmap)) ;$STM_SETIMAGE = 0x0172 Next $lMarker = GUICtrlCreateLabel('***********', 325, 30, 169, 68) GUICtrlSetBkColor(-1, 0xA0A0A0) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) Local $aMChk Do $aMChk = GUIGetCursorInfo($g_hGUI) Switch $aMChk[4] Case $g_aCtrls[0][0] CtrlMove($g_aCtrls, 0, $g_hGUI) Case $g_aCtrls[1][0] CtrlMove($g_aCtrls, 1, $g_hGUI) Case $g_aCtrls[2][0] CtrlMove($g_aCtrls, 2, $g_hGUI) Case $g_aCtrls[3][0] CtrlMove($g_aCtrls, 3, $g_hGUI) EndSwitch Until Not Sleep(50) EndFunc ;==>Example Func CtrlMove(ByRef $g_aCtrls, $iCtrl, $g_hGUI) Local $aCtrlPos = ControlGetPos($g_hGUI, "", $g_aCtrls[$iCtrl][0]) Local $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0]) Local $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1]) Local $bIsPressed = False, $iX, $iY While GUIGetCursorInfo($g_hGUI)[2] $iX = MouseGetPos(0) - $iDX $iY = MouseGetPos(1) - $iDY GUICtrlSetPos($g_aCtrls[$iCtrl][0], ($iX < $g_aCtrls[$iCtrl][3]) ? $g_aCtrls[$iCtrl][3] : ($iX > $g_aCtrls[$iCtrl][5]) ? $g_aCtrls[$iCtrl][5] : $iX, _ ($iY < $g_aCtrls[$iCtrl][4]) ? $g_aCtrls[$iCtrl][4] : ($iY > $g_aCtrls[$iCtrl][6]) ? $g_aCtrls[$iCtrl][6] : $iY) ;~ $bIsPressed = True Sleep(10) WEnd ;~ If $bIsPressed Then _WinAPI_RedrawWindow($g_hGUI) EndFunc ;==>CtrlMove Func _Exit() _WinAPI_DeleteObject($g_hGDIBitmap) _GDIPlus_ImageDispose($g_hImage) _GDIPlus_Shutdown() GUIDelete($g_hGUI) Exit EndFunc ;==>_Exit
    1 point
  5. Try something like this here: #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> AutoItSetOption("MouseCoordMode", 2) Global $g_hGUI, $g_hImage, $g_hGDIBitmap Example() Func Example() AutoItSetOption("GUIOnEventMode", 1) ; X64 running support Local $sWow64 = "" If @AutoItX64 Then $sWow64 = "\Wow6432Node" ;get AutoIt install dir Local $sRegPath = "HKLM\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt" Local $sFile = RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif" If Not FileExists($sFile) Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", $sFile & " not found!", 30) Exit EndIf $g_hGUI = GUICreate("GDI+", 800, 600) Local $iPic1 = GUICtrlCreatePic("", 20, 20, 169, 68) Local $iPic2 = GUICtrlCreatePic("", 200, 200, 169, 68) Local $iPic3 = GUICtrlCreatePic("", 400, 400, 169, 68) Local $iPic4 = GUICtrlCreatePic("", 500, 500, 169, 68) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) _GDIPlus_Startup() $g_hImage = _GDIPlus_ImageLoadFromFile($sFile) $g_hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($g_hImage) Local $i For $i = 1 To 4 _WinAPI_DeleteObject(GUICtrlSendMsg(Execute("$iPic" & $i), 0x0172, $IMAGE_BITMAP, $g_hGDIBitmap)) ;$STM_SETIMAGE = 0x0172 Next Local $aMChk, $aCtrlPos, $iDX, $iDY Do $aMChk = GUIGetCursorInfo($g_hGUI) Switch $aMChk[4] Case $iPic1 $aCtrlPos = ControlGetPos($g_hGUI, "", $iPic1) $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0]) $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1]) While GUIGetCursorInfo($g_hGUI)[2] ControlMove($g_hGUI, "", $iPic1, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY) Sleep(20) WEnd Case $iPic2 $aCtrlPos = ControlGetPos($g_hGUI, "", $iPic2) $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0]) $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1]) While GUIGetCursorInfo($g_hGUI)[2] ControlMove($g_hGUI, "", $iPic2, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY) Sleep(20) WEnd Case $iPic3 $aCtrlPos = ControlGetPos($g_hGUI, "", $iPic3) $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0]) $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1]) While GUIGetCursorInfo($g_hGUI)[2] ControlMove($g_hGUI, "", $iPic3, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY) Sleep(20) WEnd Case $iPic4 $aCtrlPos = ControlGetPos($g_hGUI, "", $iPic4) $iDX = Abs(MouseGetPos(0) - $aCtrlPos[0]) $iDY = Abs(MouseGetPos(1) - $aCtrlPos[1]) While GUIGetCursorInfo($g_hGUI)[2] ControlMove($g_hGUI, "", $iPic4, MouseGetPos(0) - $iDX, MouseGetPos(1) - $iDY) Sleep(20) WEnd EndSwitch Until Not Sleep(50) EndFunc ;==>Example Func _Exit() _WinAPI_DeleteObject($g_hGDIBitmap) _GDIPlus_ImageDispose($g_hImage) _GDIPlus_Shutdown() GUIDelete($g_hGUI) Exit EndFunc ;==>_Exit There is room for optimizations!
    1 point
×
×
  • Create New...