VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

請教VFP中使用Rich TextBox Control 如何才能有Redo; Undo功能

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
小賴



註冊時間: 2004-12-27
文章: 470


第 1 樓

發表發表於: 星期日 七月 02, 2006 2:16 pm    文章主題: 請教VFP中使用Rich TextBox Control 如何才能有Redo; Undo功能 引言回覆

VFP FORM 中加入Rich TextBox Control 我看 WordPad 有提供Undo功能
不知Rich TextBox 要如何才能有此功能 ?
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
garfield
Site Admin


註冊時間: 2003-01-30
文章: 2157


第 2 樓

發表發表於: 星期一 七月 03, 2006 2:56 pm    文章主題: 引言回覆

按滑鼠右鍵有看到 past , copy , undo, redo
_________________
利用>>搜尋<<的功能會比問的還要快得到答案.
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
小賴



註冊時間: 2004-12-27
文章: 470


第 3 樓

發表發表於: 星期一 七月 03, 2006 4:42 pm    文章主題: 引言回覆

TO Garfield 兄
您果然得到沈富雄委員真傳, 我得先猜猜您的意思 :
1. Rich TextBox 已提供Redo, Undo功能於ShortCou Menu
2. 大哥要小賴自訂ShortCut Menu
3. 大哥怪小賴不搜尋; 所以在玩小賴 ?


小賴的回覆:
1. Rich TextBox 沒提供Redo, Undo功能於ShortCou Menu
(連RightClick Event 也沒有) 我RightClick半天也不見有
Redo, Undo功能

2. ShortCut Menu 小賴早作了(圖一), 用於VFP EditBox都沒問題(圖三)
可是用於 Rich TextBox 卻不鳥我(圖四)

3. 其實我要作的功能不是ShortCut Menu而是要替我的Rich TextBox
作一Toolbar(如圖四)

4. 順便再請教一個問題, 如果不是Rich TextBox, 而是VFP的EditBox
要使用Toolbar作Redo, Undo功能可行嗎 ? (EditBox 一失去焦點, Redo,
Undo功能都破功了)
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
garfield
Site Admin


註冊時間: 2003-01-30
文章: 2157


第 4 樓

發表發表於: 星期一 七月 03, 2006 6:05 pm    文章主題: 引言回覆

1.假如在vfp9 環境下測試會有 undo ,redo
但你說沒見過, 我想可能是vfp6 的關係, 實際上去測看看, 結果真的沒有 滑鼠右鍵的功能.
2.在 vfp6 裡, 按control+C 可以複製, control+V可貼上, 但用 keyb '{ctrl+C}' 是無效的,
提供一個正常的用法, 讓 rich textbox 接受到 control+v 的功能, 你再將它放到適當的地方,

* 模擬 control + V
Declare keybd_event IN Win32API SHORT bVk, SHORT bScan, INTEGER dwFlags, INTEGER deExtraInfo
*DECLARE SHORT VkKeyScan IN user32 INTEGER ch
keybd_event(17, 0, 0, 0)
*keybd_event(VkKeyScan(asc('V')), 0, 0, 0)
*keybd_event(VkKeyScan(asc('V')), 0, 2, 0)
keybd_event(asc('V'), 0, 0, 0)
keybd_event(asc('V'), 0, 2, 0)
keybd_event(17, 0, 2, 0)
****
* KEYEVENTF_KEYUP = &H2 ' Release key
* VK_RETURN = &HD 'enter
* VK_SHIFT = &H10 'Shift
* VK_CONTROL = &H11 'Ctrl
* VK_CAPITAL = &H14 'capslock
* VK_ESCAPE = &H1B 'escape

return


以上的程式碼, 希望有所幫助.

_________________
利用>>搜尋<<的功能會比問的還要快得到答案.


garfield 在 星期三 十二月 09, 2009 10:36 pm 作了第 2 次修改
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
小賴



註冊時間: 2004-12-27
文章: 470


第 5 樓

發表發表於: 星期二 七月 04, 2006 12:05 pm    文章主題: 引言回覆

感謝Garfield兄指點 !
1.Release Key 功用, 用法不甚了解, 能否再煩指點 ?
keybd_event(asc('V'), 0, 2, 0)
keybd_event(17, 0, 2, 0)
a. RELEASE KEY 的順序?
b. 為何需Release ? 以上二指令不下, 看不出有何問題;
如果省略Release 的動作將會有何問題發生 ?


2. 複製 & 貼上我都使用_ClipText內存變數來模擬

3. Undo 功能應該無法使用您提供的方式模擬
因為EditBox一失去焦點, 就無法記住Undo內容, RightClick可讓
EditBox不失去焦點, 如果要使用ToolBar OR CommandButton 卻不能
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
garfield
Site Admin


註冊時間: 2003-01-30
文章: 2157


第 6 樓

發表發表於: 星期三 七月 05, 2006 10:52 am    文章主題: 引言回覆

1.keybd_event 在模擬按鍵時, 是偏向"像真的人在按鍵一樣",
也就是在模擬人按 ctrl+V 時, 是先按住 ctrl 不放,再按下 v, 再放開 v , 再放開 ctrl
第3個參數 2 ,就是表示放開按鍵的意思,
實際上不做這個 release 按鍵的動作是否會產生其它的問題就不得而知.

2.可以用就好.
3.Undo 要用 keybd_event 的功能, 可以試著用 on key label 的功能來做看看.

_________________
利用>>搜尋<<的功能會比問的還要快得到答案.
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
garfield
Site Admin


註冊時間: 2003-01-30
文章: 2157


第 7 樓

發表發表於: 星期三 七月 05, 2006 11:03 am    文章主題: 引言回覆

參考網站:
control rich text java source code : http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=5268&lngWId=2

vb sample code: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=59862&lngWId=1

_________________
利用>>搜尋<<的功能會比問的還要快得到答案.
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
小賴



註冊時間: 2004-12-27
文章: 470


第 8 樓

發表發表於: 星期三 七月 05, 2006 1:32 pm    文章主題: 引言回覆

garfield兄
感謝指點, 我研究看看
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
mihu



註冊時間: 2004-06-07
文章: 4


第 9 樓

發表發表於: 星期日 七月 09, 2006 2:17 am    文章主題: 引言回覆

Force positioning of text cursor by right mouse click in EditBox and RTF ActiveX controls (From UT)


Summary

There is a situation often when we need some way to position a text cursor in the text of Editbox or RTF ActiveX controlwhen right click on the control. For example, we want to display a shortcut menu on right click. In menu, user select an option that insert some text into the control on place of current position. However, right click on the control does not change the text cursor position, that confuse users. It would be good to right click, cursor moves to the clicked point and then menu displayed. After selecting the menu option additional text is inserted on the place where mouse is right-clicked.
Here is a code to do this for edit box and RTF control.

Description

Because there are no functionality in VFP to position text cursor by mouse coordinates (as if we clicked on some place), we will simulate a click by mouse on the control by left mouse button to force text cursor positioning.

For EditBox it is very simple - we can use MOUSE command:


* MouseDown event of the EditBox
LPARAMETERS nButton, nShift, nXCoord, nYCoord

if m.nButton<>1
MOUSE CLICK AT (MROW("",3)), (MCOL("",3)) PIXELS LEFT
endif
Events sequence is correct as for right click - any text inserted into edit box in RightClick event will be inserted correctly on place of right-clicking.


For RTF control it is more complex. MOUSE command works for VFP controls only. So we will use API functions to force mouse click events for RTF control.


*** ActiveX Control Event ***
LPARAMETERS nButton, nShift, nXCoord, nYCoord

if m.nButton=2
* below code transforms any mouse clicks to left-button mouse clicks
* to automatically position text cursor on place of click for
* mouse button, not only for left button as in RTF control.


local lcPointStructure
local lnFormHandle, lnTopParentHandle, lnHandle
local lnPressedKeys
local lnButtonDown, lnButtonUp, lnMKButton
local lnWM_MOUSEACTIVATE, lnWM_SETCURSOR, lnWM_MOUSEMOVE, ;
lnWM_LBUTTONDOWN, lnWM_RBUTTONDOWN, lnWM_MBUTTONDOWN, ;
lnWM_LBUTTONUP, lnWM_RBUTTONUP, lnWM_MBUTTONUP, ;
lnHTCLIENT, lnMK_LBUTTON, lnMK_RBUTTON, ;
lnMK_MBUTTON, lnMK_SHIFT, lnMK_CONTROL

*-- Declare Win32 API functions
declare integer SendMessage ;
in Win32API ;
as __SendMessage__ ;
integer lnWindowHandle, ;
integer lnMessage, ;
integer lnWParam, ;
integer lnLParam
declare integer PostMessage ;
in Win32API ;
as __PostMessage__ ;
integer lnWindowHandle, ;
integer lnMessage, ;
integer lnWParam, ;
integer lnLParam
declare integer GetDesktopWindow ;
in Win32API ;
as __GetDesktopWindow__


lnFormHandle = this.hwnd && window handle for RTF ActiveX control

* Get a handle to the desktop window
lnTopParentHandle = __GetDesktopWindow__()

* Declare constants used by mouse messages
lnWM_MOUSEACTIVATE = 0x0021
lnWM_SETCURSOR = 0x0020
lnWM_MOUSEMOVE = 0x0200

lnWM_LBUTTONDOWN = 0x0201
lnWM_RBUTTONDOWN = 0x0204
lnWM_MBUTTONDOWN = 0x0207
lnWM_LBUTTONUP = 0x0202
lnWM_RBUTTONUP = 0x0205
lnWM_MBUTTONUP = 0x0208

lnHTCLIENT = 0x0001

lnMK_LBUTTON = 0x0001
lnMK_RBUTTON = 0x0002
lnMK_MBUTTON = 0x0010
lnMK_SHIFT = 0x0004
lnMK_CONTROL = 0x0008

lnPressedKeys = 0
if BitAnd(m.nShift, 1) = 1
* The Shift key was pressed when
* mouse was clicked
lnPressedKeys = BitOr(m.lnPressedKeys, m.lnMK_SHIFT)
endif
if BitAnd(m.nShift, 2) = 2
*-- The Ctrl key was pressed when
* mouse was clicked
lnPressedKeys = BitOr(m.lnPressedKeys, m.lnMK_CONTROL)
endif

lnButtonDown = m.lnWM_LBUTTONDOWN
do case
case m.nButton = 1
*-- Left button
lnButtonUp = m.lnWM_LBUTTONUP
lnMKButton = m.lnMK_LBUTTON
case m.nButton = 2
*-- Right button
lnButtonUp = m.lnWM_RBUTTONUP
lnMKButton = m.lnMK_RBUTTON
case nButton = 4
*-- Middle button
lnButtonUp = m.lnWM_MBUTTONUP
lnMKButton = m.lnMK_MBUTTON
endcase

* Simulate a mouse up message(s)
lnLParam = m.nYCoord* 256 * 256 + m.nXCoord
= __SendMessage__( ;
m.lnFormHandle, ;
m.lnButtonUp, ;
m.lnMKButton + m.lnPressedKeys, ;
m.lnLParam)
lnLParam = m.lnWM_MOUSEMOVE * 256 * 256 + m.lnHTCLIENT
= __SendMessage__( ;
m.lnFormHandle, ;
m.lnWM_SETCURSOR, ;
m.lnFormHandle, ;
m.lnLParam)
lnLParam = m.nYCoord* 256 * 256 + m.nXCoord
= __PostMessage__( ;
m.lnFormHandle, ;
m.lnWM_MOUSEMOVE, ;
m.lnPressedKeys, ;
m.lnLParam)


* Simulate a mouse down message(s) - always for left button click
lnMKButton = lnMK_LBUTTON

lnLParam = m.lnButtonDown * 256 * 256 + m.lnHTCLIENT
= __PostMessage__( ;
m.lnFormHandle, ;
m.lnWM_MOUSEACTIVATE, ;
m.lnTopParentHandle, ;
m.lnLParam)
= __PostMessage__( ;
m.lnFormHandle, ;
m.lnWM_SETCURSOR, ;
m.lnFormHandle, ;
m.lnLParam)
lnLParam = m.nYCoord* 256 * 256 + m.nXCoord
= __PostMessage__( ;
m.lnFormHandle, ;
m.lnButtonDown, ;
m.lnMKButton, ;
m.lnLParam)

DOEVENTS && will not slow down VFP6 here because mouse events are in buffer


* Put a code for right click event HERE, because there are no
* separate RightClick event in RTF control.

* Insert some text to demo the behaviour
this.SelText = "My Name is ..."

endif
Note that the code sample for this code was get from the Fancy Tool Tip control sources (File#487 by Paul Vlad Tatavu).
回頂端
檢視會員個人資料 發送私人訊息
小賴



註冊時間: 2004-12-27
文章: 470


第 10 樓

發表發表於: 星期一 七月 10, 2006 12:00 pm    文章主題: 引言回覆

感謝mihu兄指點, 有點複雜 ; 尚須研究
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
goodnight



註冊時間: 2008-10-13
文章: 472
來自: 台南市

第 11 樓

發表發表於: 星期四 三月 19, 2009 10:27 pm    文章主題: 引言回覆

精典的範例程式
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件 雅虎訊息通 MSN Messenger
moon64



註冊時間: 2008-12-16
文章: 45


第 12 樓

發表發表於: 星期五 三月 20, 2009 2:19 am    文章主題: 引言回覆

愕....有右鍵的選單程式參考....感動而泣T_T...謝謝
回頂端
檢視會員個人資料 發送私人訊息
amd



註冊時間: 2003-07-20
文章: 54


第 13 樓

發表發表於: 星期五 三月 20, 2009 9:12 am    文章主題: 引言回覆

-------------以下存成 右鍵快顯.pro ----------

PARA oREF
DEFINE POPUP 右鍵快顯功能表 SHORTCUT RELATIVE FROM MROW(),MCOL()

DEFINE bar _med_paste of 右鍵快顯功能表 prompt "貼上(\<P)" key CTRL+V &&,"Ctrl+V" && message "貼上剪貼簿中的內容"
DEFINE bar _med_copy of 右鍵快顯功能表 prompt "複製(\<C)" key CTRL+C SKIP FOR _screen.activeform.activecontrol.sellength = 0 && SKIP FOR empty(_cliptext) && message "將選定內容複製到剪貼簿中"
DEFINE bar 3 of 右鍵快顯功能表 prompt "\-"
DEFINE bar 4 of 右鍵快顯功能表 prompt "\"

DEFINE bar _med_cut of 右鍵快顯功能表 prompt "剪下(\<T)" key CTRL+X SKIP FOR _screen.activeform.activecontrol.sellength = 0 && message "移除選定內容並將其存入剪貼簿"
DEFINE bar 6 of 右鍵快顯功能表 prompt "\-"
DEFINE bar 7 of 右鍵快顯功能表 prompt "\"

DEFINE bar _med_slcta of 右鍵快顯功能表 prompt "全選(\<A)" key CTRL+A &&,"Ctrl+A" && message "選定目前作用視窗中的所有文字或項目"
DEFINE bar 9 of 右鍵快顯功能表 prompt "\-"
DEFINE bar 10 of 右鍵快顯功能表 prompt "\"

DEFINE bar _med_clear of 右鍵快顯功能表 prompt "刪除(\<D)" key CTRL+D SKIP FOR _screen.activeform.activecontrol.sellength = 0 && message "移除選定內容並且不將其存入剪貼簿"
DEFINE bar 12 of 右鍵快顯功能表 prompt "\-"
DEFINE bar 13 of 右鍵快顯功能表 prompt "\"

DEFINE bar _med_undo of 右鍵快顯功能表 prompt "復原(\<U)" key CTRL+Z &&,"Ctrl+Z" && SKIP FOR _screen.activeform.activecontrol.sellength = 0 && message "復原上一次的命令或操作"

Activate POPUP 右鍵快顯功能表

---- 以上格式功能都可自己修改 ----------------------------------------


編成程式 在任何 你想要的 Control 的 RightClick Event 的地方 加 入 do 右鍵快顯 就可以了,只有 Grid 沒有辦法

我用 6.0 9.0 都可以,應是不分版本都可以用吧∼
如果功能不正常,編譯時請把 重新編譯檔案 也打勾
回頂端
檢視會員個人資料 發送私人訊息
ckp6250



註冊時間: 2004-07-30
文章: 1644


第 14 樓

發表發表於: 星期五 三月 20, 2009 11:10 am    文章主題: 引言回覆

amd兄
您說
編成程式 在任何 你想要的 Control 的 RightClick Event 的地方 加 入 do 右鍵快顯 就可以了,只有 Grid 沒有辦法
意思是 Grid 不能有 RightClick Event 的功能 , 若者是說 , 上述程式碼在 Grid 中不適用 ?
我的經驗是 Grid 做 undo 沒有問題呀


ckp6250 在 星期五 三月 20, 2009 11:57 am 作了第 1 次修改
回頂端
檢視會員個人資料 發送私人訊息 參觀發表人的個人網站
ckp6250



註冊時間: 2004-07-30
文章: 1644


第 15 樓

發表發表於: 星期五 三月 20, 2009 11:56 am    文章主題: 引言回覆

to 小賴兄
關於您的第四點
4. 順便再請教一個問題, 如果不是Rich TextBox, 而是VFP的EditBox
要使用Toolbar作Redo, Undo功能可行嗎 ? (EditBox 一失去焦點, Redo,
Undo功能都破功了)

我想 , 直接使用 sysmenu 的功能就好 , 管它有沒有失去焦點,都能做到Redo, Undo , 何必大費周章去搞 Toolbar 呢 ?
黑 cat 白 cat ,能捉 mouse , 就是好 cat

此外
Rich TextBox 的 Redo, Undo 功能, 您可以參考 vfp9 的範例程式中的 Rich TextBox , 它有一個屬性 AutoVerbMenu , 您把它勾起來 , 那麼 , 右鍵中就有Redo, Undo 了
小弟剛試過了,沒有問題,您參考看看
回頂端
檢視會員個人資料 發送私人訊息 參觀發表人的個人網站
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作