正则表达式    re.Pattern = "(a)(b)"
    str = "33ab33"
    Set mt = re.Execute(str)
    TXT2.Text = re.Replace(str, "$2")
 
字符串33ab33 
表达式(a)(b) 
替换列表$2 
目前结果33b33 
我想要的结果应该b 
请教如何编写代码===============无奈的分割线================
如何获得别的程序窗口的内框大小Private Type RECT
    Left   As Long
    Top   As Long
    Right   As Long
    Bottom   As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
whwnd = FindWindow(vbNullString, "其他程序的窗口")
 Dim ret As RECT
 GetWindowRect whwnd, ret
wwidth = ret.Right - ret.Left
wheight = ret.Bottom - ret.Top
Command1.Caption = wwidth & " " & wheight只能获得整体外框的大小
我想要的结果 程序内框的窗口大小===============郁闷的分割线================
如何把自己程序在别人的窗口内启动
1、别人的程序不能修改的情况下 
2、自己的程序在它的窗口中启动 
3、总在此窗口前面 但不能总在所有窗口前 
请问api hook方面应该如何编写 
目前我只会把别人的程序放在自己的窗口内启动
我想要的结果 我的窗口放在别人的窗口中启动

解决方案 »

  1.   

    使用GetClientRect函数可以获取。
      

  2.   

    开始没仔细看
    第2个问题,使用SetParent函数
    第3个问题,BringWindowToTop函数
      

  3.   

    BringWindowToTop Form1.hwnd
    不行喔我用记事本测试了一下发觉不能在顶层 只显示了一个command 其他form label都无法置顶显示
      

  4.   

    坐标问题可用使用ScreenToClient和ClientToScreen解决。
    BringWindowToTop是可以的。还可以使用SetWindowPos函数。
    我说的都是API函数。
      

  5.   

    我知道 我也是用API来写但是发现一个问题 form1.top form1.left不是用象素
    而GetClientRect返回的则是象素
    应该如何设置BringWindowToTop form1.hwnd
    这个格式没错吧 怎么就显示不了前面呢
      

  6.   

    vb 默认坐标系统的单位是Twips(提),跟 Pixs 换算的公式是 
    TwipsX = PixsX * Screen.TwipsPerPixelX   
    TwipsY = PixsY * Screen.TwipsPerPixelY
    API 里面使用的坐标基本上都是以 Pixs 为单位。
      

  7.   

    =================================
    但是发现一个问题 form1.top form1.left不是用象素在VB中,单位是“缇”,1缇 = 15pix自己换算一下就行了。
      

  8.   


    我晕哟,刚好弄反了:
    1pix = 15缇
      

  9.   

    本form在记事本内
    SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, &H1但是不贴左上 而在中间
      

  10.   

    你们搞错了,Twip 单位比 Pix 还要小。 1 Pix = 15 Twips
      

  11.   


    Option ExplicitPrivate Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Dim whwnd
    Private Sub Command1_Click()whwnd = FindWindow(vbNullString, "无标题 - 记事本")Dim rc As RECTGetClientRect whwnd, rcSetParent Form1.hwnd, whwnd
    SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, &H1MsgBox rc.RightEnd Sub
    MsgBox rc.Right
    返回结果为0
    我想得到大小SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, &H1
    无法把窗口放置左上
    我要放到右上
      

  12.   


    SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, &H1
    这个函数用的是屏幕坐标,你这样会把Form1置于屏幕的左上角位置。
      

  13.   

    你要用 GetWindowRect() 函数才可得到窗口在屏幕上的位置。Dim whwndPrivate Sub Command1_Click()whwnd = FindWindow(vbNullString, "无标题 - 记事本")
    Dim rc As RECTGetWindowRect whwnd, rc
    SetParent Form1.hwnd, whwnd
    SetWindowPos Form1.hwnd, -1, rc.Left, rc.Top, 0, 0, 1&
    MsgBox rc.RightEnd Sub
      

  14.   

    谢谢楼上坐标解决了  继而问题又来了虽然在记事本中测试通过但是我在其他窗口 例如某些程序BringWindowToTop Form1.hwnd 
    SetWindowPos Form1.hwnd, -1, rc.Left, rc.Top, 0, 0, 1&
    这2种方法都无法把自己的程序置顶 而别人的程序永远在顶上盖着请问这个怎么解决
      

  15.   

    用timer  一直设置?我的播放器的字幕就是一直在上面的,用vbnet写的,窗体有个属性是topmost,我设置成了true,然后窗体就一直在上面
    BringWindowToTop Form1.hwnd  
    SetWindowPos Form1.hwnd, -1, rc.Left, rc.Top, 0, 0, 1& 
      

  16.   

    最简单的是使用Timer定时将窗口置顶。
    复杂一点的是拦截消息泵,在自己的消息处理函数里先获得当前置顶的窗口,然后与自己窗口的句柄进行比较,如果不是自己的窗口,则作置顶。
      

  17.   

    不是使用timer的问题 而是根本无法置于那个程序的顶层 不知道是不是因为那程序使用D3D所造成的
      

  18.   

    第一个问题mt.SubMatches(1) 就是你要的答案
      

  19.   


    先谢谢,这个问题早就解决了 但答案不是mt.SubMatches(1)顶帖的问题可以不看 目前问题引申到16楼,我所说的找不到答案 是16楼的问题
      

  20.   

    由于记事本是一个特殊的窗口,当它接收到WM_PAINT消息时,会自动在EDIT子窗口绘制文本,这样一来,就会影响了你的窗口的绘制,换一个程序试。
    另外,想要把自己的窗口永远显示在别人窗口中且处于最顶层,可增加如下语句:
        SetParent Form1.hwnd, hwndParent
        Form1.Hide
        Form1.Show vbModal
        Form1.ZOrder 1000
      

  21.   

    谢谢,原理我看懂了,但是不论是记事本还是其他程序窗口 都是只能够在程序运行的时候能置顶一下  只要我在别的程序进行操作 这段代码就无效了 即使用timer也不行 不知道为什么
      

  22.   

    Option Explicit
    '该窗口为包含窗口
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Const STILL_ACTIVE As Long = &H103
    Private Const PROCESS_QUERY_INFORMATION As Long = &H400
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Const HWND_TOPMOST = -1
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const GWL_EXSTYLE = (-20)
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_SHOWMAXIMIZED = 3Private Sub Command1_Click()
        Dim hwndTarget As Long
       
        Load Form2
        Form2.Show , Me
        hwndTarget = FindWindow(vbNullString, "文档 - 写字板")
        
        If hwndTarget = 0 Then Exit Sub
        SetParent hwndTarget, Me.hwnd
        ShowWindow hwndTarget, SW_SHOWMAXIMIZED
        SetWindowPos Form2.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
        
        '等待写字板结束
        Dim pID As Long
        Dim hProcess As Long
        Dim lpExitCode As Long
        
        Call GetWindowThreadProcessId(hwndTarget, pID)
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pID)
        '以下等待被调用的进程结束
        Do While True
            Call Sleep(100)
            Call GetExitCodeProcess(hProcess, lpExitCode)
            If lpExitCode <> STILL_ACTIVE Then
                CloseHandle (hProcess)
                Exit Do
            End If
            DoEvents
        Loop
        Unload Form2
        Unload Me
    End SubPrivate Sub Form_Load()
        Me.WindowState = vbNormal
        Me.Move 0, 0, 1024 * 15, 736 * 15
    End Sub
      

  23.   

    在工程里添加两个窗口,在Form1里加一个按钮,再把上面的代码粘贴过去,看看效果能不能满足你的要求。
      

  24.   

    注意Form1的边框设置为0,ControlBox设为False,Caption设为空。
      

  25.   

    先谢谢,但是这个效果不是我需要的效果
    主要不满足第2和第3点-------------------------------------
    1、别人的程序不能修改的情况下  
    2、自己的程序在它的窗口中启动  
    3、总在此窗口前面 但不能总在所有窗口前  
    -------------------------------------第2点这样可以
    hwndTarget = FindWindow(vbNullString, "文档 - 写字板") 
    SetParent Form1.hwnd, hwndTarget 现在主要问题在于第3点
    如果不用SetParent 则效果如form2一样 总在所有窗口最前而不是hwndTarget对应的窗口前
    如果使用SetParent 则无法置于hwndTarget对应的窗口前