سؤال

I'm trying to find an opened window called "VirtualKeyboard". This is currently achieved using the following code:-

LPCWSTR WindowName =L"SoftKeyboard.exe*32";

HWND Find = ::FindWindowEx(0, 0,WindowName, 0);
cout<<Find<<endl;

The WindowName is obtained from task manager,I have initialized it to be the process name called SoftKeyboard.exe*32.I have also tested it using the task name called Virtual_Keyboard but both produce NULL results.The window was opened before running this program.

I placed a break-point at the line containing " HWND Find = ::FindWindowEx(0, 0,WindowName, 0);".The following appeared in the Autos window:-

 -      Find    0xcccccccccccccccc {unused=??? }    HWND__ *
        unused  CXX0030: Error: expression cannot be evaluated  

How can this be corrected?Why is this occuring?Is the WindowName be extracted from the task manager?Is there an alternative method to find this window?

هل كانت مفيدة؟

المحلول

You have to find out the window class name of the window you want to find. You currently know only that the process from which the window is created is SoftKeyboard.exe. First you have to determine Process ID of this process. In Task Manager Process ID is usually in the second column, right next to executable name. Use Spy++, or the following temporary piece of code to discover all the window class names that belong to this process:

BOOL CALLBACK WriteWindowClass(HWND hWnd, LPARAM lParam)
{
    DWORD nThreadID, nProcessID;
    nThreadID = GetWindowThreadProcessId(hWnd, &nProcessID);

    if (nProcessID == XXX) // Write SoftKeyboard's Process ID instead of XXX
    {
        WCHAR szClassName[256];
        GetClassName(hWnd, szClassName, 256);

        std::wcout << szClassName << std::endl;
    }

    return TRUE;
}

int wmain(int argc, wchar_t* argv[]) 
{
    EnumWindows(WriteWindowClass, 0);

    return 0;
}

You will probably see only one line in console. Text in this line is the class name, and this text should be given to FindWindowEx as third parameter, instead of existing "SoftKeyboard.exe*32".

For the "unused CXX0030" issue just google it: unused CXX0030. You will see that this is normal.

نصائح أخرى

The window class name is not the name appearing at the top of the window. The only way to determine the window class name is to use the Spy++ tool that comes with Visual Studio.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top