正则表达式 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方面应该如何编写
目前我只会把别人的程序放在自己的窗口内启动
我想要的结果 我的窗口放在别人的窗口中启动
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方面应该如何编写
目前我只会把别人的程序放在自己的窗口内启动
我想要的结果 我的窗口放在别人的窗口中启动
第2个问题,使用SetParent函数
第3个问题,BringWindowToTop函数
不行喔我用记事本测试了一下发觉不能在顶层 只显示了一个command 其他form label都无法置顶显示
BringWindowToTop是可以的。还可以使用SetWindowPos函数。
我说的都是API函数。
而GetClientRect返回的则是象素
应该如何设置BringWindowToTop form1.hwnd
这个格式没错吧 怎么就显示不了前面呢
TwipsX = PixsX * Screen.TwipsPerPixelX
TwipsY = PixsY * Screen.TwipsPerPixelY
API 里面使用的坐标基本上都是以 Pixs 为单位。
但是发现一个问题 form1.top form1.left不是用象素在VB中,单位是“缇”,1缇 = 15pix自己换算一下就行了。
我晕哟,刚好弄反了:
1pix = 15缇
SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, &H1但是不贴左上 而在中间
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
无法把窗口放置左上
我要放到右上
SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, &H1
这个函数用的是屏幕坐标,你这样会把Form1置于屏幕的左上角位置。
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
SetWindowPos Form1.hwnd, -1, rc.Left, rc.Top, 0, 0, 1&
这2种方法都无法把自己的程序置顶 而别人的程序永远在顶上盖着请问这个怎么解决
BringWindowToTop Form1.hwnd
SetWindowPos Form1.hwnd, -1, rc.Left, rc.Top, 0, 0, 1&
复杂一点的是拦截消息泵,在自己的消息处理函数里先获得当前置顶的窗口,然后与自己窗口的句柄进行比较,如果不是自己的窗口,则作置顶。
先谢谢,这个问题早就解决了 但答案不是mt.SubMatches(1)顶帖的问题可以不看 目前问题引申到16楼,我所说的找不到答案 是16楼的问题
另外,想要把自己的窗口永远显示在别人窗口中且处于最顶层,可增加如下语句:
SetParent Form1.hwnd, hwndParent
Form1.Hide
Form1.Show vbModal
Form1.ZOrder 1000
'该窗口为包含窗口
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
主要不满足第2和第3点-------------------------------------
1、别人的程序不能修改的情况下
2、自己的程序在它的窗口中启动
3、总在此窗口前面 但不能总在所有窗口前
-------------------------------------第2点这样可以
hwndTarget = FindWindow(vbNullString, "文档 - 写字板")
SetParent Form1.hwnd, hwndTarget 现在主要问题在于第3点
如果不用SetParent 则效果如form2一样 总在所有窗口最前而不是hwndTarget对应的窗口前
如果使用SetParent 则无法置于hwndTarget对应的窗口前