Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/28/2012 in all areas

  1. Hi, This example demonstrates how to replace the default context menu in an edit control with your own Uses _WinAPI_CallWindowProc, a good function that requires more examples #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiMenu.au3> #include <WinAPI.au3> #include <GUIEdit.au3> ; modified from help example: _WinAPI_CallWindowProc $hGui = GUICreate("Custom context menu for Edit Control example", 489, 354, -1, -1) $editBox = GUICtrlCreateEdit("", 8, 40, 473, 305) GUICtrlSetData(-1, "New text") $checkBox = GUICtrlCreateCheckbox("Use our own context menu", 8, 8, 241, 17) GUICtrlSetState($checkBox, $GUI_CHECKED) ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;!! subclass for $editBox $w_editBoxProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr") $w_editBoxProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($editBox), $GWL_WNDPROC, DllCallbackGetPtr($w_editBoxProcNew)) _WinAPI_SetWindowLong(GUICtrlGetHandle($editBox), $GWL_WNDPROC, DllCallbackGetPtr($w_editBoxProcNew)) ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;!! our context menu for $editBox $DummyMenu = GUICtrlCreateDummy() $ContextMenu = GUICtrlCreateContextMenu($DummyMenu) $TestMenuItem = GUICtrlCreateMenuItem("Our Custom Context Menu", $ContextMenu) GUICtrlSetState($TestMenuItem, $GUI_DEFBUTTON) GUICtrlCreateMenuItem("", $ContextMenu) $UndoMenuItem = GUICtrlCreateMenuItem("&Undo", $ContextMenu) GUICtrlCreateMenuItem("", $ContextMenu) $CutMenuItem = GUICtrlCreateMenuItem("&Cut", $ContextMenu) $CopyMenuItem = GUICtrlCreateMenuItem("&Copy", $ContextMenu) $PasteMenuItem = GUICtrlCreateMenuItem("&Paste", $ContextMenu) $DeleteMenuItem = GUICtrlCreateMenuItem("&Delete", $ContextMenu) GUICtrlCreateMenuItem("", $ContextMenu) $SelectAllMenuItem = GUICtrlCreateMenuItem("&Select all", $ContextMenu) GUICtrlCreateMenuItem("", $ContextMenu) $InsertDateMenuItem = GUICtrlCreateMenuItem("&Insert Date and Time", $ContextMenu) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg ; toggle our context menu on / off Case $checkBox If BitAND(GUICtrlRead($checkBox), $GUI_CHECKED) = $GUI_CHECKED Then _WinAPI_SetWindowLong(GUICtrlGetHandle($editBox), $GWL_WNDPROC, DllCallbackGetPtr($w_editBoxProcNew)) Else _WinAPI_SetWindowLong(GUICtrlGetHandle($editBox), $GWL_WNDPROC, $w_editBoxProcOld) EndIf Case $GUI_EVENT_CLOSE ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;!! we must free the callback before exit !! _WinAPI_SetWindowLong(GUICtrlGetHandle($editBox), $GWL_WNDPROC, $w_editBoxProcOld) DllCallbackFree($w_editBoxProcNew) Exit EndSwitch WEnd ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;!! process our context menu messages Func MenuItem($iSelected) Switch $iSelected Case $TestMenuItem _GUICtrlEdit_AppendText($editBox, @CRLF & "Our Custom Context Menu") Case $UndoMenuItem _GUICtrlEdit_Undo($editBox) Case $CutMenuItem MenuItem($CopyMenuItem) MenuItem($DeleteMenuItem) Case $CopyMenuItem Local $aSel, $sText $aSel = _GUICtrlEdit_GetSel($editBox) If ($aSel[0] <> $aSel[1]) Then $sText = StringMid(_GUICtrlEdit_GetText($editBox), $aSel[0] + 1, ($aSel[1] - $aSel[0]) + 1) ClipPut($sText) EndIf Case $PasteMenuItem Local $sText = ClipGet() If (Not @error) Then _GUICtrlEdit_ReplaceSel($editBox, $sText, True) Case $DeleteMenuItem _GUICtrlEdit_ReplaceSel($editBox, "", True) Case $SelectAllMenuItem _GUICtrlEdit_SetSel($editBox, 0, -1) Case $InsertDateMenuItem _GUICtrlEdit_ReplaceSel($editBox, @CRLF & @YEAR &"/"& @MON &"/"& @MDAY &" "& @HOUR &":" & @MIN &":" & @SEC) EndSwitch EndFunc ;==>ShowMenu ; auxilary function to update menu item states, not required Func UpdateMenuStates() Local $aSel = _GUICtrlEdit_GetSel($editBox) Local $iLen = _GUICtrlEdit_GetTextLen($editBox) _GUICtrlEnabled($UndoMenuItem, _GUICtrlEdit_CanUndo($editBox)) _GUICtrlEnabled($CutMenuItem, ($aSel[0]<>$aSel[1])) _GUICtrlEnabled($CopyMenuItem, ($aSel[0]<>$aSel[1])) _GUICtrlEnabled($PasteMenuItem, (StringLen(ClipGet())>0)) _GUICtrlEnabled($DeleteMenuItem, ($aSel[0]<>$aSel[1])) _GUICtrlEnabled($SelectAllMenuItem, ($iLen>0) And ($iLen<>$aSel[0]+$aSel[1])) EndFunc ;==>SetMenuTexts ; auxilary function to enable / disable controls, not required Func _GUICtrlEnabled($CtrlID, $fTrue = True) If $fTrue Then GUICtrlSetState($CtrlID, $GUI_ENABLE) Else GUICtrlSetState($CtrlID, $GUI_DISABLE) EndIf EndFunc ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;!! our window subclass for $editBox Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam) Switch $uiMsg Case $WM_CONTEXTMENU If $hWnd = GUICtrlGetHandle($editBox) Then ; show our context menu UpdateMenuStates() Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($ContextMenu), $hWnd, -1, -1, 1, 1, 2) MenuItem($iSelected) Return 0 EndIf EndSwitch ;pass the unhandled messages to default WindowProc Return _WinAPI_CallWindowProc($w_editBoxProcOld, $hWnd, $uiMsg, $wParam, $lParam) EndFunc ;==>_MyWindowProc Have a good day
    1 point
  2. nullschritt, And then you wonder why no-one offers to help you..... As you feel that this thread serves no useful purpose, there seems only one thing to do.....<click> { © Jos } M23 P.S. Do NOT start another one - we obviously know nothing about this subject, so there is no point in asking.
    1 point
  3. Hello monti. In the AutoIt forums, sharing is caring . You share your code, and we will care for you. Post your code in between autoit tags like this The way we care for you depends on your intent with the code you are attempting to write. If it's code, the community will discipline you If it's code, the community will assist you If it's code, the community will assist you, but you may also be scrutinized for your inability to write code So the of AutoIt will use their skills so that your and code turns into code.
    1 point
  4. Post the code you're using so that we can see what you're trying and what's not working.
    1 point
  5. You try to access an "array" which isn't an array. As you access the "array" after _FileReadToArray I would suggest you make sure the function has run without errors. If an error occurred don't try to access the array because there is none.
    1 point
  6. d4rkdz, At a guess the script cannot find the file. You are setting the @WorkingDir to @TempDir with the Run command - I imagine the file is in @ScriptDir. Try using: local $file = @ScriptDir & "urls.txt"assuming that is where the file is - just adjust the path to fit your actual case. M23
    1 point
×
×
  • Create New...