| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1799 人关注过本帖
标题:请问如何正确选择记事本中的指定行?(问题延续)
只看楼主 加入收藏
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:322
专家分:450
注 册:2019-10-11
收藏
得分:0 
每次选中后用EM_GETSEL(&HB0=176)获取的也是新的位置,为什么点击标题获得焦点后就又回到了第一次的选择了
2024-11-12 20:42
凝聚双眼
Rank: 2
等 级:论坛游民
帖 子:37
专家分:32
注 册:2023-12-1
收藏
得分:0 
win7下问题复现
2024-11-13 09:17
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:322
专家分:450
注 册: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
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:322
专家分:450
注 册:2019-10-11
收藏
得分:0 
查看网上说SetForegroundWindow调用有时候会失败,给出的解决办法是:
if(hWnd)
{
            HWND hForeWnd = ::GetForegroundWindow();
            DWORD dwForeID = ::GetWindowThreadProcessId(hForeWnd,NULL);
            DWORD dwCurID = ::GetCurrentThreadId();
            ::AttachThreadInput(dwCurID,dwForeID,TRUE);
            ::ShowWindow(hWnd,SW_SHOWNORMAL);
            ::SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
            ::SetWindowPos(hWnd,HWND_NOTOPMOST,0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
            ::SetForegroundWindow(hWnd);
            ::AttachThreadInput(dwCurID,dwForeID,FALSE);
//hWnd就是需要置前的窗口句柄
}
2024-11-13 10:25
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1790
专家分:3389
注 册:2012-2-29
收藏
得分:0 
回复 13楼 sych
这下正常啦
2024-11-13 19:41
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:322
专家分:450
注 册:2019-10-11
收藏
得分:0 
回复 15楼 schtg
应该达到目的了,不知道把窗口调到前台这样操作会不会有安全隐患
2024-11-13 20:07
zhaoshaoye
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2024-11-15
收藏
得分:0 










































2024-11-15 17:13
快速回复:请问如何正确选择记事本中的指定行?(问题延续)
数据加载中...
 
   



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

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