I have a legacy application that, on occasion, causes the windows fonts to screw up. I have found that, if I simply reset the desktop, it fixes the problem. I do not have the authority, knowledge, energy, nor desire to try and rewrite the legacy app.
With that in mind, I have gotten the following code to launch the desktop manager to the point that I need it to be. I just need to send the enter key to the opened window and it should do what I need.
Any hints on how I can get the desk.cpl to think the user has hit the enter key? AS you can see, I have tried the PostMessage function but that is not working.
Code:
void Reset( )
{
HWND hwndDskTop;
STARTUPINFO si;
PROCESS_INFORMATION pi;
char cmd[255];
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
hwndDskTop = GetDesktopWindow();
SendMessage(hwndDskTop, WM_FONTCHANGE, 0, 0);
strcpy(cmd,"control.exe desk.cpl desk,@Themes /Action:OpenTheme /File:");
strcat(cmd,"\"C:\\WINDOWS\\Resources\\Themes\\Windows Classic.theme\"");
if( !CreateProcess( NULL, // No module name (use command line).
cmd,
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.
)
{
MessageBox(NULL, "Reset has FAILED.","Error",MB_OK);
}
PostMessage (NULL, WM_KEYDOWN, VK_RETURN, 0);
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}