| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1650 人关注过本帖
标题:请问如何正确选择记事本中的指定行?(问题延续)
取消只看楼主 加入收藏
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:11 
请问如何正确选择记事本中的指定行?(问题延续)
编程论坛 - 请问如何正确选择记事本中的指定行?  https://bbs.bccn.net/thread-513979-1-1.html
上一个问题的延续,不知道大家发现了没有,如果我们多次执行选择行操作,然后记事本一旦获得焦点,选择的行自动切换回我们第一次执行的结果
比如我们第一次选择第2行,然后在随意的操作几次,然后点击记事本的标题栏使记事本窗口获得焦点,我们会发现选中的行自动变成了第2行,也就是我们第一次操作的结果


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

搜索更多相关主题的帖子: 记事本 操作 指定 获得 选择 
2024-11-12 13:45
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
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 = 68, ;
        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 init
    PUBLIC lnSendHwnd,hwnd
    ENDPROC

    PROCEDURE command1.Click
    #Define EM_SETSEL 0xb1
    #Define EM_LINEINDEX 0xbb
    #Define WM_SYSCOMMAND 0x112
    #Define SC_MAXIMIZE 0xF030
    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 SendMessageW In WIN32API as SendMsgWn Integer,Integer,Integer,Integer
    Declare Integer WinExec in kernel32 string, integer
    hWnd = FindWindowEx( 0, 0, "Notepad", NULL )
    if hwnd=0
        winexec("NOTEPAD.EXE",5)
        hWnd = FindWindowEx( 0, 0, "Notepad", NULL )
        SendMessages(m.Hwnd,WM_SYSCOMMAND,SC_MAXIMIZE,null)
        lnSendHwnd=FindWindowEx(m.hwnd,0,"Edit",Null)
        SendMessages(lnSendHwnd,12,0,prgprg)
    endif
    i=thisform.text1.value
    SendMsgWn(lnSendHwnd, EM_SETSEL ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i-1,0) ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i,0) )
    ENDPROC
ENDDEFINE
2024-11-12 14:12
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
用我上面发的代码,然后选择几次后,点击记事本标题栏试试,不要用原来的代码
2024-11-12 18:28
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
原来的代码是每次都新建一个记事本,这次是如果有打开的笔记本直接引用,不再新建笔记本了
2024-11-12 18:35
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
好奇怪,我用win10试试
2024-11-12 18:51
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
win10确实执行结果正常,我刚才发的是win7环境下,看来是win7下不正常
2024-11-12 19:01
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2024-11-12 19:15
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
win7下有点不正常,win10测试正常


2024-11-12 19:15
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
每次选中后用EM_GETSEL(&HB0=176)获取的也是新的位置,为什么点击标题获得焦点后就又回到了第一次的选择了
2024-11-12 20:42
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
加一句=SetForegroundWindow(hwnd),激活窗口至前端就好了
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 = 68, ;
        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 init
    PUBLIC lnSendHwnd,hwnd
    ENDPROC

    PROCEDURE command1.Click
    #Define EM_SETSEL 0xb1
    #Define EM_LINEINDEX 0xbb
    #Define WM_SYSCOMMAND 0x112
    #Define SC_MAXIMIZE 0xF030
    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 SendMessageW In WIN32API as SendMsgWn Integer,Integer,Integer,Integer
    Declare Integer WinExec in kernel32 string, integer
       Declare SetForegroundWindow in win32api long hwnd
    hWnd = FindWindowEx( 0, 0, "Notepad", NULL )
    if hwnd=0
        winexec("NOTEPAD.EXE",5)
        hWnd = FindWindowEx( 0, 0, "Notepad", NULL )
        SendMessages(m.Hwnd,WM_SYSCOMMAND,SC_MAXIMIZE,null)
        lnSendHwnd=FindWindowEx(m.hwnd,0,"Edit",Null)
        SendMessages(lnSendHwnd,12,0,prgprg)
    endif
      =SetForegroundWindow(hwnd)
    i=thisform.text1.value
    SendMsgWn(lnSendHwnd, EM_SETSEL ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i-1,0) ;
        , SendMsgWn(lnSendHwnd,EM_LINEINDEX,i,0) )
    ENDPROC
ENDDEFINE
2024-11-13 10:09
快速回复:请问如何正确选择记事本中的指定行?(问题延续)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017511 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved