0

Im looking in this site and google but found nothing. I need to show a form contain some control show information, but need to dont steal the focus to other windows (like windowed-full screen game) AND can use the textbox inside the form, for write without steal the game window focus.

I can launch the window without steal focus using this: Opening a WinForm with TopMost=true but not having it steal focus?

But when i click in the window, get the focus. I need to make the window active, and textbox writable, but without steal other windows focus It is possible?

Community
  • 1
  • 1
Zenth
  • 769
  • 2
  • 7
  • 23
  • 1
    I'm afraid not, you can't have a writeable textbox without a focus, how would that even work? – walther Dec 07 '14 at 17:04
  • When the user clicks on the control and writes in it, it WILL have focus. But has soon as he/she is done typing you can close the form. Then you can open another one that looks exactly the same and does not have focus, using the tricks you've referenced. – RenniePet Dec 07 '14 at 19:08

3 Answers3

0

I need to show a form contain some control show information, but need to dont steal the focus to other windows ... But when i click in the window, get the focus.

So it sounds to me like you want a regular window, but only doesn't steal focus when it is first displayed?

Instead of using the built-in Form.Show(), use the ShowWindow() API with SW_SHOWNA:

private const int SW_SHOWNA = 4;

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

private void ShowWindowWithoutFocus()
{
    ShowWindow(this.Handle, SW_SHOWNA);
}
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • i need the window dont steal never the focus to others but allow to use the controls inside – Zenth Dec 07 '14 at 19:08
  • As said before, to type into the textbox your window needs focus. The things you're asking for **do not** go together. – Idle_Mind Dec 07 '14 at 19:26
0
// Sets the window to be foreground
[DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hwnd);

/// <summary>
/// onVisible focus input username text box
/// </summary>
protected override void OnVisibleChanged(EventArgs e)
{
    SetForegroundWindow(this.Handle);
    base.OnVisibleChanged(e);
}
GSP
  • 574
  • 3
  • 7
  • 34
0

you can control with window show flags like below example. but it's have some problem. to raise top position, current focused process should have this window. on the other hand, one process have two window. window1 is focused , but window2 is not focused. if you keep window1's focus, you call bellow function. but window1 and window2 process are different. this function not work.

window2->SetWindowPos(0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

to move top position regardless focus and process, you call two times setWindowpos

first: move screen top most, but window have top most position and occupied top always

window2->SetWindowPos(HWND_TOPMOST , 0,0,0,0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

second: remove TOPMOST attribute

window2->SetWindowPos(HWND_NOTOPMOST , 0,0,0,0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
MadFish.DT
  • 41
  • 4