VC 将CreateProcess 隐藏的窗口重新显示
STARTUPINFOsi;PROCESS_INFORMATIONpi;ZeroMemory(&pi,sizeof(pi));////隐藏进程窗口si.dwFlags=S...
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
// //隐藏进程窗口
si.dwFlags =STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
// Start the child process.
if( !CreateProcess( NULL , // No module name (use command line).
exe,//process, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
return FALSE;
}
以上是程序代码,通过
si.dwFlags =STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
这两个语句,我把进程窗口隐藏了,但是在以后的操作中我想重新显示这个进程的窗口,应该怎样实现呢?我试过加si.wShowWindow = SW_SHOW;或者将si.dwFlags =STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW; 两句都加上,但是不能实现进程窗口的显示。
有正确答案的话我一定会追加三十分的。
现在我想问的是,如何得到我用CreateProcess创建这个进程程序的窗口句柄?只要回答这个问题就可以了。 展开
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof(pi) );
// //隐藏进程窗口
si.dwFlags =STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
// Start the child process.
if( !CreateProcess( NULL , // No module name (use command line).
exe,//process, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
return FALSE;
}
以上是程序代码,通过
si.dwFlags =STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
这两个语句,我把进程窗口隐藏了,但是在以后的操作中我想重新显示这个进程的窗口,应该怎样实现呢?我试过加si.wShowWindow = SW_SHOW;或者将si.dwFlags =STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW; 两句都加上,但是不能实现进程窗口的显示。
有正确答案的话我一定会追加三十分的。
现在我想问的是,如何得到我用CreateProcess创建这个进程程序的窗口句柄?只要回答这个问题就可以了。 展开
4个回答
展开全部
直接对你的窗体发送一个按键的消息就行了。参考MSDN SendMessage。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把CreateProcess之前的取反去掉,把return FALSE挪到else里,在if(..){}里添加如下代码:
Sleep(5000);
::EnumWindows(&EnumWindowsProc, pi.dwThreadId);//Iterate all windows
其中EnumWindowsProc是一个回调,具体实现如下:
int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pID;
DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);//get process id
if (TpID == (DWORD)param)
{
apphwnd=hwnd;//hwnd is the window handle
return false;
}
return true;
}
这里apphwnd之前定义好,枚举窗口结束时(就是return false),apphwnd就为CreateProcess的进程窗口句柄。
Sleep(5000);
::EnumWindows(&EnumWindowsProc, pi.dwThreadId);//Iterate all windows
其中EnumWindowsProc是一个回调,具体实现如下:
int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pID;
DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);//get process id
if (TpID == (DWORD)param)
{
apphwnd=hwnd;//hwnd is the window handle
return false;
}
return true;
}
这里apphwnd之前定义好,枚举窗口结束时(就是return false),apphwnd就为CreateProcess的进程窗口句柄。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
EnumThreadWindows
VB声明
Declare Function EnumThreadWindows Lib "user32" Alias "EnumThreadWindows" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
说明
枚举与指定任务相关的窗口
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
dwThreadId Long,某线程的标识符,它的窗口将被枚举
lpfn Long,指向一个函数的指针,要求为每个子窗口都调用这个函数。用AddressOf运算符获得函数在标准模式下的地址
lParam Long,在枚举期间,传递给dwcbkd32d.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的
注解
子窗口下属的其他子窗口也可由这个函数枚举
'Enum Classnames
'in a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim ThreadID As Long, ProcessID As Long ' receive id to thread and process of Form1
' Determine the thread which owns this window
ThreadID = GetWindowThreadProcessId(Me.hWnd, ProcessID)
' Use the callback function to list all of the enumerated thrad windows
EnumThreadWindows ThreadID, AddressOf EnumThreadWndProc, 0
'Show the results
Me.AutoRedraw = True
Me.Print sClasses
End Sub
'In a module
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'variable used to list all the classnames
Public sClasses As String
Public Function EnumThreadWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim Ret As Long, sText As String
'create a string-buffer
sText = Space(255)
'get the classname of the window handle
Ret = GetClassName(hWnd, sText, 255)
'cut off the unnecessary part of Chr$(0)'s
sText = Left$(sText, Ret)
'add this classname to the list of classnames
sClasses = sClasses + sText + vbCrLf
'continue the enumeration
EnumThreadWndProc = 1
End Function
VB声明
Declare Function EnumThreadWindows Lib "user32" Alias "EnumThreadWindows" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
说明
枚举与指定任务相关的窗口
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
dwThreadId Long,某线程的标识符,它的窗口将被枚举
lpfn Long,指向一个函数的指针,要求为每个子窗口都调用这个函数。用AddressOf运算符获得函数在标准模式下的地址
lParam Long,在枚举期间,传递给dwcbkd32d.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的
注解
子窗口下属的其他子窗口也可由这个函数枚举
'Enum Classnames
'in a form
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim ThreadID As Long, ProcessID As Long ' receive id to thread and process of Form1
' Determine the thread which owns this window
ThreadID = GetWindowThreadProcessId(Me.hWnd, ProcessID)
' Use the callback function to list all of the enumerated thrad windows
EnumThreadWindows ThreadID, AddressOf EnumThreadWndProc, 0
'Show the results
Me.AutoRedraw = True
Me.Print sClasses
End Sub
'In a module
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'variable used to list all the classnames
Public sClasses As String
Public Function EnumThreadWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim Ret As Long, sText As String
'create a string-buffer
sText = Space(255)
'get the classname of the window handle
Ret = GetClassName(hWnd, sText, 255)
'cut off the unnecessary part of Chr$(0)'s
sText = Left$(sText, Ret)
'add this classname to the list of classnames
sClasses = sClasses + sText + vbCrLf
'continue the enumeration
EnumThreadWndProc = 1
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询