2

I want to avoid multiple executions of my application and set the focus on the already running instance when the application is started another time.
I have made the application a singleton by using a mutex, which works fine. But I encountered an issue when bringing it to front. The code for this is taken from these SO answers:
https://stackoverflow.com/a/7358286/2505186
https://stackoverflow.com/a/2315093/2505186

SetForegroundWindow(hWnd);
ShowWindow(hWnd, SW_RESTORE);

At the beginning it always failed to bring the window to front. After some while, I found that it is actually working, but not fully. The only thing that came to front was this little symbol:

This is the overlay icon of Teamviewer (I'm using version 8). Instead of my application, only this icon is brought to front:

When I log off at Teamviewer, the focussing on my application is working as expected. :-)

Why does it not work with Teamviewer logged on?
What functions do I need to execute to make it work also with Teamviewer?

I tested the "Bring to front" function of Sysinternals ProcessExplorer... it's working. So they must be using functions that are able to overcome this problem.

Community
  • 1
  • 1
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45
  • While teamviewer is running ,some of the codings stop working hence you cannot access the application – Tharif Mar 20 '15 at 11:56
  • What do you mean by "running"? In my case, I don't have any active connections, only the program is running and logged on to an account. Also, the application itself works fine, that single function excepted. – Tobias Knauss Mar 20 '15 at 12:04
  • While Teamviewer Application is running – Tharif Mar 20 '15 at 12:05

2 Answers2

2

This button is drawn by TeamViewer in other application windows. You can disable it in the TeamViewer options:

Options -> Advanced -> Advanced settings for Computers and Contacts -> QuickConnect button -> Configure... -> Disable "Show QuickConnect button"

ness
  • 41
  • 5
  • Thanks, but I know how to disable it. Nevertheless I would like to find a solution that is working with this button remaining enabled. ProcessExplorer has this solution, but I don't know how they do it. I think I'm gonna write them. – Tobias Knauss Mar 20 '15 at 15:00
0

Try using first ShowWindow() and after SetForeGroundWindow()

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

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hWnd);
P.A
  • 130
  • 6