Jump to content

rexx

Active Members
  • Posts

    63
  • Joined

  • Last visited

Recent Profile Visitors

197 profile views

rexx's Achievements

Wayfarer

Wayfarer (2/7)

0

Reputation

  1. Answering myself: Use COM Local $oShell = ObjCreate("Shell.Application") Local $oFolder = $oShell.BrowseForFolder(0, "Select Folder", 0) if IsObj($oFolder) then Local $sName = $oFolder.Self.Name Local $sPath = $oFolder.Self.Path MsgBox(0, "Select Folder", "Name: " & $sName & @CRLF & "Path: " & $sPath) endif
  2. Thanks. But there are some special folders not in the table. For example, "Control Panel" in Windows 7 is "::{26EE0668-A00A-44D7-9371-BEB064C98683}" It's not in the appendix. Can I get it from the system?
  3. No, I mean $var = FileSelectFolder("Select","") and selecting a special folder, $var gets its name (e.g. My Document), instead of its CLSID. My question is how to get the CLSID of the selected special folder.
  4. Hi, Can I get the CLSIDs of special folders (Computer, Control Panel...etc.) from FileSelectFolder()? In the doc it's possible to set root of FileSelectFolder() by CLSIDs, but when I select a special folder, I'll get name of it instead of CLSID. Is it possible?
  5. Thanks! Works fine both 32 and 64 bit.
  6. Hi, I found this is not working under x64. I tried to make some modifications but still not working. Maybe it's the problem of the PEB structure. http://msdn.microsoft.com/en-us/library/aa813706(VS.85).aspx But I don't know how to fix it. Any idea? Func _WinAPI_GetCommandLineFromPID($PID) Local $ret1 = DllCall("kernel32.dll", 'handle', 'OpenProcess', 'dword', $PROCESS_VM_READ+$PROCESS_QUERY_INFORMATION, 'bool', False, 'dword', $PID) Local $tag_PROCESS_BASIC_INFORMATION = "int ExitStatus;" & _ "ptr PebBaseAddress;" & _ "ptr AffinityMask;" & _ "ptr BasePriority;" & _ "ulong_ptr UniqueProcessId;" & _ "ulong InheritedFromUniqueProcessId;" Local $PBI=DllStructCreate($tag_PROCESS_BASIC_INFORMATION) DllCall("ntdll.dll", "int", "ZwQueryInformationProcess", "hwnd", $ret1[0], "int", 0, "ptr", DllStructGetPtr($PBI), "int", _ DllStructGetSize($PBI), "int",0) Local $dw=DllStructCreate("ptr") DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $ret1[0], _ "ptr", DllStructGetData($PBI,2)+0x10, _ ; PebBaseAddress+16 bytes <-- ptr _PROCESS_PARAMETERS "ptr", DllStructGetPtr($dw), "ulong_ptr", 4, "ulong_ptr*", 0) Local $unicode_string = DllStructCreate("ushort Length;ushort MaxLength;ptr String") DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $ret1[0], _ "ptr", DllStructGetData($dw, 1)+0x40, _ ; _PROCESS_PARAMETERS+64 bytes <-- ptr CommandLine Offset (UNICODE_STRING struct) - Win XP / Vista. "ptr", DllStructGetPtr($unicode_string), "ulong_ptr", DllStructGetSize($unicode_string), "ulong_ptr*", 0) Local $ret = DllCall("kernel32.dll", "int", "ReadProcessMemory", "handle", $ret1[0], _ "ptr", DllStructGetData($unicode_string, "String"), _ ; <-- ptr Commandline Unicode String "wstr", 0, "ulong_ptr", DllStructGetData($unicode_string, "Length") + 2, "ulong_ptr*", 0) ; read Length + terminating NULL (2 bytes in unicode) DllCall("kernel32.dll", 'int', 'CloseHandle', "hwnd", $ret1[0]) If $ret[5] Then Return $ret[3] ; If bytes returned, return commandline... Return "" ; Getting empty string is correct behaviour when there is no commandline to be had... EndFunc
  7. OK, I solved it. Just use the $tagNMHDR structure. Global Const $tagNMHDR = "hwnd hWndFrom;uint_ptr IDFrom;INT Code" "Code" is int, not int_ptr #include <GuiTreeView.au3> #Include <WindowsConstants.au3> #Include <GUIConstantsEx.au3> ;Opt("GUICloseOnESC", 0) Opt("GUIOnEventMode", 1) $sTitle = "Treeview Drag & Drop Editing" ;Required global constants: Global $bTreeDrag = False, $bTreeEdit = False, $hDragItem, $hTreeDragImage, $fWhere $hGui = GUICreate($sTitle, 400, 300, -1, -1, -1, -1) $label = GUICtrlCreateLabel("Drag and drop separate items or branches to move them." & _ @LF & "To start edit selected item, LMB on item or press Enter." & _ @LF & "To end editing, LMB outside item (apply) or Esc (cancel) / Enter (apply)." & _ @LF & "To insert new item press Insert, to delete existing item press Delete.", 30, 10, 340, 60) $cTree = GUICtrlCreateTreeView(50,75,300,200,$TVS_HASBUTTONS+$TVS_HASLINES+$TVS_LINESATROOT+$TVS_EDITLABELS+$TVS_CHECKBOXES) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $cTreeItemsStart = GUICtrlCreateDummy() $cTreeItem_1 = GUICtrlCreateTreeViewItem("item 1", $cTree) $cTreeItem_1a = GUICtrlCreateTreeViewItem("item 1a", $cTreeItem_1) $cTreeItem_1b = GUICtrlCreateTreeViewItem("item 1b", $cTreeItem_1) $cTreeItem_2 = GUICtrlCreateTreeViewItem("item 2", $cTree) $cTreeItem_2a = GUICtrlCreateTreeViewItem("item 2a", $cTreeItem_2) $cTreeItem_3 = GUICtrlCreateTreeViewItem("item 3", $cTree) $cTreeItem_3a = GUICtrlCreateTreeViewItem("item 3a", $cTreeItem_3) $cTreeItem_3a1 = GUICtrlCreateTreeViewItem("item 3a1", $cTreeItem_3a) $cTreeItem_4 = GUICtrlCreateTreeViewItem("item 4", $cTree) $cTreeItemsEnd = GUICtrlCreateDummy() ;Treeview with images test: ;~ $hImgList = _GUIImageList_Create (16, 16) ;~ For $ii = 1 To $cTreeItemsEnd-$cTreeItemsStart ;~ _GUIImageList_AddIcon ($hImgList, "shell32.dll", 60+$ii*2) ;~ Next ;~ _GUICtrlTreeView_SetNormalImageList(GUICtrlGetHandle($cTree), $hImgList) ;~ $a = 0 ;~ For $i = $cTreeItemsStart+1 To $cTreeItemsEnd-1 ;~ _GUICtrlTreeView_SetImageIndex($cTree, _GUICtrlTreeView_GetItemHandle($cTree, $i), $a) ;~ _GUICtrlTreeView_SetSelectedImageIndex($cTree, _GUICtrlTreeView_GetItemHandle($cTree, $i), $a) ;~ $a += 1 ;~ Next $label2 = GUICtrlCreateLabel("", 50, 280, 300, 15) GUISetOnEvent($GUI_EVENT_CLOSE, "SysEvents") GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "SysEvents") GUISetOnEvent($GUI_EVENT_PRIMARYUP, "SysEvents") GUIRegisterMsg($WM_NOTIFY, "On_WM_NOTIFY") GUISetState() While 1 Sleep(200) ;add Enter, Esc, Delete and Insert key functionality to treeview edit: ; TreeKeyboardFunc($cTree) WEnd Func SysEvents() Local $hTree = GUICtrlGetHandle($cTree) Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYUP If $bTreeDrag Then _WinAPI_InvalidateRect($hTree) $bTreeDrag = False _GUIImageList_Destroy($hTreeDragImage) ;delete drag image _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark If (TreeItemFromPoint($hTree) = $hDragItem) Then ContinueCase ;move item: $hItem = TreeItemCopy($hTree, $hDragItem, TreeItemFromPoint($hTree), $fWhere) If $hItem <> 0 Then _GUICtrlTreeView_SelectItem($hTree, $hItem) _GUICtrlTreeView_Delete($hTree, $hDragItem) EndIf EndIf Case $GUI_EVENT_MOUSEMOVE If $bTreeDrag = False Then ContinueCase Local $tPoint = DllStructCreate("int;int") DllStructSetData($tPoint, 1, MouseGetPos(0)) DllStructSetData($tPoint, 2, MouseGetPos(1)) Local $hWndPoint = _WinAPI_WindowFromPoint($tPoint) ;cancel drag in progress and cleanup if moved outside treeview: if $hWndPoint <> $hTree then $bTreeDrag = False _WinAPI_InvalidateRect($hTree) _GUIImageList_Destroy($hTreeDragImage) ;delete drag image _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark ContinueCase EndIf $hItemHover = TreeItemFromPoint($hTree) If $hItemHover = 0 Then ;meh Else $aRect = _GUICtrlTreeView_DisplayRect($hTree, $hItemHover) $iTreeY = _WinAPI_GetMousePosY(True, $hTree) Switch $iTreeY Case $aRect[1] To $aRect[1]+Int(($aRect[3]-$aRect[1])/4) _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, $hItemHover) ;add InsertMark before item $fWhere = -1 Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])/3) To $aRect[1]+Int(($aRect[3]-$aRect[1])*2/3) _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, $hItemHover) ;add DropTarget $fWhere = 0 Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])*2/3) To $aRect[3] _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 1, $hItemHover) ;add InsertMark after item $fWhere = 1 EndSwitch EndIf DrawDragImage($hTree, $hTreeDragImage) EndSwitch EndFunc ; TreeItemFromPoint() ; Returns handle of tree item under mouse: Func TreeItemFromPoint($hWnd) Local $tMPos = _WinAPI_GetMousePos(True, $hWnd) Return _GUICtrlTreeView_HitTestItem($hWnd, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) EndFunc ; TreeItemCopy() ; Copies tree item $hItemSource and all its children to an item $hItemTarget, depending on $fDirection ; $fDirection: ; -1 = before $hItemTarget ; 0 = inside $hItemTarget ; 1 = after $hItemTarget Func TreeItemCopy($hWnd, $hItemSource, $hItemTarget, $fDirection) ;making sure parent can't be dropped onto one of its descendants: $hTest = $hItemTarget Do $hTest = _GUICtrlTreeView_GetParentHandle($hWnd, $hTest) If $hTest = $hItemSource Then Return 0 Until $hTest = 0 ;create new item at determined position $sText = _GUICtrlTreeView_GetText($hWnd, $hItemSource) $hParent = _GUICtrlTreeView_GetParentHandle($hWnd, $hItemTarget) Switch $fDirection Case -1 $hPrev = _GUICtrlTreeView_GetPrevSibling($hWnd, $hItemTarget) If $hPrev = 0 Then $hNew = _GUICtrlTreeView_AddFirst($hWnd, $hItemTarget, $sText) Else $hNew = _GUICtrlTreeView_InsertItem($hWnd, $sText, $hParent, $hPrev) EndIf Case 0 $hNew = _GUICtrlTreeView_InsertItem($hWnd, $sText, $hItemTarget) Case 1 $hNew = _GUICtrlTreeView_InsertItem($hWnd, $sText, $hParent, $hItemTarget) Case Else Return 0 EndSwitch ;save item state and checkbox image if there is such _GUICtrlTreeView_SetState($hWnd, $hNew, _GUICtrlTreeView_GetState($hWnd, $hItemSource)) If _GUICtrlTreeView_GetStateImageList($hWnd) <> 0 Then _GUICtrlTreeView_SetStateImageIndex($hWnd, $hNew, _GUICtrlTreeView_GetStateImageIndex($hWnd, $hItemSource)) EndIf ;save icon/selected image indexes If _GUICtrlTreeView_GetNormalImageList($hWnd) <> 0 Then _GUICtrlTreeView_SetImageIndex($hWnd, $hNew, _GUICtrlTreeView_GetImageIndex($hWnd, $hItemSource)) _GUICtrlTreeView_SetSelectedImageIndex($hWnd, $hNew, _GUICtrlTreeView_GetSelectedImageIndex($hWnd, $hItemSource)) EndIf ;recurse through descendants: $iChildCount = _GUICtrlTreeView_GetChildCount($hWnd, $hItemSource) If $iChildCount > 0 Then For $i = 0 To $iChildCount-1 $hRecSource = _GUICtrlTreeView_GetItemByIndex($hWnd, $hItemSource, $i) TreeItemCopy($hWnd, $hRecSource, $hNew, 0) Next EndIf Return $hNew EndFunc Func On_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) ;wparam = cid, lparam = pnmh If $wParam = $cTree Then Local $tNMHDR = DllStructCreate("hwnd hTree;int_ptr;int code", $lParam) Local $code = DllStructGetData($tNMHDR, "code") Local $hTree = HWnd(DllStructGetData($tNMHDR, "hTree")) Switch $code Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW $bTreeDrag = True $hDragItem = TreeItemFromPoint($hTree) ;~ _GUICtrlTreeView_SelectItem($hTree, $hDragItem) _GUICtrlTreeView_SetSelected($hTree, _GUICtrlTreeView_GetSelection($hTree), False) $hTreeDragImage = TreeCreateDragImage($hTree, $hDragItem) DrawDragImage($hTree, $hTreeDragImage) Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW $bTreeEdit = True ;~ $hTreeEdit = _SendMessage($hTree, $TVM_GETEDITCONTROL, 0, 0) Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW $bTreeEdit = False Return 1 Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW Local $hSel = _GUICtrlTreeView_GetSelection($hTree) ; Local $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW, $lParam) ; Local $hSel = DllStructGetData($tNMTREEVIEW, "NewhItem") Local $sTxt = "Selected: " & _GUICtrlTreeView_GetText($hTree, $hSel) & " (item handle " & $hSel & ")" GUICtrlSetData($label2, $sTxt) Case Else EndSwitch ; EndIf EndFunc Func KeyPressed($iHexKey) Local $aRet = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", $iHexKey) ;~ If BitAND($aRet[0], 0x8000) Or BitAND($aRet[0], 1) Then Return 1 If BitAND($aRet[0], 1) Then Return 1 Return 0 EndFunc ;Func TreeKeyboardFunc($cID) ; Local $hWnd = GUICtrlGetHandle($cID) ; If $bTreeDrag Then Return ; If $bTreeEdit Then ; If KeyPressed(0x0d) Then _SendMessage($hWnd, $TVM_ENDEDITLABELNOW, 0, 0) ;enter ; If KeyPressed(0x1b) Then _SendMessage($hWnd, $TVM_ENDEDITLABELNOW, 1, 0) ;esc ; EndIf ; Local $aRet = DllCall('user32.dll', 'hwnd', 'GetFocus') ; If $aRet[0] = $hWnd Then ; If KeyPressed(0x2d) Then _GUICtrlTreeView_Add($hWnd, _GUICtrlTreeView_GetSelection($hWnd), "New Item") ;insert ; If KeyPressed(0x2e) Then _GUICtrlTreeView_Delete($hWnd, _GUICtrlTreeView_GetSelection($hWnd)) ;delete ; If KeyPressed(0x0d) Then _SendMessage($hWnd, $TVM_EDITLABEL, 0, _GUICtrlTreeView_GetSelection($hWnd)) ;enter ; EndIf ;EndFunc Func TreeCreateDragImage($hWnd, $hItem) ;if treeview has imagelist, use image from it If _GUICtrlTreeView_GetNormalImageList($hWnd) <> 0 Then Return _GUICtrlTreeView_CreateDragImage($hWnd, $hItem) ;if not, create a bitmap of dragitem's text rectangle and put it into imagelist. Local $aItemRect = _GUICtrlTreeView_DisplayRect($hWnd, $hItem, True) Local $iImgW = $aItemRect[2]-$aItemRect[0] Local $iImgH = $aItemRect[3]-$aItemRect[1] Local $hTreeDC = _WinAPI_GetDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hTreeDC) Local $hMemBmp = _WinAPI_CreateCompatibleBitmap($hTreeDC, $iImgW, $iImgH) Local $hMemBmpOld = _WinAPI_SelectObject($hMemDC, $hMemBmp) _WinAPI_BitBlt($hMemDC, 0, 0, $iImgW, $iImgH, $hTreeDC, $aItemRect[0], $aItemRect[1], $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hMemBmpOld) _WinAPI_ReleaseDC($hWnd, $hTreeDC) _WinAPI_DeleteDC($hMemDC) Local $hImgList = _GUIImageList_Create($iImgW, $iImgH, 6) _GUIImageList_Add($hImgList, $hMemBmp) _WinAPI_DeleteObject($hMemBmp) Return $hImgList EndFunc ; Draw drag image ; by Gary Frost (gafrost) (?) Func DrawDragImage(ByRef $hControl, ByRef $aDrag) Local $tPoint, $hDC $hDC = _WinAPI_GetWindowDC($hControl) $tPoint = _WinAPI_GetMousePos(True, $hControl) _WinAPI_InvalidateRect($hControl) _GUIImageList_Draw($aDrag, 0, $hDC, DllStructGetData($tPoint, "X")-10, DllStructGetData($tPoint, "Y")-8) _WinAPI_ReleaseDC($hControl, $hDC) EndFunc ;==>DrawDragImage
  8. I found the solution for WindowFromPoint http://www.autoitscript.com/forum/index.php?showtopic=109121 But the first problem still not solved.
  9. http://www.autoitscript.com/forum/index.php?showtopic=56411 It works fine in x86, but in x64, I got some problem in DLL calls. First, in the WM_NOTIFY function, Local $tNMHDR = DllStructCreate("hwnd hTree;int_ptr;int_ptr code", $lParam) Local $code = DllStructGetData($tNMHDR, "code") I use int_ptr in the struct to get the correct 64-bit int, but it becomes unsigned int. The help file says that int_ptr is signed int. Is that a bug or I'm doing something wrong? I convert both $code and the $TVN_ constants to HEX to make it work, but I think it's not a good solution. And the second problem, in the SysEvents() function. Case $GUI_EVENT_MOUSEMOVE If $bTreeDrag = False Then ContinueCase $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1)) ;cancel drag in progress and cleanup if moved outside treeview: If ($aHwnd[0] <> $hTree) Then $bTreeDrag = False _WinAPI_InvalidateRect($hTree) _GUIImageList_Destroy($hTreeDragImage) ;delete drag image _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark ContinueCase EndIf The $aHwnd[0] is always a strange number, so it always stop dragging here. I've tried use "uint_ptr" for mouse position, but not works. Anyone helps? Thanks in advance. Here's the full code. #include <GuiTreeView.au3> #Include <WindowsConstants.au3> #Include <GUIConstantsEx.au3> ;Opt("GUICloseOnESC", 0) Opt("GUIOnEventMode", 1) $sTitle = "Treeview Drag & Drop Editing" ;Required global constants: Global $bTreeDrag = False, $bTreeEdit = False, $hDragItem, $hTreeDragImage, $fWhere $hGui = GUICreate($sTitle, 400, 300, -1, -1, -1, -1) $label = GUICtrlCreateLabel("Drag and drop separate items or branches to move them." & _ @LF & "To start edit selected item, LMB on item or press Enter." & _ @LF & "To end editing, LMB outside item (apply) or Esc (cancel) / Enter (apply)." & _ @LF & "To insert new item press Insert, to delete existing item press Delete.", 30, 10, 340, 60) $cTree = GUICtrlCreateTreeView(50,75,300,200,$TVS_HASBUTTONS+$TVS_HASLINES+$TVS_LINESATROOT+$TVS_EDITLABELS+$TVS_CHECKBOXES) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $cTreeItemsStart = GUICtrlCreateDummy() $cTreeItem_1 = GUICtrlCreateTreeViewItem("item 1", $cTree) $cTreeItem_1a = GUICtrlCreateTreeViewItem("item 1a", $cTreeItem_1) $cTreeItem_1b = GUICtrlCreateTreeViewItem("item 1b", $cTreeItem_1) $cTreeItem_2 = GUICtrlCreateTreeViewItem("item 2", $cTree) $cTreeItem_2a = GUICtrlCreateTreeViewItem("item 2a", $cTreeItem_2) $cTreeItem_3 = GUICtrlCreateTreeViewItem("item 3", $cTree) $cTreeItem_3a = GUICtrlCreateTreeViewItem("item 3a", $cTreeItem_3) $cTreeItem_3a1 = GUICtrlCreateTreeViewItem("item 3a1", $cTreeItem_3a) $cTreeItem_4 = GUICtrlCreateTreeViewItem("item 4", $cTree) $cTreeItemsEnd = GUICtrlCreateDummy() ;Treeview with images test: ;~ $hImgList = _GUIImageList_Create (16, 16) ;~ For $ii = 1 To $cTreeItemsEnd-$cTreeItemsStart ;~ _GUIImageList_AddIcon ($hImgList, "shell32.dll", 60+$ii*2) ;~ Next ;~ _GUICtrlTreeView_SetNormalImageList(GUICtrlGetHandle($cTree), $hImgList) ;~ $a = 0 ;~ For $i = $cTreeItemsStart+1 To $cTreeItemsEnd-1 ;~ _GUICtrlTreeView_SetImageIndex($cTree, _GUICtrlTreeView_GetItemHandle($cTree, $i), $a) ;~ _GUICtrlTreeView_SetSelectedImageIndex($cTree, _GUICtrlTreeView_GetItemHandle($cTree, $i), $a) ;~ $a += 1 ;~ Next $label2 = GUICtrlCreateLabel("", 50, 280, 300, 15) GUISetOnEvent($GUI_EVENT_CLOSE, "SysEvents") GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "SysEvents") GUISetOnEvent($GUI_EVENT_PRIMARYUP, "SysEvents") GUIRegisterMsg($WM_NOTIFY, "On_WM_NOTIFY") GUISetState() While 1 Sleep(200) ;add Enter, Esc, Delete and Insert key functionality to treeview edit: ; TreeKeyboardFunc($cTree) WEnd Func SysEvents() Local $hTree = GUICtrlGetHandle($cTree) Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYUP If $bTreeDrag Then _WinAPI_InvalidateRect($hTree) $bTreeDrag = False _GUIImageList_Destroy($hTreeDragImage) ;delete drag image _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark If (TreeItemFromPoint($hTree) = $hDragItem) Then ContinueCase ;move item: $hItem = TreeItemCopy($hTree, $hDragItem, TreeItemFromPoint($hTree), $fWhere) If $hItem <> 0 Then _GUICtrlTreeView_SelectItem($hTree, $hItem) _GUICtrlTreeView_Delete($hTree, $hDragItem) EndIf EndIf Case $GUI_EVENT_MOUSEMOVE If $bTreeDrag = False Then ContinueCase $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1)) ;cancel drag in progress and cleanup if moved outside treeview: If ($aHwnd[0] <> $hTree) Then $bTreeDrag = False _WinAPI_InvalidateRect($hTree) _GUIImageList_Destroy($hTreeDragImage) ;delete drag image _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark ContinueCase EndIf $hItemHover = TreeItemFromPoint($hTree) If $hItemHover = 0 Then ;meh Else $aRect = _GUICtrlTreeView_DisplayRect($hTree, $hItemHover) $iTreeY = _WinAPI_GetMousePosY(True, $hTree) Switch $iTreeY Case $aRect[1] To $aRect[1]+Int(($aRect[3]-$aRect[1])/4) _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 0, $hItemHover) ;add InsertMark before item $fWhere = -1 Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])/3) To $aRect[1]+Int(($aRect[3]-$aRect[1])*2/3) _SendMessage($hTree, $TVM_SETINSERTMARK, 0, 0) ;remove InsertMark _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, $hItemHover) ;add DropTarget $fWhere = 0 Case 1+$aRect[1]+Int(($aRect[3]-$aRect[1])*2/3) To $aRect[3] _SendMessage($hTree, $TVM_SELECTITEM, $TVGN_DROPHILITE, 0) ;remove DropTarget _SendMessage($hTree, $TVM_SETINSERTMARK, 1, $hItemHover) ;add InsertMark after item $fWhere = 1 EndSwitch EndIf DrawDragImage($hTree, $hTreeDragImage) EndSwitch EndFunc ; TreeItemFromPoint() ; Returns handle of tree item under mouse: Func TreeItemFromPoint($hWnd) Local $tMPos = _WinAPI_GetMousePos(True, $hWnd) Return _GUICtrlTreeView_HitTestItem($hWnd, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) EndFunc ; TreeItemCopy() ; Copies tree item $hItemSource and all its children to an item $hItemTarget, depending on $fDirection ; $fDirection: ; -1 = before $hItemTarget ; 0 = inside $hItemTarget ; 1 = after $hItemTarget Func TreeItemCopy($hWnd, $hItemSource, $hItemTarget, $fDirection) ;making sure parent can't be dropped onto one of its descendants: $hTest = $hItemTarget Do $hTest = _GUICtrlTreeView_GetParentHandle($hWnd, $hTest) If $hTest = $hItemSource Then Return 0 Until $hTest = 0 ;create new item at determined position $sText = _GUICtrlTreeView_GetText($hWnd, $hItemSource) $hParent = _GUICtrlTreeView_GetParentHandle($hWnd, $hItemTarget) Switch $fDirection Case -1 $hPrev = _GUICtrlTreeView_GetPrevSibling($hWnd, $hItemTarget) If $hPrev = 0 Then $hNew = _GUICtrlTreeView_AddFirst($hWnd, $hItemTarget, $sText) Else $hNew = _GUICtrlTreeView_InsertItem($hWnd, $sText, $hParent, $hPrev) EndIf Case 0 $hNew = _GUICtrlTreeView_InsertItem($hWnd, $sText, $hItemTarget) Case 1 $hNew = _GUICtrlTreeView_InsertItem($hWnd, $sText, $hParent, $hItemTarget) Case Else Return 0 EndSwitch ;save item state and checkbox image if there is such _GUICtrlTreeView_SetState($hWnd, $hNew, _GUICtrlTreeView_GetState($hWnd, $hItemSource)) If _GUICtrlTreeView_GetStateImageList($hWnd) <> 0 Then _GUICtrlTreeView_SetStateImageIndex($hWnd, $hNew, _GUICtrlTreeView_GetStateImageIndex($hWnd, $hItemSource)) EndIf ;save icon/selected image indexes If _GUICtrlTreeView_GetNormalImageList($hWnd) <> 0 Then _GUICtrlTreeView_SetImageIndex($hWnd, $hNew, _GUICtrlTreeView_GetImageIndex($hWnd, $hItemSource)) _GUICtrlTreeView_SetSelectedImageIndex($hWnd, $hNew, _GUICtrlTreeView_GetSelectedImageIndex($hWnd, $hItemSource)) EndIf ;recurse through descendants: $iChildCount = _GUICtrlTreeView_GetChildCount($hWnd, $hItemSource) If $iChildCount > 0 Then For $i = 0 To $iChildCount-1 $hRecSource = _GUICtrlTreeView_GetItemByIndex($hWnd, $hItemSource, $i) TreeItemCopy($hWnd, $hRecSource, $hNew, 0) Next EndIf Return $hNew EndFunc Func On_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) ;wparam = cid, lparam = pnmh If $wParam = $cTree Then Local $tNMHDR = DllStructCreate("hwnd hTree;int_ptr;int_ptr code", $lParam) Local $code = DllStructGetData($tNMHDR, "code") Local $hTree = HWnd(DllStructGetData($tNMHDR, "hTree")) ; tooltip($code) Switch Hex($code) Case Hex($TVN_BEGINDRAGA), Hex($TVN_BEGINDRAGW) ; msgbox(0,0,"Begin Drag",0) $bTreeDrag = True $hDragItem = TreeItemFromPoint($hTree) ;~ _GUICtrlTreeView_SelectItem($hTree, $hDragItem) _GUICtrlTreeView_SetSelected($hTree, _GUICtrlTreeView_GetSelection($hTree), False) $hTreeDragImage = TreeCreateDragImage($hTree, $hDragItem) DrawDragImage($hTree, $hTreeDragImage) Case Hex($TVN_BEGINLABELEDITA), Hex($TVN_BEGINLABELEDITW) $bTreeEdit = True ;~ $hTreeEdit = _SendMessage($hTree, $TVM_GETEDITCONTROL, 0, 0) Case Hex($TVN_ENDLABELEDITA), Hex($TVN_ENDLABELEDITW) $bTreeEdit = False Return 1 Case Hex($TVN_SELCHANGEDA), Hex($TVN_SELCHANGEDW) Local $hSel = _GUICtrlTreeView_GetSelection($hTree) ; Local $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW, $lParam) ; Local $hSel = DllStructGetData($tNMTREEVIEW, "NewhItem") Local $sTxt = "Selected: " & _GUICtrlTreeView_GetText($hTree, $hSel) & " (item handle " & $hSel & ")" GUICtrlSetData($label2, $sTxt) Case Else EndSwitch ; EndIf EndFunc Func KeyPressed($iHexKey) Local $aRet = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", $iHexKey) ;~ If BitAND($aRet[0], 0x8000) Or BitAND($aRet[0], 1) Then Return 1 If BitAND($aRet[0], 1) Then Return 1 Return 0 EndFunc ;Func TreeKeyboardFunc($cID) ; Local $hWnd = GUICtrlGetHandle($cID) ; If $bTreeDrag Then Return ; If $bTreeEdit Then ; If KeyPressed(0x0d) Then _SendMessage($hWnd, $TVM_ENDEDITLABELNOW, 0, 0) ;enter ; If KeyPressed(0x1b) Then _SendMessage($hWnd, $TVM_ENDEDITLABELNOW, 1, 0) ;esc ; EndIf ; Local $aRet = DllCall('user32.dll', 'hwnd', 'GetFocus') ; If $aRet[0] = $hWnd Then ; If KeyPressed(0x2d) Then _GUICtrlTreeView_Add($hWnd, _GUICtrlTreeView_GetSelection($hWnd), "New Item") ;insert ; If KeyPressed(0x2e) Then _GUICtrlTreeView_Delete($hWnd, _GUICtrlTreeView_GetSelection($hWnd)) ;delete ; If KeyPressed(0x0d) Then _SendMessage($hWnd, $TVM_EDITLABEL, 0, _GUICtrlTreeView_GetSelection($hWnd)) ;enter ; EndIf ;EndFunc Func TreeCreateDragImage($hWnd, $hItem) ;if treeview has imagelist, use image from it If _GUICtrlTreeView_GetNormalImageList($hWnd) <> 0 Then Return _GUICtrlTreeView_CreateDragImage($hWnd, $hItem) ;if not, create a bitmap of dragitem's text rectangle and put it into imagelist. Local $aItemRect = _GUICtrlTreeView_DisplayRect($hWnd, $hItem, True) Local $iImgW = $aItemRect[2]-$aItemRect[0] Local $iImgH = $aItemRect[3]-$aItemRect[1] Local $hTreeDC = _WinAPI_GetDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hTreeDC) Local $hMemBmp = _WinAPI_CreateCompatibleBitmap($hTreeDC, $iImgW, $iImgH) Local $hMemBmpOld = _WinAPI_SelectObject($hMemDC, $hMemBmp) _WinAPI_BitBlt($hMemDC, 0, 0, $iImgW, $iImgH, $hTreeDC, $aItemRect[0], $aItemRect[1], $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hMemBmpOld) _WinAPI_ReleaseDC($hWnd, $hTreeDC) _WinAPI_DeleteDC($hMemDC) Local $hImgList = _GUIImageList_Create($iImgW, $iImgH, 6) _GUIImageList_Add($hImgList, $hMemBmp) _WinAPI_DeleteObject($hMemBmp) Return $hImgList EndFunc ; Draw drag image ; by Gary Frost (gafrost) (?) Func DrawDragImage(ByRef $hControl, ByRef $aDrag) Local $tPoint, $hDC $hDC = _WinAPI_GetWindowDC($hControl) $tPoint = _WinAPI_GetMousePos(True, $hControl) _WinAPI_InvalidateRect($hControl) _GUIImageList_Draw($aDrag, 0, $hDC, DllStructGetData($tPoint, "X")-10, DllStructGetData($tPoint, "Y")-8) _WinAPI_ReleaseDC($hControl, $hDC) EndFunc ;==>DrawDragImage
  10. Just run the example script in UDF help file and you can see the same problem. #include <GuiMenu.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $iMemo _Main() Func _Main() Local $hGUI, $hFile, $hEdit, $hHelp, $hMain Local Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout ; Create GUI $hGUI = GUICreate("Menu", 400, 300) ; Create File menu $hFile = _GUICtrlMenu_CreateMenu () _GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew) _GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen) _GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave) _GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0) _GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit) ; Create Edit menu $hEdit = _GUICtrlMenu_CreateMenu () _GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut) _GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy) _GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste) ; Create Help menu $hHelp = _GUICtrlMenu_CreateMenu () _GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout) ; Create Main menu $hMain = _GUICtrlMenu_CreateMenu () _GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile) _GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit) _GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp) ; Set window menu _GUICtrlMenu_SetMenu ($hGUI, $hMain) ; Create memo control $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Set New menu item to have a bitmap _GUICtrlMenu_SetItemBmp ($hFile, 0, _WinAPI_CreateSolidBitmap ($hGUI, 0xFF0000, 11, 11)) MemoWrite("Item bitmap handle: 0x" & Hex(_GUICtrlMenu_GetItemBmp ($hFile, 0))) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Write message to memo Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite
  11. I use _GUICtrlMenu_SetItemBmp() to set an icon to my menu item. In vista, all works good, but in xp, i works but looks not so good. Here's a screenshot. The left one is au3, and the right one is ahk_L (a mod of ahk). In the au3 one, there's no margin between icon and text. And the highlighted item's icon is also highlighted. But I prefer something like the ahk one. Is there any way to do so? Thanks!
  12. Great! I don't even need the dummy control. Thanks.
  13. Thanks, it works! But when I use OnEvent mode it does not work. Sorry I should ask for OnEvent mode at the first time. Thanks again! #Include <GUIConstantsEx.au3> #Include <HotKeyInput.au3> Opt("GUIOnEventMode", 1) Global Const $EN_CHANGE = 0x300 Global $Form, $ButtonOk, $Dummy, $HotkeyInput1, $HotkeyInput2, $GUIMsg Global $t $Form = GUICreate('Test', 300, 160) GUISetFont(8.5, 400, 0, 'Tahoma', $Form) $HotkeyInput1 = _GUICtrlCreateHotKeyInput(0, 56, 55, 230, 20, -1, -1, ' - ') $HotkeyInput2 = _GUICtrlCreateHotKeyInput(0, 56, 89, 230, 20) $InputHotkeyKey = $HotkeyInput1 _KeyLock(0x062E) ; Lock CTRL-ALT-DEL for Hotkey Input control, but not for Windows GUICtrlCreateLabel('Hotkey1:', 10, 58, 44, 14) GUICtrlCreateLabel('Hotkey2:', 10, 92, 44, 14) GUICtrlCreateLabel('Click on Input box and hold a combination of keys.' & @CR & 'Press OK to view the code.', 10, 10, 280, 28) $ButtonOk = GUICtrlCreateButton('OK', 110, 124, 80, 23) GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS)) $Dummy = GUICtrlCreateDummy() GUICtrlSetOnEvent($Dummy, "DummyEvent") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() While 1 Sleep(10) WEnd Func DummyEvent() InputHotkeyChange(GUICtrlRead($Dummy)) EndFunc Func InputHotkeyChange($iInput) ToolTip(GUICtrlRead($InputHotkeyKey) & @LF & _GUICtrlReadHotKeyInput($InputHotkeyKey)) EndFunc ;==>InputHotkeyChange Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iCode = _WinAPI_HiWord($wParam) Local $iID = _WinAPI_LoWord($wParam) Local $hCtrl = $lParam If $iCode = $EN_CHANGE Then Switch $iID Case $InputHotkeyKey GUICtrlSendToDummy($Dummy, $iID) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND
  14. I found a copy on my computer. And I have made some modifications on it, so that it can use more than two modifiers. Here's the original one._AsyncHotKeySet_mod.au3 And this is my version._AsyncHotKeySet2.au3 The keycode format is like Hotkey.au3, 0~7 bit is virtual key code, and 8 9 10 11 bit is shift, ctrl, alt, win respectively. Also add an option to send keycode to the called function.
  15. Hi, Can I get the hotkey code on change? I use the code below, and it gets the hotkey text correctly, but the key code seems to be previous one. #Include <GUIConstantsEx.au3> #Include <HotKeyInput.au3> Global Const $EN_CHANGE = 0x300 Global $Form, $ButtonOk, $HotkeyInput1, $HotkeyInput2, $GUIMsg Global $t $Form = GUICreate('Test', 300, 160) GUISetFont(8.5, 400, 0, 'Tahoma', $Form) $HotkeyInput1 = _GUICtrlCreateHotKeyInput(0, 56, 55, 230, 20, -1, -1, ' - ') $HotkeyInput2 = _GUICtrlCreateHotKeyInput(0, 56, 89, 230, 20) $InputHotkeyKey = $HotkeyInput1 _KeyLock(0x062E) ; Lock CTRL-ALT-DEL for Hotkey Input control, but not for Windows GUICtrlCreateLabel('Hotkey1:', 10, 58, 44, 14) GUICtrlCreateLabel('Hotkey2:', 10, 92, 44, 14) GUICtrlCreateLabel('Click on Input box and hold a combination of keys.' & @CR & 'Press OK to view the code.', 10, 10, 280, 28) $ButtonOk = GUICtrlCreateButton('OK', 110, 124, 80, 23) GUICtrlSetState(-1, BitOR($GUI_DEFBUTTON, $GUI_FOCUS)) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() While 1 $GUIMsg = GUIGetMsg() Select Case $GUIMsg = $GUI_EVENT_CLOSE Exit Case $GUIMsg = $ButtonOk $t = ' Hotkey1: 0x' & StringRight(Hex(_GUICtrlReadHotKeyInput($HotkeyInput1)), 4) & ' (' & GUICtrlRead($HotkeyInput1) & ') ' & @CR & @CR & _ ' Hotkey2: 0x' & StringRight(Hex(_GUICtrlReadHotKeyInput($HotkeyInput2)), 4) & ' (' & GUICtrlRead($HotkeyInput2) & ') ' MsgBox(0, 'Code', $t, 0, $Form) EndSelect WEnd Func InputHotkeyChange($iInput) tooltip(GUICtrlRead($InputHotkeyKey)&@LF&_GUICtrlReadHotKeyInput($InputHotkeyKey)) EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iCode = _WinAPI_HiWord($wParam) Local $iID = _WinAPI_LoWord($wParam) Local $hCtrl = $lParam if $iCode = $EN_CHANGE then Switch $iID Case $InputHotkeyKey InputHotkeyChange($iID) EndSwitch endif return $GUI_RUNDEFMSG EndFunc
×
×
  • Create New...