Sign in to follow this  
Followers 0
themaskedwolf

[Solved] Richedit with window tabs

21 posts in this topic

#1 ·  Posted (edited)

hellow Melba23 been looking around and i know you hate looking at the richedit. but maybe since i'm still kinda fumbling my way through this you can help. Currently i'm trying to put a richeditor inside a tabbed window so that i can have multiple richedit boxes for text coloring inside one window. this is currently what i have. I have take a few of yours and other examples from the form here and have thrown this together quickly. and though i have seen a post of whether this is even possible i have not seen a defined answer for whether it can be done.

on a side note this is what i get on my screen a richedit box on top of the form. I have changed the _GUICtrlRichEdit_Create($Form1 to _GUICtrlRichEdit_Create($TabSheet1 and then i lose all visibility on the richedit so its either on top of the tabs and covers everything else or it seems to disappear all together. thanks in advance for any direction u can shoot me in =)

EDIT: DOh edited the wrong post =p

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Main", 400, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $idTab = GUICtrlCreateTab(2, 2, 396, 396)
        $hTab = GUICtrlGetHandle($idTab)
        $TabSheet1 = GUICtrlCreateTabItem("Main")
            $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ;~ ControlDisable($Form1, "", $hRichEdit)
            ;~ ControlHide($Form1, "", $hRichEdit)
            GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
        $TabSheet2 = GUICtrlCreateTabItem("History")
            GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ControlDisable($Form1, "", $historyrich)
            ControlHide($Form1, "", $historyrich)
        $TabSheet3 = GUICtrlCreateTabItem("blah")
            GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
            $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ControlDisable($Form1, "", $Tab3rich)
            ControlHide($Form1, "", $Tab3rich)
    GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

            For $i=1 to 30
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ASDF  fj aslfj skldjf lkdsjf jaskdjf lsjdfldsjflasldsjf llskjlg fsdfsdffdsdsfghjf lskjdf lskdjf lskdjflkjlg ashd")
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ABC",0x00FF00) ;green
                _GUICtrlRichEdit_WriteLine($historyrich,"ABC",0xFF0000) ;red
                _GUICtrlRichEdit_WriteLine($historyrich,"ABC",0xFFFF00) ;yellow
                _GUICtrlRichEdit_WriteLine($Tab3rich,"ABC",0x00FF00) ;green
                _GUICtrlRichEdit_WriteLine($Tab3rich,"ABC" ,0x00FFFF) ;light blue
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ABC" ,0x0000FF) ;BLUE
                _GUICtrlRichEdit_WriteLine($historyrich,"3333333333" ,0xFF00FF) ;Purple
            Next


while 1
    Sleep(1000)
WEnd


;~ While 1
;~     $nMsg = GUIGetMsg()
;~     Switch $nMsg
;~         Case $GUI_EVENT_CLOSE
;~             _GUICtrlRichEdit_Destroy($hRichEdit)
;~             Exit
;~     EndSwitch
;~ WEnd
Func CLOSEClicked()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    ; Count the @CRLFs
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $iLines = @extended
    ; Adjust the text char count to account for the @CRLFs
    Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines
    ; Add new text
    _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF)
    ; Select text between old and new end points
    _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1)
    ; Convert colour from RGB to BGR
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    ; Set colour
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    ; Clear selection
    _GUICtrlRichEdit_Deselect($hWnd)

EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ;window id
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") ;Control ID?
    $iCode = DllStructGetData($tNMHDR, "Code") ; TAB ID?
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $Tab1rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab1rich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $historyrich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $historyrich)   ;shows the richedit box for viewing
                        Case 2   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $Tab1rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab1rich)    ;hides the control from view
                            ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab3rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab3rich)   ;shows the richedit box for viewing
                        Case Else
;~                             ControlDisable($Form1, "", $hRichEdit) ;disables control for richedit
;~                             ControlHide($Form1, "", $hRichEdit)    ;hides the control from view
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by themaskedwolf

Share this post


Link to post
Share on other sites



You need _GUICtrlRichEdit_Destroy($historybox) just above your Exit to not get a crash when you exit the GUI.

:huh2:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Demo for handling WM_NOTIFY on TCN_SELCHANGE to make the RichEdit come and go as required:

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

$Form1 = GUICreate("Main", 400, 400)
$idTab = GUICtrlCreateTab(2, 2, 396, 396)
$hTab = GUICtrlGetHandle($idTab)
$TabSheet1 = GUICtrlCreateTabItem("Main")
GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
$TabSheet2 = GUICtrlCreateTabItem("History")
GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
$hRichEdit = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
For $n = 1 To 50
    _GUICtrlRichEdit_AppendText($hRichEdit, $n & ": Test a very long line of text in a RichEdit box." & @CRLF)
Next
ControlDisable($Form1, "", $hRichEdit)
ControlHide($Form1, "", $hRichEdit)
$TabSheet3 = GUICtrlCreateTabItem("blah")
GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE ; selection changed
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 1
                            ControlEnable($Form1, "", $hRichEdit)
                            ControlShow($Form1, "", $hRichEdit)
                        Case Else
                            ControlDisable($Form1, "", $hRichEdit)
                            ControlHide($Form1, "", $hRichEdit)
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

:huh2:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks for replyin ill have a thorogh look at this tomorrow. But at just a glance i see you are using a dll and such(which i have no exp in what so ever). And as i have never complied this script just run it via scite i would have never known that i woul of had to destroy it thx. Ill post back after i get to play with it

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

that is WICKED thanks so much. let me know if i'm correct in assuming this on the new function u added.

$hWndFrom = Window control id

$iIDFrom = Object control ID

$iTab = Tab Control ID$

$TCN_SELCHANGE = i'm assuming this just says the tab has changed. cause i get a value of -551 no matter what tab i got to using a MsgBox to check value. and i readded the color text input. =)

last thing i've been pondering is there a way to have it append lines to top. i was looking at where it appended them in the richedit.au3 and after looking a while it seems to select at end of file and i'm assuming again cause i'm getting over my head =)

here is what i got now. thanks to you again =).

Edited: added destroy and updated the other 2 tabs

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Main", 400, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $idTab = GUICtrlCreateTab(2, 2, 396, 396)
        $hTab = GUICtrlGetHandle($idTab)
        $TabSheet1 = GUICtrlCreateTabItem("Main")
            $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ;~ ControlDisable($Form1, "", $hRichEdit)
            ;~ ControlHide($Form1, "", $hRichEdit)
            GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
        $TabSheet2 = GUICtrlCreateTabItem("History")
            GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ControlDisable($Form1, "", $historyrich)
            ControlHide($Form1, "", $historyrich)
        $TabSheet3 = GUICtrlCreateTabItem("blah")
            GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
            $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ControlDisable($Form1, "", $Tab3rich)
            ControlHide($Form1, "", $Tab3rich)
    GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

            For $i=1 to 30
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ASDF  fj aslfj skldjf lkdsjf jaskdjf lsjdfldsjflasldsjf llskjlg fsdfsdffdsdsfghjf lskjdf lskdjf lskdjflkjlg ashd")
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ABC",0x00FF00) ;green
                _GUICtrlRichEdit_WriteLine($historyrich,"ABC",0xFF0000) ;red
                _GUICtrlRichEdit_WriteLine($historyrich,"ABC",0xFFFF00) ;yellow
                _GUICtrlRichEdit_WriteLine($Tab3rich,"ABC",0x00FF00) ;green
                _GUICtrlRichEdit_WriteLine($Tab3rich,"ABC" ,0x00FFFF) ;light blue
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ABC" ,0x0000FF) ;BLUE
                _GUICtrlRichEdit_WriteLine($historyrich,"3333333333" ,0xFF00FF) ;Purple
            Next


while 1
    Sleep(1000)
WEnd


;~ While 1
;~     $nMsg = GUIGetMsg()
;~     Switch $nMsg
;~         Case $GUI_EVENT_CLOSE
;~             _GUICtrlRichEdit_Destroy($hRichEdit)
;~             Exit
;~     EndSwitch
;~ WEnd
Func CLOSEClicked()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    ; Count the @CRLFs
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $iLines = @extended
    ; Adjust the text char count to account for the @CRLFs
    Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines
    ; Add new text
    _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF)
    ; Select text between old and new end points
    _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1)
    ; Convert colour from RGB to BGR
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    ; Set colour
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    ; Clear selection
    _GUICtrlRichEdit_Deselect($hWnd)

EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ;window id
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") ;Control ID?
    $iCode = DllStructGetData($tNMHDR, "Code") ; TAB ID?
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $Tab1rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab1rich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $historyrich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $historyrich)   ;shows the richedit box for viewing
                        Case 2   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $Tab1rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab1rich)    ;hides the control from view
                            ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab3rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab3rich)   ;shows the richedit box for viewing
                        Case Else
;~                             ControlDisable($Form1, "", $hRichEdit) ;disables control for richedit
;~                             ControlHide($Form1, "", $hRichEdit)    ;hides the control from view
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by themaskedwolf

Share this post


Link to post
Share on other sites

You forgot the _GUICtrlRichEdit_Destroy()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
    EndSwitch
WEnd

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

*facepalm* thx =) fixed the code and updated post =)

Edited by themaskedwolf

Share this post


Link to post
Share on other sites

not sure y but the scroll buttons on top and bottom of the initial tab is messed up they are not visible unless u change tabs or do something with the window.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Uhm...

I though the idea of creating all that text while the gui was shown was irritating... so i moved the @SW_Show... that fixed it i think...

Line 32 and 45

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Main", 400, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $idTab = GUICtrlCreateTab(2, 2, 396, 396)
        $hTab = GUICtrlGetHandle($idTab)
        $TabSheet1 = GUICtrlCreateTabItem("Main")
            $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ;~ ControlDisable($Form1, "", $hRichEdit)
            ;~ ControlHide($Form1, "", $hRichEdit)
            GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
        $TabSheet2 = GUICtrlCreateTabItem("History")
            GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ControlDisable($Form1, "", $historyrich)
            ControlHide($Form1, "", $historyrich)
        $TabSheet3 = GUICtrlCreateTabItem("blah")
            GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
            $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            ControlDisable($Form1, "", $Tab3rich)
            ControlHide($Form1, "", $Tab3rich)
    GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; GUISetState(@SW_SHOW); <======================= From here!

            For $i=1 to 30
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ASDF  fj aslfj skldjf lkdsjf jaskdjf lsjdfldsjflasldsjf llskjlg fsdfsdffdsdsfghjf lskjdf lskdjf lskdjflkjlg ashd")
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ABC",0x00FF00) ;green
                _GUICtrlRichEdit_WriteLine($historyrich,"ABC",0xFF0000) ;red
                _GUICtrlRichEdit_WriteLine($historyrich,"ABC",0xFFFF00) ;yellow
                _GUICtrlRichEdit_WriteLine($Tab3rich,"ABC",0x00FF00) ;green
                _GUICtrlRichEdit_WriteLine($Tab3rich,"ABC" ,0x00FFFF) ;light blue
                _GUICtrlRichEdit_WriteLine($Tab1rich,"ABC" ,0x0000FF) ;BLUE
                _GUICtrlRichEdit_WriteLine($historyrich,"3333333333" ,0xFF00FF) ;Purple
            Next

GUISetState(@SW_SHOW); <======================= Too here!

while 1
    Sleep(1000)
WEnd


;~ While 1
;~     $nMsg = GUIGetMsg()
;~     Switch $nMsg
;~         Case $GUI_EVENT_CLOSE
;~             _GUICtrlRichEdit_Destroy($hRichEdit)
;~             Exit
;~     EndSwitch
;~ WEnd
Func CLOSEClicked()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    ; Count the @CRLFs
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $iLines = @extended
    ; Adjust the text char count to account for the @CRLFs
    Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines
    ; Add new text
    _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF)
    ; Select text between old and new end points
    _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1)
    ; Convert colour from RGB to BGR
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    ; Set colour
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    ; Clear selection
    _GUICtrlRichEdit_Deselect($hWnd)

EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ;window id
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") ;Control ID?
    $iCode = DllStructGetData($tNMHDR, "Code") ; TAB ID?
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $Tab1rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab1rich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $historyrich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $historyrich)   ;shows the richedit box for viewing
                        Case 2   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $Tab1rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab1rich)    ;hides the control from view
                            ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab3rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab3rich)   ;shows the richedit box for viewing
                        Case Else
;~                             ControlDisable($Form1, "", $hRichEdit) ;disables control for richedit
;~                             ControlHide($Form1, "", $hRichEdit)    ;hides the control from view
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

let me know if i'm correct in assuming this on the new function u added.

$hWndFrom = Window control id

That's the handle of the control that sent the notification (the tab control).

$iIDFrom = Object control ID

Control ID of the same control as $hWndFrom.

$iTab = Tab Control ID$

Tab index (0-based) of the selected tab.

$TCN_SELCHANGE = i'm assuming this just says the tab has changed. cause i get a value of -551 no matter what tab i got to using a MsgBox to check value.

TCN_SELCHANGE is one of many tab control notifications.

and i readded the color text input.

Of course you want to customize your GUIs to your needs, but minimize irrelevant details like that when posting to the forum. You reduce the number of people willing to help by making them wade through meaningless customization to get to the "real" issue in the code.

last thing i've been pondering is there a way to have it append lines to top. i was looking at where it appended them in the richedit.au3 and after looking a while it seems to select at end of file and i'm assuming again cause i'm getting over my head =)

Append, by definition, means add to the end. You want to INSERT text by setting the insert point with _GUICtrlRichEdit_GotoCharPos() and then _GuiCtrlRichEdit_InsertText(), see help file.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Alright to show everyone the finished code here it is. I had a problem with the scroll bars acting up so i just showed them after i created the rich edit and that solved everything for some reason it was having trouble redrawing the rich edit when it goes from no scroll bar to showing one. if you changed tabs problem would solve itself, although just showing scroll bar from the start removed any need to change tabs which makes it a bit cleaner on the eyes although not on the code. =) so after cleaning up the code a bit and having it where it throws stuff into the box. also changing it to on-event so that if you are running other things instead of in loop it will still function. anyways thanks to all of you who have expanded my knowledge a bit more :)

PS thanks alot PSaltyDS

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

Opt("GUIOnEventMode", 1)


$Form1 = GUICreate("Main", 400, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    $idTab = GUICtrlCreateTab(2, 2, 396, 396)
        $hTab = GUICtrlGetHandle($idTab)
        $TabSheet1 = GUICtrlCreateTabItem("Main")
            $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($Tab1rich, $SB_VERT, True)

            GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
        $TabSheet2 = GUICtrlCreateTabItem("History")
            GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($historyrich, $SB_VERT, True)
            ControlDisable($Form1, "", $historyrich)
            ControlHide($Form1, "", $historyrich)
        $TabSheet3 = GUICtrlCreateTabItem("blah")
            GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
            $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($Tab3rich, $SB_VERT, True)
            ControlDisable($Form1, "", $Tab3rich)
            ControlHide($Form1, "", $Tab3rich)
    GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

            GUISetState(@SW_SHOW)
$count=0
while 1
    Sleep(150)
        _GUICtrlRichEdit_WriteLine($Tab1rich,$count&": "&"1234567890",0x0000FF) ;Purple
        _GUICtrlRichEdit_WriteLine($historyrich,$count&": "&"Tab 2 blkajlkjf  thiis is stupid",0x00FF00) ;Purple
        _GUICtrlRichEdit_WriteLine($Tab3rich,$count&": "&"tab 3 lkjl;kjsdlfjkljk ",0xFF0000) ;Purple
        $count+=1
        sleep(150)
        _GUICtrlRichEdit_WriteLine($Tab1rich,$count&": "&"lkjl;ksjdflkjsdljsadflkjlkj long textljklkjl;kjl;jkkll;j;ljkl;j lkas oiq aopz oi oaiu ioidfu a oiuweajlkj o iw nklasjdfiow",0xFF00FF) ;Purple
        _GUICtrlRichEdit_WriteLine($historyrich,$count&": "&"3woiuabdfsdoalkj asd fdsaljkfl;asd",0xFF00FF) ;Purple
        _GUICtrlRichEdit_WriteLine($Tab3rich,$count&": "&"alkjl;k alkjdfa oiwjab lma sdaf oqn alsdjfl",0x0000FF) ;RED
        $count+=1
WEnd


Func CLOSEClicked()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc

;this function just adds color =)
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $icharcount=stringlen($sText)
    _GUICtrlRichEdit_GotoCharPos($hWnd,0)
    _GUICtrlRichEdit_InsertText($hWnd,$sText&@CRLF)
    _GuiCtrlRichEdit_SetSel($hWnd, 0, $icharcount)
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GUICtrlRichEdit_Deselect($hWnd)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ;second  tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $Tab3rich)
                            ControlHide($Form1, "", $Tab3rich)
                           ControlEnable($Form1, "", $historyrich)
                            ControlShow($Form1, "", $historyrich)
                        Case 2   ;third tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $historyrich)
                            ControlHide($Form1, "", $historyrich)
                           ControlEnable($Form1, "", $Tab3rich)
                            ControlShow($Form1, "", $Tab3rich)
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by themaskedwolf

Share this post


Link to post
Share on other sites

Can i ask why you would write in the RichEdit while the user can see it ?

Wouldnt it be better if you finished up everything before showing it to the user ?


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

well i was thinking this will be alot nicer for debugging programs as i can pause and see exactly what is happening. still have to make this like splashtext window. the only reason i was using richedit was cause i can have the color of text. so it will run all default messages in black and when there hits a error or what not it will pop up in red. now i may have gone about and done this a completely complicated way but for some reason i usually do =) so basicly its only so so. working on it now to currently to get it to be like splash window where it is always on top and will not shift focus from another window =)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Ah, got ya!

I belive its $sw_foremost or something like that, look in the style list

Edit, it was $WS_EX_TOPMOST

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

yeah that keeps it on top although for some reason focus keeps shifting back to the window. if i could i would like to make it even if u clicked on the window it wont become active. kinda like a splashtext just cant seem to find the right combination of styles i ssuppose i'll keep working at it

EDIT: here is the code if u run it into a function and then throw text from the function the first time u change windows say to notepad or what not it will shift the active window back to Form1. any other time it seems fine. only the first change seems to cause something.

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

Opt("GUIOnEventMode", 1)


$Form1 = GUICreate("Main", 400, 400,100,100,$GUI_SS_DEFAULT_GUI ,$WS_EX_WINDOWEDGE+$WS_EX_TOPMOST)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
    $idTab = GUICtrlCreateTab(2, 2, 396, 396)
        $hTab = GUICtrlGetHandle($idTab)
        $TabSheet1 = GUICtrlCreateTabItem("Main")
            $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($Tab1rich, $SB_VERT, True)

            GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
        $TabSheet2 = GUICtrlCreateTabItem("History")
            GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($historyrich, $SB_VERT, True)
            ControlDisable($Form1, "", $historyrich)
            ControlHide($Form1, "", $historyrich)
        $TabSheet3 = GUICtrlCreateTabItem("blah")
            GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
            $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($Tab3rich, $SB_VERT, True)
            ControlDisable($Form1, "", $Tab3rich)
            ControlHide($Form1, "", $Tab3rich)
    GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

            GUISetState(@SW_SHOW)

Main()


Func Main()
    local $count=0
    while 1
        Sleep(1000)
            _GUICtrlRichEdit_WriteLine($Tab1rich,$count&": "&"1234567890",0x0000FF)
            _GUICtrlRichEdit_WriteLine($historyrich,$count&": "&"Tab 2 blkajlkjf  thiis is stupid",0x00FF00)
            _GUICtrlRichEdit_WriteLine($Tab3rich,$count&": "&"tab 3 lkjl;kjsdlfjkljk ",0xFF0000)
            sleep(5000)
            _GUICtrlRichEdit_WriteLine($Tab1rich,$count&": "&"lkjl;ksjdflkjsdljsadflkjlkj long textljklkjl;kjl;jkkll;j;ljkl;j lkas oiq aopz oi oaiu ioidfu a oiuweajlkj o iw nklasjdfiow",0xFF00FF) ;Purple
            _GUICtrlRichEdit_WriteLine($historyrich,$count&": "&"3woiuabdfsdoalkj asd fdsaljkfl;asd",0xFF00FF)
            _GUICtrlRichEdit_WriteLine($Tab3rich,$count&": "&"alkjl;k alkjdfa oiwjab lma sdaf oqn alsdjfl",0x0000FF)
            $count+=1
    WEnd
EndFunc

Func Terminate()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc

;this function just adds color =)
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $icharcount=stringlen($sText)
    _GUICtrlRichEdit_GotoCharPos($hWnd,0)
    _GUICtrlRichEdit_InsertText($hWnd,$sText&@CRLF)
    _GuiCtrlRichEdit_SetSel($hWnd, 0, $icharcount)
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GUICtrlRichEdit_Deselect($hWnd)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ;second  tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $Tab3rich)
                            ControlHide($Form1, "", $Tab3rich)
                           ControlEnable($Form1, "", $historyrich)
                            ControlShow($Form1, "", $historyrich)
                        Case 2   ;third tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $historyrich)
                            ControlHide($Form1, "", $historyrich)
                           ControlEnable($Form1, "", $Tab3rich)
                            ControlShow($Form1, "", $Tab3rich)
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by themaskedwolf

Share this post


Link to post
Share on other sites

So you want it to just stay on the screen, but not be active ?


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

So you want it to just stay on the screen, but not be active ?

that is correct. have the window always ontop yet not at focus. right now i have it where it is unresizeable as the richedit boxes doesnt resize with dockauto. but first thing is first still working on this to keep it from stealing focus back from any other window. and the odd thing is it only does it once. never again unless u close and restart it. its a gremlin that will probly drive me crazy :)

Share this post


Link to post
Share on other sites

Something i made to fix it.

Worked, then it didnt work, then it worked without the code... :)

Idk, if it works but you can try it atleast.

also you could get the active window, then run the code to start it, then force the previous active window to become active again!

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Main", 400, 400,100,100,$GUI_SS_DEFAULT_GUI ,$WS_EX_WINDOWEDGE+$WS_EX_TOPMOST)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
    $idTab = GUICtrlCreateTab(2, 2, 396, 396)
        $hTab = GUICtrlGetHandle($idTab)
        $TabSheet1 = GUICtrlCreateTabItem("Main")
            $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($Tab1rich, $SB_VERT, True)

            GUICtrlCreateLabel("Main tab 0...", 20, 50, 360, 20)
        $TabSheet2 = GUICtrlCreateTabItem("History")
            GUICtrlCreateLabel("History tab 1...", 20, 50, 360, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($historyrich, $SB_VERT, True)
            ControlDisable($Form1, "", $historyrich)
            ControlHide($Form1, "", $historyrich)
        $TabSheet3 = GUICtrlCreateTabItem("blah")
            GUICtrlCreateLabel("blah tab 2...", 20, 50, 360, 20)
            $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, 360, 200, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            _GUIScrollBars_ShowScrollBar($Tab3rich, $SB_VERT, True)
            ControlDisable($Form1, "", $Tab3rich)
            ControlHide($Form1, "", $Tab3rich)
    GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

            GUISetState(@SW_SHOW)

Clicker();====================== HERE!!!!!!!!!

Main()


Func Main()
    local $count=0
    while 1
        Sleep(1000)
            _GUICtrlRichEdit_WriteLine($Tab1rich,$count&": "&"1234567890",0x0000FF)
            _GUICtrlRichEdit_WriteLine($historyrich,$count&": "&"Tab 2 blkajlkjf  thiis is stupid",0x00FF00)
            _GUICtrlRichEdit_WriteLine($Tab3rich,$count&": "&"tab 3 lkjl;kjsdlfjkljk ",0xFF0000)
            sleep(5000)
            _GUICtrlRichEdit_WriteLine($Tab1rich,$count&": "&"lkjl;ksjdflkjsdljsadflkjlkj long textljklkjl;kjl;jkkll;j;ljkl;j lkas oiq aopz oi oaiu ioidfu a oiuweajlkj o iw nklasjdfiow",0xFF00FF) ;Purple
            _GUICtrlRichEdit_WriteLine($historyrich,$count&": "&"3woiuabdfsdoalkj asd fdsaljkfl;asd",0xFF00FF)
            _GUICtrlRichEdit_WriteLine($Tab3rich,$count&": "&"alkjl;k alkjdfa oiwjab lma sdaf oqn alsdjfl",0x0000FF)
            $count+=1
    WEnd
EndFunc

Func Clicker();====================== AND HERE!!!!!!!!!
    $MousePos = MouseGetPos()
    Opt("MouseCoordMode", 0)
    MouseClick("primary",30,10,0)
    Opt("MouseCoordMode", 1)
    MouseMove($MousePos[0],$MousePos[1],0)
EndFunc


Func Terminate()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc

;this function just adds color =)
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $icharcount=stringlen($sText)
    _GUICtrlRichEdit_GotoCharPos($hWnd,0)
    _GUICtrlRichEdit_InsertText($hWnd,$sText&@CRLF)
    _GuiCtrlRichEdit_SetSel($hWnd, 0, $icharcount)
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GUICtrlRichEdit_Deselect($hWnd)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ;second  tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $Tab3rich)
                            ControlHide($Form1, "", $Tab3rich)
                           ControlEnable($Form1, "", $historyrich)
                            ControlShow($Form1, "", $historyrich)
                        Case 2   ;third tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $historyrich)
                            ControlHide($Form1, "", $historyrich)
                           ControlEnable($Form1, "", $Tab3rich)
                            ControlShow($Form1, "", $Tab3rich)
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

I fiddled, a bit to much, so i had to reverse what i did :)

But anyhow, this will open the script, then shift the focus back on the window that had the focus!

I marked out the important stuff with big arrow thingies <=== ;)

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

Opt("GUIOnEventMode", 1)

Global $Focus = _ControlGetHovered(), $FocusCount, $count=0, $Number;<================ The focus varaible

$TrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
$TrayHeight = _WinAPI_GetWindowHeight($TrayWnd)

Global $GuiHeight = 500, $GuiWidth = 131
Global $GuiXPos = (@DesktopHeight-$GuiHeight-($TrayHeight*1.75))
Global $GuiYPos = (@DesktopWidth-$GuiWidth-10)
Global $REWidth = $GuiWidth - 35
Global $REHeight = ($GuiHeight - 100)

$Form1 = GUICreate("", $GuiWidth, $GuiHeight,$GuiYPos ,$GuiXPos,-1 ,$WS_EX_WINDOWEDGE+$WS_EX_TOPMOST)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")
    $idTab = GUICtrlCreateTab(2, 2,$GuiWidth, $GuiHeight )
        $hTab = GUICtrlGetHandle($idTab)

        ;Tab 1
        $TabSheet1 = GUICtrlCreateTabItem("Tab 1")
        $TabLabel1 = GUICtrlCreateLabel("Tab 1", 20, 50, $REWidth, 20)
                $Tab1rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, $REWidth, $REHeight, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
                    _GUIScrollBars_ShowScrollBar($Tab1rich, $SB_VERT, True)

        ;Tab 2
        $TabSheet2 = GUICtrlCreateTabItem("Tab 2")
        $TabLabel2 = GUICtrlCreateLabel("Tab 2", 20, 50, $REWidth, 20)
            $historyrich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, $REWidth, $REHeight, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
                _GUIScrollBars_ShowScrollBar($historyrich, $SB_VERT, True)
                    ControlDisable($Form1, "", $historyrich)
                        ControlHide($Form1, "", $historyrich)
        ;Tab 3
        $TabSheet3 = GUICtrlCreateTabItem("Tab 3")
        $TabLabel3 = GUICtrlCreateLabel("Tab 3", 20, 50, $REWidth, 20)
                $Tab3rich = _GUICtrlRichEdit_Create($Form1, "", 20, 80, $REWidth, $REHeight, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
                    _GUIScrollBars_ShowScrollBar($Tab3rich, $SB_VERT, True)
                        ControlDisable($Form1, "", $Tab3rich)
                            ControlHide($Form1, "", $Tab3rich)

 GUICtrlCreateTabItem("")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState(@SW_SHOW)


While 1
    If $FocusCount = 0 then Focuser();<================This counter
    Main()
WEnd

Func Main()
        Sleep(50)
        $Number = Round(Random(1,9999))
        If $Number <= 2000 then
            _GUICtrlRichEdit_WriteLine($Tab1rich,$Number,0x00CCFF)
        ElseIf $Number >= 8000 then
            _GUICtrlRichEdit_WriteLine($Tab1rich,$Number,0xFF0000)
        Else
            _GUICtrlRichEdit_WriteLine($Tab1rich,$Number,0x000000)
        EndIf
        GuiCtrlSetData($TabLabel1,$Number)

        Sleep(50)
        $Number = Round(Random(1,9999))
        If $Number <= 2000 then
            _GUICtrlRichEdit_WriteLine($historyrich,$Number,0x00CCFF)
        ElseIf $Number >= 8000 then
            _GUICtrlRichEdit_WriteLine($historyrich,$Number,0xFF0000)
        Else
            _GUICtrlRichEdit_WriteLine($historyrich,$Number,0x000000)
        EndIf
        GuiCtrlSetData($TabLabel2,$Number)

        Sleep(50)
        $Number = Round(Random(1,9999))
        If $Number <= 2000 then
            _GUICtrlRichEdit_WriteLine($Tab3rich,$Number,0x00CCFF)
        ElseIf $Number >= 8000 then
            _GUICtrlRichEdit_WriteLine($Tab3rich,$Number,0xFF0000)
        Else
            _GUICtrlRichEdit_WriteLine($Tab3rich,$Number,0x000000)
        EndIf
        GuiCtrlSetData($TabLabel3,$Number)

        $count+=1
EndFunc

Func Focuser();<================ This function
    WinActivate($Focus)
    $FocusCount += 1
EndFunc

Func _ControlGetHovered();<================ And this function
    Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If Not IsArray($aRet) Then Return SetError(1, 0, 0)
    Return HWnd($aRet[0])
EndFunc

Func Terminate()
    ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
    ;and @GUI_WINHANDLE would equal $mainwindow
    _GUICtrlRichEdit_Destroy($Tab1rich)
    _GUICtrlRichEdit_Destroy($historyrich)
    _GUICtrlRichEdit_Destroy($Tab3rich)
    Exit
EndFunc

;this function just adds color =)
Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iColor = 0) ;
    StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "")
    Local $icharcount=stringlen($sText)
    _GUICtrlRichEdit_GotoCharPos($hWnd,0)
    _GUICtrlRichEdit_InsertText($hWnd,$sText&@CRLF)
    _GuiCtrlRichEdit_SetSel($hWnd, 0, $icharcount)
    $iColor = Hex($iColor, 6)
    $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2)
    _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GUICtrlRichEdit_Deselect($hWnd)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $iTab
    $hWndTab = $hTab

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $TCN_SELCHANGE
                    $iTab = _GUICtrlTab_GetCurSel($hTab)
                    Switch $iTab
                        Case 0   ; First tab     1 would be second tab  2 would be third tab ect....
                             ControlDisable($Form1, "", $historyrich) ;disables control for richedit
                            ControlHide($Form1, "", $historyrich)    ;hides the control from view
                            ControlDisable($Form1, "", $Tab3rich) ;disables control for richedit
                            ControlHide($Form1, "", $Tab3rich)    ;hides the control from view
                           ControlEnable($Form1, "", $Tab1rich)  ;Enable rich edit for showing
                            ControlShow($Form1, "", $Tab1rich)   ;shows the richedit box for viewing
                        Case 1  ;second  tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $Tab3rich)
                            ControlHide($Form1, "", $Tab3rich)
                           ControlEnable($Form1, "", $historyrich)
                            ControlShow($Form1, "", $historyrich)
                        Case 2   ;third tab
                             ControlDisable($Form1, "", $Tab1rich)
                            ControlHide($Form1, "", $Tab1rich)
                            ControlDisable($Form1, "", $historyrich)
                            ControlHide($Form1, "", $historyrich)
                           ControlEnable($Form1, "", $Tab3rich)
                            ControlShow($Form1, "", $Tab3rich)
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Very nice! i would have never thought of it like that as my dll knowledge is very limited.(will have to figure those out one day) that that has solved the problem all together. still kinda odd on it swapping though was kind wondering if it was a bug of some sort. Thanks again to all of those that help and Maffe811 thanks for sticking around to the end helping me =)

Share this post


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
Sign in to follow this  
Followers 0