Page 1 sur 1

[R] RichEdit s'affiche dans toutes mes Tab

Posté : ven. 20 mai 2016 20:07
par Flashneo
Bonjour,

Je rencontre un problème que je n'arrive pas à résoudre même en ayant chercher sur internet et dans la doc. Mon problème est que j'ai intégrer un RichEdit dans un Tabsheet et que quand je change de tabsheet mon RichEdit ne disparait pas, il s'affiche dans toutes mes Tab. Je pense que cela vient du faite qu'il s'intègre dans la gui, et pas dans le tab...

Merci d'avance pour votre aide, je commence a désespérer....

Re: [..] RichEdit s'affiche dans toutes mes Tab  

Posté : ven. 20 mai 2016 23:02
par mikell
C'est parce qu'avec RichEdit il y a une finesse : il faut activer/montrer et désactiver/masquer le controle au changement de tabitem
Voilà un exemple qui vient du forum US :

Code : Tout sélectionner

#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 20
    _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

Re: [..] RichEdit s'affiche dans toutes mes Tab

Posté : sam. 21 mai 2016 00:45
par Flashneo
Merci, j'ai pas compris la ligne avec Case 1, mais ça fonctionne c'est le plus important donc c'est pas grave

Re: [R] RichEdit s'affiche dans toutes mes Tab

Posté : sam. 21 mai 2016 11:39
par mikell
Sisisi, faut comprendre :mrgreen:

Code : Tout sélectionner

$iTab = _GUICtrlTab_GetCurSel($hTab)  ; retourne l'index base-0 du tab sélectionné
Switch $iTab
    Case 1  ; celui d'index 1 donc le 2ème (onglet "history" dans le code) où est le Richedit