简体   繁体   English

查找要在FindWindow wniapi C ++中使用的已启动应用程序的lpClassName?

[英]find lpClassName of started application to be used in FindWindow wniapi c++?

How can i find the lpClassName string of the FindWindow API call if i start application with CreateProcess API function 如果我使用CreateProcess API函数启动应用程序,如何查找FindWindow API调用的lpClassName字符串

PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter

STARTUPINFO StartupInfo; //This is an [in] parameter

ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field

if(CreateProcess("c:\\temp\\application1.exe", NULL,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
}
else
{
MessageBox("The process could not be started...");
}

also can i some how set only part of the name in the FindWindow ? 我也可以如何在FindWindow中仅设置名称的一部分? for example if i know that allays the app name is "application< some version number>.exe" so it can be : 例如,如果我知道该应用程序的名称为“ application <某些版本号> .exe”,那么它可以是:
application1.exe 应用程序1.exe
application1.1.exe 应用程序1.1.exe
application1.2.1.exe application1.2.1.exe

my final goal is to use Windows Message system and the SendMessage API method to send messages to the application. 我的最终目标是使用Windows消息系统和SendMessage API方法将消息发送到应用程序。

It sounds like what you really want is the handle to the window created by your launched application. 听起来您真正想要的是启动的应用程序创建的窗口的句柄。

The problem is, your process might create many windows. 问题是,您的过程可能会创建许多窗口。 You can use the SetWindowsHookEx function to be notified whenever the process creates a new window. 您可以使用SetWindowsHookEx函数在进程创建新窗口时得到通知。

Untested code incoming: 未经测试的代码传入:

LRESULT CALLBACK CBTProc(int nCode,  WPARAM wParam,  LPARAM lParam) {
    if(nCode == HCBT_CREATEWND) {
        // wParam is a handle to a window your app just created.
    }
    return 0;
}

CreateProcess("c:\\temp\\application1.exe", NULL,
    NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,
    NULL,&StartupInfo,&ProcessInfo);

SetWindowsHookEx(WH_CBT, procHook, NULL, ProcessInfo.hThread);

ResumeThread(ProcessInfo.hTread);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM