Jump to content

Recommended Posts

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

  1. The second combo box is blank
  2. Icons in taskbar are not appearing (don't really care for now, .dll file for icon in attachement)
  3. 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

Link to post
Share on other sites

ComboBox is below the toolbar, either position it lower or place the GuiCtrlCreateCombo above the toolbar for example:

#include <ComboConstants.au3>

Global $g_hMainGui = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE)
Global $g_idFontNames = GUICtrlCreateCombo("", $WIDTH - 170, 10, 160, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL))
    GUICtrlSetData($g_idFontNames, _RegEnumVal($FONTKEY));ALSOHERE
Global $g_idFontSizes = GUICtrlCreateCombo("", $WIDTH - 200, 10, 20, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL))

Global $g_hToolBar = _GUICtrlToolbar_Create($g_hMainGui)
...

 

Link to post
Share on other sites
7 hours ago, Subz said:

ComboBox is below the toolbar, either position it lower or place the GuiCtrlCreateCombo above the toolbar for example:

#include <ComboConstants.au3>

Global $g_hMainGui = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE)
Global $g_idFontNames = GUICtrlCreateCombo("", $WIDTH - 170, 10, 160, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL))
    GUICtrlSetData($g_idFontNames, _RegEnumVal($FONTKEY));ALSOHERE
Global $g_idFontSizes = GUICtrlCreateCombo("", $WIDTH - 200, 10, 20, 20, Bitor($CBS_SORT,$CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_VSCROLL))

Global $g_hToolBar = _GUICtrlToolbar_Create($g_hMainGui)
...

 

For the combobox it worked but the BitOR also gave me an error

image.png.61841227a0db33f73a0ee55365bf1959.png

Also when  i tried to set the font using

_GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, GUICtrlRead($FONTCOMBOBOX))

it dosen't work because when i click on the combo box it deselect the text that i selected on my editbox.

again Thanks so much for your support

Link to post
Share on other sites
5 hours ago, AFrenchCroissant said:

BitOR also gave me an error

use #include <GuiConstants.au3> instead of #include <GuiConstantsEx.au3>

6 hours ago, AFrenchCroissant said:

it dosen't work because when i click on the combo box it deselect the text

Use style $ES_NOHIDESEL in rich edit creation.

Link to post
Share on other sites

sorry i don't really understand what's wrong, i searched for errors in the script but couldn't find some

The only thing i noticed was that when you click anything on the toolbar or on the menus everything flickers

here is the code:

#NoTrayIcon

#include <Misc.au3>
#include <GuiConstants.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
$FONTSIZECOMBOBOX = 18


$MAINGUI = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE)



 $EDITBOX = _GUICtrlRichEdit_Create($MAINGUI, "This is a test.", 10, 35, $WIDTH - 20, $HEIGHT - 70, _
                  BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_NOHIDESEL))
$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)

 $TOOLBAR = _GUICtrlToolbar_Create($MAINGUI)
 _GUIImageList_AddIcon($TOOLBAR, @SystemDir & "\shell.dll")
 $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)






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
;~          $CHECKFONT = GUICtrlRead($FONTCOMBOBOX)
;~          _GUICtrlRichEdit_SetFont($EDITBOX, $FONTSIZECOMBOBOX, "Times New Roman")

         Case $FONTCOMBOBOX
             $FONTTYPE = GUICtrlRead($FONTCOMBOBOX)
            _GUICtrlRichEdit_SetFont($EDITBOX, "12", $FONTTYPE)
    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

sorry again for bothering everyone

Link to post
Share on other sites
  • Solution

Yes it does flicker a lot.  But I do not have to courage to debug such a long script.  Here a small reproducer that shows it is working well.

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>

Const $sRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"

Local $hGUI = GUICreate("Test", 400, 300, 400, 400)

$cCombo_Font = GUICtrlCreateCombo("", 10, 10, 170, 20, BitOR($CBS_SORT, $CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL))
GUICtrlSetData($cCombo_Font, _RegEnumVal($sRegKey))

$cLabel = GUICtrlCreateLabel("Font preview", 230, 10, 155, 20)
$idRich = _GUICtrlRichEdit_Create($hGUI, "This is a test.  Long enough to be seen even if the combo is active.  Please select a part that you can see.", 10, 100, 380, 150, $ES_NOHIDESEL)

GUISetState()

While True
  $msg = GUIGetMsg()
  Switch $msg
    Case $GUI_EVENT_CLOSE
      Exit
    Case $cCombo_Font
      GUICtrlSetFont($cLabel, 10, Default, Default, GUICtrlRead($cCombo_Font))
      _GUICtrlRichEdit_SetFont($idRich, 10, 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

 

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 It_is_me_Me
      I am making some GUI with combobox for the Baudrates communications and I listed 9600, 57600, 115200. 
      I wrote the code to be defaulted to 57600 like this:
      GUICtrlSetData($comboBox_opticalBaudRate, "9600|57600|115200", "57600")
      But I wanted the GUI to remember the last item the user picks so the baudrates will NOT be defaulted to 57600.
      Example, I pick 9600 as my baudrates, then I close the GUI, after opening it, it always prompt 57600 since that is what I did in my code. But I want that if I choose 9600 and close the GUI, opening it again will show 9600 now instead of 57600.
      Is there a way to do it in GUI setting?
       
      Thanks.
    • By ute_man
      Hi Forum,
      I am struggling to select an IP address from "Server Interface" dropdown (ComboBox2) of tftpd32 client.
      tftpd32 is a TFTP server - TFTPD32 : an opensource IPv6 ready TFTP server/service for windows : TFTP server (pagesperso-orange.fr)
      The IP addresses (and the associated interfaces) are dynamic in ComboBox2.
      What I want to do is to select an item from ComboBox2 which contains a given IP address (eg. 192.168.2.1) - (which is hidden in the picture as it is at the bottom of the list) and fill the edit field with the selection. (Note : the ComboBox items contain the IP address and the Interface name, therefore IP address is just a part of the item)
      I am not sure whether functions such as _GUICtrlComboBox_SelectString() are only to be used with Autoit generated ComboBoxes.
      Please help !!!!
      My code below, it does not select the ComboBox2 item with my IP address 192.168.2.1.
      Local $hWnd=ControlGetHandle("Tftpd32 by Ph. Jounin", "", 4008) Sleep(100) ControlFocus("Tftpd32 by Ph. Jounin", "", $hWnd) Sleep(100) Local $IP = "192.168.2.1" _GUICtrlComboBox_SelectString($HWnd, $IP) ComboBox2 ID = 4008


    • 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
    • By MrCreatoR
      This UDF allows to create formatted label using pseudo element RichLabel (RichEdit actually). Formating is set by using special modificator similar to <font> tag in Html.
      Notes: This UDF is a transformation-continuation of related UDF


      Example:
      Download:
      GUIRichLabel_1.2.zip
      Small syntax related fix: GUIRichLabel_1.1.zip
      GUIRichLabel_1.1.zip
       
      History version:
    • By Colduction
      Hi, i have a source code of "Danny35d" and i have 2 main question that are:
       How to extract this function's results (Datas are as Array) to combo-box without set number of datas?  When i type 1, 2 in _SystemUsers($AccountType = 0) to get only Local or Domain users, it just give me both of them, it's old problem of this function, please share us debugged code :)❤ #include <Array.au3> $Users = _ArrayToString(_SystemUsers(), "|", 1) ConsoleWrite($Users & @CRLF) #cs =============================================================================== Function: _SystemUsers($AccountType = 0) Description: Return an array with the local or domain username Parameter(s): $AccountType: Local, domain or both username 0 = Local and Domain usernames 1 = Local usernames only 2 = Domain usernames only Returns: An array with the list of usernames - Succeeded @error 1 - Didn't query any username @error 2 - Failed to create Win32_SystemUsers object @error 3 - Invalid $AccountType Author(s): Danny35d #ce =============================================================================== Func _SystemUsers($AccountType = 0) Local $aSystemUsers Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20 Local $colItems = "", $strComputer = "localhost" If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '') $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $Output = StringSplit($objItem.PartComponent, ',') If IsArray($Output) Then $Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '') If $AccountType = 0 Or ($AccountType = 1 And @ComputerName = $Temp) Then $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|' ElseIf $AccountType = 2 And @ComputerName <> $Temp Then $aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|' EndIf EndIf Next $aSystemUsers = StringTrimRight($aSystemUsers, 1) If $aSystemUsers = '' Then Return(SetError(1, 1, $aSystemUsers)) Return(SetError(0, 0, StringSplit($aSystemUsers, '|'))) Else $aSystemUsers = '' Return(SetError(2, 2, $aSystemUsers)) EndIf EndFunc ;==>_SystemUsers Thanks to your best Team.
×
×
  • Create New...