找回密码
 加入
搜索
查看: 3855|回复: 7

[GUI管理] Tab上用富文本的问题[已解决]

  [复制链接]
发表于 2011-4-24 18:56:21 | 显示全部楼层 |阅读模式
本帖最后由 AUFS 于 2011-4-24 20:26 编辑

在tab上用富文本控件,转页的时候还是在上面..把所有页面都给穿透了,,怎么解决呢?
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Global $hRichEdit, $mnu, $mnuUndo, $mnuRedo, $mnuCut, $mnuCopy
Global $mnuPaste, $mnuPasteSpl, $mnuPasteSplRTF, $mnuPasteSplwObjs

$Form2 = GUICreate("窗体1", 342, 197, 353, 251)
$Tab1 = GUICtrlCreateTab(0, 0, 337, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button1", 24, 40, 75, 25)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
GUICtrlSetState(-1,$GUI_SHOW)
$hRichEdit = _GUICtrlRichEdit_Create($Form2, "This is a test.", 8, 32, 321, 137)
;$hRichEdit = GUICtrlCreateEdit("", 8, 32, 321, 137)
;GUICtrlSetData(-1, "Edit1")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)



        ;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

        $mnu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
        $mnuUndo = GUICtrlCreateMenuItem("Undo", $mnu)
        $mnuRedo = GUICtrlCreateMenuItem("Redo", $mnu)
        GUICtrlCreateMenuItem("", $mnu)
        $mnuCut = GUICtrlCreateMenuItem("Cut", $mnu)
        $mnuCopy = GUICtrlCreateMenuItem("Copy", $mnu)
        $mnuPaste = GUICtrlCreateMenuItem("Paste", $mnu)
        $mnuPasteSpl = GUICtrlCreateMenu("Paste Special", $mnu)
        $mnuPasteSplRTF = GUICtrlCreateMenuItem("RTF only", $mnuPasteSpl)
        $mnuPasteSplwObjs = GUICtrlCreateMenuItem("With objects", $mnuPasteSpl)
        _GuiCtrlRichEdit_SetEventMask($hRichEdit, $ENM_MOUSEEVENTS)
        
        
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        GUIDelete()
                        Exit
                Case $TabSheet1
                        MsgBox(64,'提示','提示')
        EndSwitch
WEnd



Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
        #forceref $iMsg, $iWparam
        Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
        $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case $hRichEdit
                        Select
                                Case $iCode = $EN_MSGFILTER
                                        $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $iLparam)
                                        If DllStructGetData($tMsgFilter, "msg") = $WM_RBUTTONUP Then
                                                $hMenu = GUICtrlGetHandle($mnu)
                                                _SetMenuTexts($hWndFrom, $hMenu)
                                                _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                                        EndIf
                        EndSelect
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _SetMenuTexts($hWnd, $hMenu)
        Local $fState
        If _GUICtrlRichEdit_CanUndo($hWnd) Then
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuUndo, True, False)
                _GUICtrlMenu_SetItemText($hMenu, $mnuUndo, "Undo: " & _GUICtrlRichEdit_GetNextUndo($hWnd), False)
        Else
                _GUICtrlMenu_SetItemText($hMenu, $mnuUndo, "Undo", False)
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuUndo, False, False)
        EndIf
        If _GUICtrlRichEdit_CanRedo($hWnd) Then
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuRedo, True, False)
                _GUICtrlMenu_SetItemText($hMenu, $mnuRedo, "Redo: " & _GUICtrlRichEdit_GetNextRedo($hWnd), False)
        Else
                _GUICtrlMenu_SetItemText($hMenu, $mnuRedo, "Redo", False)
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuRedo, False, False)
        EndIf
        $fState = _GuiCtrlRichEdit_IsTextSelected($hWnd)
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuCut, $fState, False)
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuCopy, $fState, False)

        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuPaste, _GUICtrlRichEdit_CanPaste($hWnd))

        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuPasteSpl, _GUICtrlRichEdit_CanPasteSpecial($hWnd), False)
EndFunc   ;==>_SetMenuTexts

Func ReadBmpToRtf($sBmpFilspc)
        Local $hFile, $sRtf
        $hFile = FileOpen($sBmpFilspc, 16)
        If FileRead($hFile, 2) <> "0x424D" Then Return SetError(1, 0, "")
        FileRead($hFile, 12)
        $sRtf = '{\rtf1{\pict\dibitmap ' & Hex(FileRead($hFile)) & '}}'
        FileClose($hFile)
        Return $sRtf
EndFunc   ;==>ReadBmpToRtf

Func FindFirstBMP($sPath = @WindowsDir)
        Local $hFind, $sBmpFilspc
        $hFind = FileFindFirstFile($sPath & "\*.bmp")
        $sBmpFilspc = FileFindNextFile($hFind)
        FileClose($hFind)
        Return $sPath & "" & $sBmpFilspc
EndFunc   ;==>FindFirstBMP
发表于 2011-4-24 19:22:03 | 显示全部楼层
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
$Form2 = GUICreate("窗体1", 342, 197, 353, 251)
$Tab1 = GUICtrlCreateTab(0, 0, 337, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button1", 24, 40, 75, 25)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$hRichEdit = GUICtrlCreateEdit("", 8, 32, 321, 137)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                                        GUIDelete()
                                        Exit
                Case 5
                                        MsgBox(64,'提示','提示')
        EndSwitch
WEnd
 楼主| 发表于 2011-4-24 19:37:01 | 显示全部楼层
其实我是想在TAB页里实现这样的功能..右键功能...
如果用普通的EDIT的话不行....
#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>

Global $hRichEdit, $mnu, $mnuUndo, $mnuRedo, $mnuCut, $mnuCopy
Global $mnuPaste, $mnuPasteSpl, $mnuPasteSplRTF, $mnuPasteSplwObjs

Main()

Func Main()
        Local $hGui
        $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName,4) &")", 320, 350, -1, -1)
        $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
        GUISetState(@SW_SHOW)

        ;_GUICtrlRichEdit_AppendText($hRichEdit, ReadBmpToRtf(FindFirstBMP()) & @CR)

        GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

        $mnu = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
        $mnuUndo = GUICtrlCreateMenuItem("Undo", $mnu)
        $mnuRedo = GUICtrlCreateMenuItem("Redo", $mnu)
        GUICtrlCreateMenuItem("", $mnu)
        $mnuCut = GUICtrlCreateMenuItem("Cut", $mnu)
        $mnuCopy = GUICtrlCreateMenuItem("Copy", $mnu)
        $mnuPaste = GUICtrlCreateMenuItem("Paste", $mnu)
        $mnuPasteSpl = GUICtrlCreateMenu("Paste Special", $mnu)
        $mnuPasteSplRTF = GUICtrlCreateMenuItem("RTF only", $mnuPasteSpl)
        $mnuPasteSplwObjs = GUICtrlCreateMenuItem("With objects", $mnuPasteSpl)
        _GuiCtrlRichEdit_SetEventMask($hRichEdit, $ENM_MOUSEEVENTS)

        While True
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                GUIDelete()
                                Exit
                        Case $mnuUndo
                                _GuiCtrlRichEdit_Undo($hRichEdit)
                        Case $mnuRedo
                                _GuiCtrlRichEdit_Redo($hRichEdit)
                        Case $mnuCut
                                _GuiCtrlRichEdit_Cut($hRichEdit)
                        Case $mnuCopy
                                _GuiCtrlRichEdit_Copy($hRichEdit)
                        Case $mnuPaste
                                _GuiCtrlRichEdit_Paste($hRichEdit)
                        Case $mnuPasteSplRTF
                                _GuiCtrlRichEdit_PasteSpecial($hRichEdit, False)
                        Case $mnuPasteSplwObjs
                                _GuiCtrlRichEdit_PasteSpecial($hRichEdit, True)
                EndSwitch
        WEnd
EndFunc   ;==>Main

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
        #forceref $iMsg, $iWparam
        Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu
        $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case $hRichEdit
                        Select
                                Case $iCode = $EN_MSGFILTER
                                        $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $iLparam)
                                        If DllStructGetData($tMsgFilter, "msg") = $WM_RBUTTONUP Then
                                                $hMenu = GUICtrlGetHandle($mnu)
                                                _SetMenuTexts($hWndFrom, $hMenu)
                                                _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd)
                                        EndIf
                        EndSelect
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _SetMenuTexts($hWnd, $hMenu)
        Local $fState
        If _GUICtrlRichEdit_CanUndo($hWnd) Then
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuUndo, True, False)
                _GUICtrlMenu_SetItemText($hMenu, $mnuUndo, "Undo: " & _GUICtrlRichEdit_GetNextUndo($hWnd), False)
        Else
                _GUICtrlMenu_SetItemText($hMenu, $mnuUndo, "Undo", False)
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuUndo, False, False)
        EndIf
        If _GUICtrlRichEdit_CanRedo($hWnd) Then
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuRedo, True, False)
                _GUICtrlMenu_SetItemText($hMenu, $mnuRedo, "Redo: " & _GUICtrlRichEdit_GetNextRedo($hWnd), False)
        Else
                _GUICtrlMenu_SetItemText($hMenu, $mnuRedo, "Redo", False)
                _GUICtrlMenu_SetItemEnabled($hMenu, $mnuRedo, False, False)
        EndIf
        $fState = _GuiCtrlRichEdit_IsTextSelected($hWnd)
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuCut, $fState, False)
        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuCopy, $fState, False)

        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuPaste, _GUICtrlRichEdit_CanPaste($hWnd))

        _GUICtrlMenu_SetItemEnabled($hMenu, $mnuPasteSpl, _GUICtrlRichEdit_CanPasteSpecial($hWnd), False)
EndFunc   ;==>_SetMenuTexts

Func ReadBmpToRtf($sBmpFilspc)
        Local $hFile, $sRtf
        $hFile = FileOpen($sBmpFilspc, 16)
        If FileRead($hFile, 2) <> "0x424D" Then Return SetError(1, 0, "")
        FileRead($hFile, 12)
        $sRtf = '{\rtf1{\pict\dibitmap ' & Hex(FileRead($hFile)) & '}}'
        FileClose($hFile)
        Return $sRtf
EndFunc   ;==>ReadBmpToRtf

Func FindFirstBMP($sPath = @WindowsDir)
        Local $hFind, $sBmpFilspc
        $hFind = FileFindFirstFile($sPath & "\*.bmp")
        $sBmpFilspc = FileFindNextFile($hFind)
        FileClose($hFind)
        Return $sPath & "" & $sBmpFilspc
EndFunc   ;==>FindFirstBMP
发表于 2011-4-24 20:23:30 | 显示全部楼层
用牛人的一句话来说就是
善于搜索
http://www.autoitx.com/forum.php ... hlight=%D3%D2%BC%FC
 楼主| 发表于 2011-4-24 20:26:06 | 显示全部楼层
这个我是搜索到并在用的了...现在只是想知道富文本的这个能不能在TAB上解决这个问题....不过都谢谢老大的热心,,结贴了...
发表于 2011-4-24 20:53:52 | 显示全部楼层
回复 5# AUFS


    我之前测试过的
在 Tab上没问题
发表于 2011-4-27 16:22:11 | 显示全部楼层
good example.thanks!!!!!!!
发表于 2012-10-2 09:02:01 | 显示全部楼层
收藏 备用 收藏 备用
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-18 16:26 , Processed in 0.076514 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表