Hello,
I have a window's handle; with that, I want to restore the window = bring it to front, on top of any other windows I have, and set focus on it.
The only way I can do that (using shortcuts, atm) is by minimizing the currently active window and then restoring the window I want to restore.
It may be a problem with how I listen for hotkeys.
Effects with just using:
SetForegroundWindow(hWnd.ToInt32());
ShowWindowAsync(hWnd, SW_RESTORE);
string activeWindowTitle = GetWindowText(hWnd);
IF there's no active window (I'm viewing desktop), it works just fine. Else, my window is restored, but focus stays on the old one.
Ideally, I should be able to activate a window without minimizing the currently active one. :(
private void restore(IntPtr hWnd)
{
//minimize current window
IntPtr ptrCurrentActiveWindow = GetForegroundWindow();
ShowWindowAsync(ptrCurrentActiveWindow, SW_MINIMIZE);
//restore desired window
SetForegroundWindow(hWnd.ToInt32());
ShowWindowAsync(hWnd, SW_RESTORE);
string activeWindowTitle = GetWindowText(hWnd);
}
bool control = false; //CTRL key pressed?
IntPtr ptrActiveWindow;
void gkh_KeyUp(object sender, KeyEventArgs e)
{
//release a key
if (e.KeyCode.ToString().Equals("F9") && control) //CTRL+F9
{
//notDone = true;
//mode = 0;
//GetDesktopWindowsCaptions();
restore(ptrActiveWindow);
e.Handled = true;
return;
}
else if (e.KeyCode.ToString().Equals("LControlKey"))
{ //ctrl released, disable ctrl effect
control = false;
e.Handled = true;
return;
}
e.Handled = true ;
}