小弟需要在VB程序中控制另一个程序的行为,具体的流程是在主程序中调用另一个程序(简称B)如果B程序没有运行则调用B程序,如果B程序在运行则使B程序获得焦点(即使得B程序称为当前窗口)代码如下
smswinhwnd=FindWindow(vbNullString,"SmsRCS") '
if smswinhwnd<>0 then
PostMessage smswinhwnd,WM_SETFOCUS+WM_SHOWWINDOW,0,0
else
shell "C:\MYCODE\SmsRCS.exe",vbMaximizedFocus
endif问题出现在PostMessage语句上,不论我在主程序中怎么调用,总是不能把已经运行的SmsRCS.exe程序切成当前窗口,请大家帮帮我。
smswinhwnd=FindWindow(vbNullString,"SmsRCS") '
if smswinhwnd<>0 then
PostMessage smswinhwnd,WM_SETFOCUS+WM_SHOWWINDOW,0,0
else
shell "C:\MYCODE\SmsRCS.exe",vbMaximizedFocus
endif问题出现在PostMessage语句上,不论我在主程序中怎么调用,总是不能把已经运行的SmsRCS.exe程序切成当前窗口,请大家帮帮我。
if smswinhwnd<>0 then
SetActiveWindow smswinhwnd
else
shell "C:\MYCODE\SmsRCS.exe",vbMaximizedFocus
endif
if mycodel <>0 then
setActiveWindow mycodel '这个语句执行了但是没有效果,
else
shell "e:\temp\mycode.exe",vbMaximizedFocus
mycodel=FindWindow(vbNullString,"mycode")
endif
End Subprivate Sub Form_Unload(Cancel as Integer)
PostMessage mycodel ,&H10,0,0 '这个语句可以正常执行
End Sub
Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Longsmswinhwnd=FindWindow(vbNullString,"SmsRCS")if smswinhwnd<>0 then
me.hide
ShowWindow smswinhwnd,1
SetActiveWindow smswinhwnd
else
shell "C:\MYCODE\SmsRCS.exe",vbMaximizedFocus
me.hide
endif