Microsoft IME is not activated after new desktop created by API CreateDesktop?

楠 张 1 Reputation point
2021-10-18T12:40:32.067+00:00

I created a new desktop for some user-registration program which requires user text info input via edit box.

The problem is:
Microsoft IME works well in the default desktop ( Named as DeskA).
But in the new created desktop (Named as DeskN), microsoft IME CAN NOT be activated in any edit control, even in notepad program.

The desktop creation code is as following:

HDESK hCurrentDesk = GetThreadDesktop(GetCurrentThreadId());
HDESK hVirtualOutSourceDesk = CreateDesktop(
     szSecDesktopName.c_str(),
     NULL,
     NULL,
     DF_ALLOWOTHERACCOUNTHOOK,
     GENERIC_ALL,
     NULL);

TCHAR explorer_path[MAX_PATH];
STARTUPINFO startup_info = { 0 };
ExpandEnvironmentStrings(L"%windir%\\explorer.exe", explorer_path, MAX_PATH - 1);
startup_info.cb = sizeof(startup_info);
startup_info.lpDesktop = const_cast<TCHAR*>(szSecDesktopName.c_str());
PROCESS_INFORMATION process_info = { 0 };

//We need to create an explorer.exe in the context of the new desktop for start menu, etc
SetThreadDesktop(hVirtualOutSourceDesk);
CreateProcess(explorer_path, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup_info, &process_info);
CreateMyUserRegisterProgram();
SetThreadDesktop(hCurrentDesk);
SwitchDesktop(hVirtualOutSourceDesk);

I guess there may be some permission issue but not clear about this.
Any suggestions?
Thanks!!!

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,428 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 11,501 Reputation points Microsoft Vendor
    2021-10-20T06:01:42.743+00:00

    According to Desktops,

    The desktops associated with the interactive window station, Winsta0, can be made to display a user interface and receive user input, but only one of these desktops at a time is active. This active desktop, also known as the input desktop, is the one that is currently visible to the user and that receives user input. Applications can use the OpenInputDesktop function to get a handle to the input desktop. Applications that have the required access can use the SwitchDesktop function to specify a different input desktop.