Jump to content

Recommended Posts

I found this example on an edit control:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiMenu.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo

$hGUI = GUICreate("Test", 300, 200)

$Edit1 = GUICtrlCreateEdit("", 10, 10, 280, 150, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))

$hMenu = _GUICtrlMenu_CreatePopup()

_GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
_GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
_GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)

GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")

$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Edit1), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIDelete($hGui)
DllCallbackFree($wProcHandle)

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case GUICtrlGetHandle($Edit1)
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            ConsoleWrite("-> Open" & @LF)
                        Case $idSave
                            ConsoleWrite("-> Save" & @LF)
                        Case $idInfo
                            ConsoleWrite("-> Info" & @LF)
                    EndSwitch
            EndSwitch
    EndSwitch
    
    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
                          "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
    Return $aRet[0]
EndFunc

How could the above be done for a richedit control?

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to post
Share on other sites
  • Solution

Easy, 99.9% of the code is the same. Change the edit to a rich edit, change anything using GUICtrlGetHandle($Edit1) to just use the handle, change the message handler to use WM_RBUTTONUP because richedits don't send WM_CONTEXTMENU messages I seem to remember. Because you change the message you can't use $wParam like you are above, you probably want $hWnd instead.

Give this a try:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiMenu.au3>
#include <Constants.au3>
#include <WinAPI.au3>

#include <GUIRichEdit.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo

$hGUI = GUICreate("Test", 300, 200)

$Edit1 = _GUICtrlRichEdit_Create($hGUI, "", 10, 10, 280, 150, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))

$hMenu = _GUICtrlMenu_CreatePopup()

_GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
_GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
_GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)

GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")

$wProcOld = _WinAPI_SetWindowLong($Edit1, $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd


GUIDelete($hGUI)
DllCallbackFree($wProcHandle)


Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $Edit1
            Switch $Msg
                Case $WM_RBUTTONUP
                    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            ConsoleWrite("-> Open" & @LF)
                        Case $idSave
                            ConsoleWrite("-> Save" & @LF)
                        Case $idInfo
                            ConsoleWrite("-> Info" & @LF)
                    EndSwitch
            EndSwitch
    EndSwitch

    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)

    Return $aRet[0]
EndFunc   ;==>_WindowProc
Link to post
Share on other sites

Thanks Mat and James!(Or should it be James and Mat?)

Perfect, exactly what I was looking for.

Now I just need to tackle the HTML formatted text to rich edit and back...

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to post
Share on other sites

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By benners
      I have a GUI that contains a treeview and what I am trying to do is to get the context menu to only show when an item is right clicked. Currently, as it's assigned to the treeview, the context menu activates whenever the treeview is clicked. Rather than keep enabling\disabling the menu items I am in need of a way limit the menus popup.
      One of the options on the menu will open another GUI and disable the parent, for this reason, I cannot do much in the WM_NOTIFY portion as it hangs the program and I don't want to hang around blocking the messages.
      The other option is to create a menu for each treeview item when the are added to the list. This will fix the issue but there maybe 100+ items and I don't want to have that many menus all of which have the same 2/3 options.
      I am currently looking at using an Adlib function as mentioned here by Melba. I could create and destroy the menu each time and unregister the adlib when the function closes.
      Anyway, a producer code is below if there are any other ideas, or I've missed the obvious. Cheers
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <GuiTreeView.au3> #include <ButtonConstants.au3> #include <GUIListBox.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI = GUICreate("TreeView", 400, 300) Global $cTreeView = GUICtrlCreateTreeView(10, 10, 380, 280) Local $cParent = GUICtrlCreateTreeViewItem('List', $cTreeView) For $i = 1 To 5 GUICtrlCreateTreeViewItem('Item ' & $i, $cParent) Next Local $cCMenu = GUICtrlCreateContextMenu($cTreeView) Global $cCMenuEdit = GUICtrlCreateMenuItem("Edit", $cCMenu) GUICtrlSetState(-1, $GUI_DISABLE) _GUICtrlTreeView_Expand($cTreeView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cCMenuEdit EndSwitch WEnd EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $cTreeView Switch $iCode Case $NM_RCLICK Local $tPoint = _WinAPI_GetMousePos(True, $hWndFrom) Local $tHitTest = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2)) If BitAND(DllStructGetData($tHitTest, "Flags"), $TVHT_ONITEM) Then If _GUICtrlTreeView_Level($cTreeView, DllStructGetData($tHitTest, 'Item')) > 0 Then GUICtrlSetState($cCMenuEdit, $GUI_ENABLE) Else GUICtrlSetState($cCMenuEdit, $GUI_DISABLE) EndIf _GUICtrlTreeView_SelectItem($hWndFrom, DllStructGetData($tHitTest, 'Item')) Else GUICtrlSetState($cCMenuEdit, $GUI_DISABLE) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  
    • By Jemboy
      Hi,
      For an internal project I want to write internal script to mail some special request to an external party.
      To make it a little bit universal I decided that the user should be able to write or edit the e-mail signature.
      Because I wanted to put a logo into the e-mail, I decided to use RichEdit.

      I I found the following code by  @UEZ and adapted it a little to save and load.
      When I start the script and edit the text only, I can save and load the signature.rtf.
      However the moment I resize one of the images (with the mouse), the script wil only save the edited image.
      Somehow resizing an image deletes the other content of the RichEdit object.
      Does anyone know a solution for me?
      P.s. you need to delete signature.rtf to reset the file.
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGui, $iMsg, $idBtnExit, $hRichEdit $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 520, 550, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 500, 490, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnExit = GUICtrlCreateButton("Exit", 10, 510, 40, 30) $GoodRead = False If FileExists(@ScriptDir & "\signature.rtf") Then $ResSFF = _GUICtrlRichEdit_StreamFromFile($hRichEdit, @ScriptDir & "\signature.rtf") If $ResSFF=true then $GoodRead = True EndIf If $GoodRead=False Then _GUICtrlRichEdit_InsertText($hRichEdit, "Inserting image..." & @LF & @LF) _GUICtrlRichEdit_InsertText($hRichEdit, @LF & "JPG image scaled:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\mslogo.jpg", "\qc", "\picw6747\pich1058\picwgoal6690\pichgoal1860\") ;\qc = centered _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "PNG image:" & @LF & @LF) _GUICtrlRichEdit_InsertBitmap($hRichEdit, "c:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png") _GUICtrlRichEdit_InsertText($hRichEdit, @LF & @LF & "Done.") EndIf GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtnExit _GUICtrlRichEdit_StreamToFile($hRichEdit, @ScriptDir & "\signature.rtf") _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes GUIDelete() Exit EndSwitch WEnd EndFunc ;==>Example Func _GUICtrlRichEdit_InsertBitmap($hWnd, $sFile, $sFormatFunctions = "\", $sBitmapFunctions = "\", $iBgColor = Default) ;coded by UEZ build 2016-02-16 If Not FileExists($sFile) Then Return SetError(0, 0, 1) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(0, 0, 2) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then _GDIPlus_Shutdown() Return SetError(0, 0, 3) EndIf Local Const $aDim = _GDIPlus_ImageGetDimension($hImage) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aDim[0], $aDim[1]), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) If $iBgColor = Default Then $iBgColor = 0xFF000000 + _WinAPI_SwitchColor(_GUICtrlRichEdit_GetBkColor($hWnd)) EndIf _GDIPlus_GraphicsClear($hGfx, $iBgColor) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $aDim[0], $aDim[1]) _GDIPlus_GraphicsDispose($hGfx) Local $binStream = _GDIPlus_StreamImage2BinaryString($hBitmap, "BMP") If @error Then _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return SetError(0, 0, 4) EndIf Local $binBmp = StringMid($binStream, 31) Local Const $binRtf = "{\rtf1\viewkind4" & $sFormatFunctions & " {\pict{\*\picprop}" & $sBitmapFunctions & "dibitmap " & $binBmp & "}\par}" ;check out http://www.biblioscape.com/rtf15_spec.htm _GUICtrlRichEdit_AppendText($hWnd, $binRtf) $binStream = 0 $binBmp = 0 _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Return 1 EndFunc ;==>_GUICtrlRichEdit_InsertBitmap Func _GDIPlus_StreamImage2BinaryString($hBitmap, $sFormat = "JPG", $iQuality = 80, $bSave = False, $sFileName = @ScriptDir & "\Converted.jpg") ;coded by UEZ 2013 build 2014-01-25 (based on the code by Andreik) Local $sImgCLSID, $tGUID, $tParams, $tData Switch $sFormat Case "JPG" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) $tParams = _GDIPlus_ParamInit(1) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Case "PNG", "BMP", "GIF", "TIF" $sImgCLSID = _GDIPlus_EncodersGetCLSID($sFormat) $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Case Else Return SetError(1, 0, 0) EndSwitch Local $hStream = _WinAPI_CreateStreamOnHGlobal() ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(2, 0, 0) _GDIPlus_ImageSaveToStream($hBitmap, $hStream, DllStructGetPtr($tGUID), DllStructGetPtr($tParams)) If @error Then Return SetError(3, 0, 0) Local $hMemory = _WinAPI_GetHGlobalFromStream($hStream) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(4, 0, 0) Local $iMemSize = _MemGlobalSize($hMemory) If Not $iMemSize Then Return SetError(5, 0, 0) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) _WinAPI_ReleaseStream($hStream) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) If $bSave Then Local $hFile = FileOpen($sFileName, 18) If @error Then Return SetError(6, 0, $bData) FileWrite($hFile, $bData) FileClose($hFile) EndIf Return $bData EndFunc ;==>_GDIPlus_StreamImage2BinaryString  
       
    • By TheAutomator
      This is Iconizer:


      This program is made to replace the free / pro version of folder maker.
      (I bundled a few icon packs with it too).

      How it works:

      Icons are copied to the selected folder, the folder icon is changed to that icon and the icon inside the folder is made hidden and read-only.
      By copying the icon to the folder itself you can now move it to another computer and the icon will stay!
      (A new icon will override the old one).

      I wrote a little installer for it to add or remove this program from/to the context menu of any folder, harddrives are also accepted:



      It runs from the contextmenu but also accepts command-line arguments if you wish.
      Just opening it without any parameters wil launch the 'Iconarchive' website.
      Let me know what you think, any tips, bugs or nice ideas are welcome 
      I'm not sure if I can upload the icons because they were extracted from the .ICL file of foldermaker..
      Kind regards! TheAutomator.
      test.bat Icon.ico Iconize.au3 Installer.au3
    • By AFrenchCroissant
      Hello,
      i would like to know why isnt anything displayed on the combo box. i used this example and added it to my code
      Autoit Example :
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> Dim $sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" GUICreate("Test", 400, 100) $cCombo_Font = GUICtrlCreateCombo("", 10, 10, 170, 20, 2097474);HELPHERE GUICtrlSetData($cCombo_Font, _RegEnumVal($sRegKey)) $cLabel = GUICtrlCreateLabel("Font preview", 230, 10, 155, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $cCombo_Font GUICtrlSetFont($cLabel, 10, Default, Default, GUICtrlRead($cCombo_Font)) EndSwitch WEnd Func _RegEnumVal($sKey) Local $i = 1, $sVal, $sResult While 1 $sVal = RegEnumVal($sKey, $i) If @error Then ExitLoop $i += 1 $sResult &= $sVal & "|" WEnd Return StringRegExpReplace($sResult, " \(.*?\)", "") EndFunc ;==>_RegEnumVal And my code:
      #NoTrayIcon #include <Misc.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiEdit.au3> #include <String.au3> #include <GuiRichEdit.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> $WIDTH = 500 $HEIGHT = 380 $EXT1 = "|Rich Text File (*.rtf)" $EXT2 = "|ODF Text (*.odt)" $EXT3 = "|All Files(*.*)" $EXT = $EXT1 & $EXT2 $SETTINGS = "Settings.ini" Dim $FONTKEY = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" Global $FILESAVE, $FILEOPEN = "", $SAVES, $SAVE, $FILEOPENED = 0 Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp $MAINGUI = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE) $TOOLBAR = _GUICtrlToolbar_Create($MAINGUI) _GUIImageList_AddIcon($TOOLBAR, @SystemDir & "\shell.dll", -1) $IMAGES = _GUIImageList_Create(24,24) _GUICtrlToolbar_SetImageList($TOOLBAR, $IMAGES) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -1);AndHereIfYouCouldTHX _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -2) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 3) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 4) _GUICtrlToolbar_AddButtonSep($TOOLBAR) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 5) _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 6) $EDITBOX = _GUICtrlRichEdit_Create($MAINGUI, "This is a test.", 10, 35, $WIDTH - 20, $HEIGHT - 70, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $FONTCOMBOBOX = GUICtrlCreateCombo("", $WIDTH - 170, 10, 160, 20, 2097474);HELPMEHERE GUICtrlSetData($FONTCOMBOBOX, _RegEnumVal($FONTKEY));ALSOHERE $FONTSIZECOMBOBOX = GUICtrlCreateCombo("", $WIDTH - 200, 10, 20, 20, 2097474);FuncForPreviousLineAtTheEnd $FILE = GUICtrlCreateMenu("File") $NEW = GUICtrlCreateMenuItem("New", $FILE) $OPEN = GUICtrlCreateMenuItem("Open...", $FILE) $SAVE = GUICtrlCreateMenuItem("Save", $FILE) $SAVEAS = GUICtrlCreateMenuItem("Save As...", $FILE) $PRINT = GUICtrlCreateMenuItem("Print...", $FILE) GUICtrlCreateMenuItem("", $FILE) $EXIT = GUICtrlCreateMenuItem("Exit", $FILE) $EDIT = GUICtrlCreateMenu("Edit") $UNDO = GUICtrlCreateMenuItem("Undo", $EDIT) $REDO = GUICtrlCreateMenuItem("Redo", $EDIT) $SEPARATOR = GUICtrlCreateMenuItem("", $EDIT) $FONT = GUICtrlCreateMenuItem("Font test", $EDIT) $SEPARATOR1 = GUICtrlCreateMenuItem("", $EDIT) $CUT = GUICtrlCreateMenuItem("Cut", $EDIT) $COPY = GUICtrlCreateMenuItem("Copy", $EDIT) $PASTE = GUICtrlCreateMenuItem("Paste", $EDIT) GUISetState(@SW_SHOW & $GUI_ACCEPTFILES) While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) Exit EndIf If $SAVECHANGES = 7 Then ExitLoop Exit EndIf EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit Case $Msg = $OPEN $FILEOPEN = FileOpenDialog("Open", $FILEOPEN, $EXT) $TEXT = _GUICtrlRichEdit_StreamFromFile($EDITBOX, $FILEOPEN) _GUICtrlRichEdit_ReplaceText($EDITBOX, $TEXT) $FILEOPENED = 1 Case $Msg = $NEW If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) EndIf If $SAVECHANGES = 7 Then GUICtrlSetData($EDITBOX, "") If $SAVECHANGES = 2 Then Sleep(1) EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then GUICtrlSetData($EDITBOX, "") $FILEOPENED = 0 Case $Msg = $EXIT If _GUICtrlEdit_CanUndo($EDITBOX) Then $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?") If $SAVECHANGES = 6 And $FILEOPENED = 0 Then SaveAs() _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndIf If $SAVECHANGES = 6 And $FILEOPENED = 1 Then FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) Exit EndIf If $SAVECHANGES = 7 Then ExitLoop If $SAVECHANGES = 2 Then Sleep(1) EndIf EndIf If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit Case $Msg = $SAVEAS GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $SAVE And $FILEOPENED = 1 FileDelete($FILEOPEN) FileWrite($FILEOPEN, GUICtrlRead($EDITBOX)) _GUICtrlEdit_EmptyUndoBuffer($EDITBOX) Case $Msg = $SAVE And $FILEOPENED = 0 GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $SAVE And $FILEOPENED = 0 GUICtrlSetState($EDITBOX, $GUI_DISABLE) SaveAs() $FILEOPENED = 1 GUICtrlSetState($EDITBOX, $GUI_ENABLE) Case $Msg = $PRINT $PRINTMSGBOX = MsgBox(35, "Text Editor", "Are you sure you want to print this page?") Select Case $PRINTMSGBOX = 6 If FileExists("Print.txt") Then FileDelete("Print.txt") EndIf FileWrite("Print.txt", GUICtrlRead($EDITBOX)) $PRINTFILE = "Print.txt" _FilePrint($PRINTFILE) FileDelete($PRINTFILE) EndSelect Case $Msg = $UNDO _GUICtrlRichEdit_Undo($EDITBOX) Case $Msg = $REDO _GUICtrlRichEdit_Redo($EDITBOX) Case _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 1 GUICtrlSetState($SAVE, $GUI_ENABLE) Case $Msg = $CUT _GUICtrlRichEdit_Cut ($EDITBOX) Case $Msg = $COPY _GUICtrlRichEdit_Copy ($EDITBOX) Case $Msg = $PASTE _GUICtrlRichEdit_Paste ($EDITBOX) Case Not _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 0 GUICtrlSetState($SAVE, $GUI_DISABLE) $SAVES = 1 Case $Msg = $FONT _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, "Times New Roman") Case $FONTCOMBOBOX _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, GUICtrlRead($FONTCOMBOBOX)) EndSelect WEnd Exit Func SaveAs() $FILESAVEAS = FileSaveDialog("Save As", "", "Text Document (*.txt)|All Files (*.*)") If Not @error Then $STRING = StringSplit($FILESAVEAS, ".") If $STRING[0] = 1 Then FileDelete($FILESAVEAS) _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf") Else _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf") EndIf EndIf EndFunc Func _RegEnumVal($sKey) Local $i = 1, $sVal, $sResult While 1 $sVal = RegEnumVal($sKey, $i) If @error Then ExitLoop $i += 1 $sResult &= $sVal & "|" WEnd Return StringRegExpReplace($sResult, " \(.*?\)", "") EndFunc ;==>_RegEnumVal So the problem is that
      The second combo box is blank Icons in taskbar are not appearing (don't really care for now, .dll file for icon in attachement) problem with $FONTCOMBOBOX = GUICtrlCreateCombo("", 10, 10, 200, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL) (BitOR gave me a weird error)
      Thanks !
      Autoit newbie
      ico.dll
    • By Aelc
      Hey there!
      I'm gonna try to get access to an RichEdit Control in PSPad with Autoit which is scripted with Delphi. I wrote the commands out ouf the RichEdit.au3 UDF to can change them, because it always fails or crashs, when i call it. I Just want to set the Textcolor for the RichEdit.
      It seems to be a Problem with $EM_SETCHARFORMAT... (maybe protected?) I can use e.g. $EM_SETBKGNDCOLOR or other messages with no error. Sadly it doesn't exist a message constant to just set the textcolor... This is what i already tried:
      use $EM_GETCHARFORMAT but it crashs/doesn't work too. I saw the riched20.dll is linked to GDI+ but i couldn't make something work with it... (GetDc and so on but maybe there is another way?) Tried to set some other style on it (setWindowLong) I read the MSDN about $EM_SETCHARFORMAT up and down, but i can't find any other solution.
      The RichEdit should be version 2 ( error message point to riched20.dll )
       
      Here is the PSPad that will be required for testing:
      https://autoit.de/wcf/attachment/87712-pspad4autoit3-v1-0-0-beta-without-setup-zip/
      You need to start PSPad.exe first!
      ; = Info =========================================================================================== ; Title : RichEdit_Test ; -------------------------------------------------------------------------------------------------- ; ; Version (vnots) : 0.0.1 ; Date : 2020-05-13 ; Author(s) : Aelc ; ; ================================================================================================== #include <File.au3> #include <Misc.au3> #include <Date.au3> #include <String.au3> #include <GuiListBox.au3> #include <WinAPI.au3> #include <MsgBoxConstants.au3> #include <Color.au3> #include <GuiRichEdit.au3> #include <EditConstants.au3> AutoItSetOption("MustDeclareVars", 1) RichEdit_Test_Main() Func RichEdit_Test_Main() Local $hPSPad = Null Local $tLogCtrls Local $hLB_hwnd Local $hLB_ID $hPSPad = _WinAPI_GetForegroundWindow() If Not WinExists("[CLASS:TfPSPad]") Then MsgBox ( 48,"","PSPad not found." ) Exit EndIf Sleep(1000) $hPSPad = WinGetHandle("[CLASS:TfPSPad]") ;~ If $hPSPad = Null Then ;~ MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, 'AutoIt3_CompilerRunner: - Error -', 'No handle found for PSPad!') ;~ Exit (2) ; 2 = PSPad-hwnd not found ;~ EndIf If _WinAPI_IsClassName($hPSPad, "TfPSPad") Then ; -------------------------------------------------------------------------- If _Singleton("PSPad->RichEdit_Test " & String($hPSPad), 1) = 0 Then MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "RichEdit_Test: - Error -", _ '"RichEdit_Test" is already running') Exit EndIf ; -------------------------------------------------------------------------- $tLogCtrls = PSPad_GetLogControls($hPSPad, 'Log') $hLB_hwnd = $tLogCtrls.hWnd_ListBox $hLB_ID = $tLogCtrls.ID_ListBox If $hLB_hwnd > 0 Then _SendMessage($hLB_hwnd, 0xCF,False) ;Set $READONLY to False Local $tagCHARFORMAT_changeable = "struct;uint cbSize;long dwMask;long dwEffects;long yHeight;long yOffset;INT crTextColor;" & _ "byte bCharSet;byte bPitchAndFamily;wchar szFaceName[32];endstruct" Local $aColor[3] = [0xFF, 0x00, 0xFF] Local $nColor = _ColorSetCOLORREF($aColor) Local $tCharFormat = DllStructCreate($tagCHARFORMAT_changeable) DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat)) DllStructSetData($tCharFormat, 2, $CFM_COLOR) DllStructSetData($tCharFormat, 6, $nColor) MsgBox ( 64,"",_SendMessage($hLB_hwnd, $EM_SETCHARFORMAT, $SCF_SELECTION, $tCharFormat, 0, "wparam", "struct*")) Else ; Log-Fenster konnte nicht gefunden werden. MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "AutoIt3_CompilerRunner: - Error -", _ "The log window of PSPad could not be found.") Exit EndIf Else EndIf EndFunc ;==>RichEdit_Test_Main ;~ Func _RichEditGetTextLength($hWnd) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ Local $bChars = True ;~ Local $bExact = True ;~ Local $tGetTextLen = DllStructCreate($tagGETTEXTLENGTHEX) ;~ Local $iFlags = BitOR($GTL_USECRLF, ($bExact ? $GTL_PRECISE : $GTL_CLOSE)) ;~ $iFlags = BitOR($iFlags, ($bChars ? $GTL_DEFAULT : $GTL_NUMBYTES)) ;~ DllStructSetData($tGetTextLen, 1, $iFlags) ;~ DllStructSetData($tGetTextLen, 2, ($bChars ? $CP_ACP : $CP_UNICODE)) ;~ Local $iRet = _SendMessage($hWnd, $EM_GETTEXTLENGTHEX, $tGetTextLen, 0, 0, "struct*") ;~ Return $iRet ;~ EndFunc ;==>_RichEditGetTextLength ;~ Func _RichEditGetBKColor($hWnd) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ Local $iBkColor = _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, 0) ;~ _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, $iBkColor) ;~ Return $iBkColor ;~ EndFunc ;==>_RichEditGetBKColor ;~ Func _RichEditSetBKColor($hWnd, $iBkColor) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, $iBkColor) ;~ Return $iBkColor ;~ EndFunc ;==>_RichEditSetBKColor Func PSPad_GetLogControls($_hPSPad, $_sSheetText = 'Log') Local $sStruct_LogCtrls = _ 'hwnd hWnd_PageControl;' & _ ; TPageControl 'int ID_PageControl;' & _ 'hwnd hWnd_TabSheet;' & _ ; TTabSheet 'int ID_TabSheet;' & _ 'hwnd hWnd_ListBox;' & _ ; TListBox 'int ID_ListBox;' Local $tResult = DllStructCreate($sStruct_LogCtrls) Local $aEnum Local $sSheet Local $i, $x $aEnum = _WinAPI_EnumChildWindows($_hPSPad, False) If IsArray($aEnum) Then For $i = 1 To $aEnum[0][0] If $aEnum[$i][1] = "TTabSheet" Then $sSheet = ControlGetText($_hPSPad, '', _WinAPI_GetDlgCtrlID($aEnum[$i][0])) If $sSheet = $_sSheetText Then ; TabSheet gefunden. $tResult.hWnd_TabSheet = $aEnum[$i][0] $tResult.ID_TabSheet = _WinAPI_GetDlgCtrlID($tResult.hWnd_TabSheet) $tResult.hWnd_PageControl = _WinAPI_GetParent($tResult.hWnd_TabSheet) $tResult.ID_PageControl = _WinAPI_GetDlgCtrlID($tResult.hWnd_PageControl) For $x = $i + 1 To $aEnum[0][0] If $aEnum[$x][1] = "TRichEdit" Then $tResult.hWnd_ListBox = $aEnum[$x][0] $tResult.ID_ListBox = _WinAPI_GetDlgCtrlID($tResult.hWnd_ListBox) Return $tResult ; Wenn gefunden, dann raus aus der Funktion. EndIf Next EndIf EndIf Next EndIf Return $tResult EndFunc ;==>PSPad_GetLogControls I don't have any ideas anymore  But maybe someone else has?
      I would be happy for every idea  
       
      Thanks in advance
×
×
  • Create New...