注册 登录
编程论坛 VFP论坛

请问如何正确选择记事本中的指定行?

sych 发布于 2024-11-10 14:41, 261 次点击
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录

如果没有双字节字符,执行结果是正确
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form
    Height = 110
    Width = 193
    ShowWindow = 2
    DoCreate = .T.
    AutoCenter = .T.
    Caption = "Form1"
    AlwaysOnTop = .T.
    Name = "Form1"

    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 60, ;
        Left = 48, ;
        Height = 25, ;
        Width = 60, ;
        Caption = "执行", ;
        Name = "Command1"

    ADD OBJECT text1 AS textbox WITH ;
        Alignment = 3, ;
        Value = 1, ;
        Height = 25, ;
        InputMask = "999", ;
        Left = 72, ;
        Top = 24, ;
        Width = 40, ;
        Name = "Text1"

    ADD OBJECT label1 AS label WITH ;
        Caption = "选择第:", ;
        Height = 16, ;
        Left = 24, ;
        Top = 29, ;
        Width = 46, ;
        Name = "Label1"

    ADD OBJECT label2 AS label WITH ;
        Caption = "行", ;
        Height = 16, ;
        Left = 116, ;
        Top = 29, ;
        Width = 46, ;
        Name = "Label2"

    PROCEDURE command1.Click
        #Define EM_SETSEL 0xb1
        #Define EM_LINEINDEX 0xbb
TEXT TO prgprg noshow
2343432435
34454t4365t43
ddffergter
rwew阿德顺丰到付归属感
谁丰东股份23424递四方速递
23424535
水电费45235
3424
endtext
        DECLARE Long FindWindowEx IN WIN32API Long, Long, String, String
        Declare Integer SendMessage In WIN32API as SendMessages Integer,Integer,Integer,String
        Declare Integer SendMessage In WIN32API as SendMessagen Integer,Integer,Integer,Integer
        Declare Integer WinExec in kernel32 string, integer
        winexec("NOTEPAD.EXE",1)
        hWnd = FindWindowEx( 0, 0, "Notepad", NULL )
        SendMessages(m.Hwnd,274,61488,null)
        lnSendHwnd=FindWindowEx(m.hwnd,0,"Edit",Null)
        SendMessages(lnSendHwnd,12,LEN(prgprg)+1,prgprg)
        i=thisform.text1.value
        SendMessagen(lnSendHwnd,EM_SETSEL,SendMessagen(lnSendHwnd,EM_LINEINDEX,i-1,0),SendMessagen(lnSendHwnd,EM_LINEINDEX,i,0))
    ENDPROC

ENDDEFINE


[此贴子已经被作者于2024-11-10 14:42编辑过]

9 回复
#2
schtg2024-11-10 19:39
回复 楼主 sych
在我的机子上运行,出现相同问题,但暂时看不出原因。
#3
wcx_cc2024-11-10 23:39
.................

[此贴子已经被作者于2024-11-19 22:21编辑过]

#4
csyx2024-11-11 09:37
改为按宽字符处理试试

[此贴子已经被作者于2024-11-11 09:41编辑过]

#5
csyx2024-11-11 09:44
大概这样:
        .... 省略前面代码
        winexec("NOTEPAD.EXE",1)
        hWnd = FindWindowEx( 0, 0, "Notepad", NULL )
        SendMessages(m.Hwnd,274,61488,null)
        lnSendHwnd=FindWindowEx(m.hwnd,0,"Edit",Null)
#IF .F.
    SendMessages(lnSendHwnd,  WM_SETTEXT, LEN(prgprg)+1, prgprg)
    SendMessages(lnSendHwnd,12,LEN(prgprg)+1,prgprg)
    i=thisform.text1.value
    SendMessagen(lnSendHwnd,EM_SETSEL,SendMessagen(lnSendHwnd,EM_LINEINDEX,i-1,0),SendMessagen(lnSendHwnd,EM_LINEINDEX,i,0))
#ELSE
    Declare Integer SendMessageW In WIN32API as SendMsgWc Integer,Integer,Integer,String
    Declare Integer SendMessageW In WIN32API as SendMsgWn Integer,Integer,Integer,Integer
    prgprg = Strconv(prgprg, 5)    && DBCS > UNICODE
    #define WM_SETTEXT    0x000C
    SendMsgWc(lnSendHwnd, WM_SETTEXT, 0, prgprg)
    i=thisform.text1.value
    SendMsgWn(lnSendHwnd, EM_SETSEL ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i-1,0) ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i,0) )

#ENDIF
ENDDEFINE

#6
sych2024-11-11 09:59
完美解决
#7
sych2024-11-11 10:11
你建议改为按宽字符处理试试,我是一点头绪也没有,看到你的代码才豁然开朗,谢谢。
#8
sych2024-11-11 10:22
我又测试了一下,发现只变动这一句也可以
    SendMsgWn(lnSendHwnd, EM_SETSEL ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i-1,0) ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i,0) )
#9
iswith2024-11-13 23:13
思路就是把Edit的超过ASCII字符全部去掉!以及不可见字符代码替换掉,手工处理何时才是头。。。。

[此贴子已经被作者于2024-11-13 23:15编辑过]

#10
kmyz_yyl4 天前 23:13
可用filetostr和alines
1