box wont maximize further - c#

I have this app written in C# and it won't maximize further even though the code forcefully specifies the size, the window doesn't follow it. Other windows app follows the size that I specified but this one doesn't (been figuring what might go wrong but it seems a bug). Thanks stackoverflow
As you can see, the running window is not following explicitly what the code tells. The displayed window should be way larger than the current size.

Related

Is there any way to detect if an external process is running on exclusive fullscreen mode?

spent the whole day looking up for a solution, but I couldn't find it
I'm not talking about borderless windowed fullscreen, but those exclusive fullscreen mode that usually games use
is this possible?
I think you can get list of the process independently from your mode using System.Diagnostics.Process. Than you can just find any process by name or other properties.
UPDATED
So I have tried some solutions, but for now found one that works if process if full-screen right now, not minimized. Pretty much that:
Is there a way to check to see if another program is running full screen
My code Snippet (Runs in loop and checks if the process with specific name is fullsreen)
https://pastebin.com/qwE7ZXVt
Another possible solution based on window into style flags
https://www.reddit.com/r/AutoHotkey/comments/6maqdd/detecting_if_window_in_the_foreground_is/
But I was unable to make it work. You can try to PM folks there.
Also this site was very handy
https://www.pinvoke.net/index.aspx

remote desktop application with wrongly displayed buttons

I have a winform within a remote desktop application that is built dynamically with a container panel for a toolbar with large (regular) buttons. The application is writen in C# and .NET 4.0. The application is viewed as it should only if I do not maximize the window (meaning restored view is fine).
Now, after RDP login - within most client computers - the application looks fine (even when we maximize and restoring). Within low resolution client computers (800x600), the buttons on the toolbar are not displayed in the right position (such as in the 1024x768 clients).
I used double buffering and it didn't help... the problem may or may not be depended on the screen resolution (it can be memory issue or something). It is not a problem of localization layout.
The following image shows the Fine and Bad states: http://imgur.com/gO4UJ,v7O9K
What can I do to resolve this issue?
OK, so in case anybody gets to this kind of case, this is the thing that made the issue:
In the form, there was an empty repaint override. The programmer that created the form was overriding the repaint with an empty method (don't know why, I guess I'll ask my team for the business logic).
How did I reproduce it in the development environment? Following Albin Sunnanbo's note, I ran the RDP application in minimized version during initialization, and I noticed that it occurs with large resolution clients also in this use case... So, I know repaint occurs while performing a window resize - and this made me suspicious about the method...
==> On a side note, I guess this is why inheritance is so bad, and going on to WPF is better. It took me 3 days to understand why this issue occurred.

Silverlight - First time going to Full Screen opens in background (FF, Chrome, not IE)

I have not found an answer to this, not here or when I have googled for it.
The case is that we have a silverlight with a video-stream. If we have enabled fullscreen with the code : Application.Current.Host.Content.IsFullScreen first time the application is taken to fullscreen it opens in the background (and for the customer it seems like nothing happens).
It seems it will remember it to the next time.
The alternative for our sake is to not enable it to disable this so that when the window loses focus it is taken out of fullscreen.
Is there a way to get around this, as we would both like to open it in fullscreen on top of the screen (not hidden), and have the possibility to make it pinned there. (Since many of our users would like to have it on another monitor and use the computer at the same time)
I have been thinking about storing it in application storage, as it seems it rememebers the first time a user move it in front. But dont know how this can be done, and also seems a bit hackish.
In IE this works, but of course this is not good enough.
To have your application stay fullscreen even when not focused, you have to add the following to your Application:
Host.Content.FullScreenOptions = System.Windows.Interop.FullScreenOptions.StaysFullScreenWhenUnfocused;
This will generate a prompt for permission when you switch to full screen mode, similar to IsolatedStorage quota prompts.
For the app showing in background, I only have experienced this using Safari on MacOS, I never had this issue on Windows IE, FF or Chrome. Maybe the line above will help matters though.

C# Select default screen for separate process

Is there a way to designate the start up location of an external process? I am trying to select the screen BEFORE the application launches, NOT move it afterwards.
When start the process and then move the window from one screen to another (programatically or manually) it resizes the window but not the content of that window because they are different resolutions.
I don't have control of the resolution of the screens or selection of which one is primary.
This question is similar to, but not the same as:
Launch an application and send it to second monitor?
Launch an application and send it to second monitor
May be I understand what you mean.
You want that external programm appears immediately in the screen you want, so you will get rid of resolution mananagement bug of the program, cause this is a bug, if content of the window doesn't reflect resolution changes of host window.
There is no way to do that, that I'm aware of. In fact solutions linked by you first load program, find window and finally move where needed.
If this is not what you're actually asking for, please explain better your intentions.
So if I understand correctly, you want to decide location a windows program launches but you don't want to move it after the program starts.
Usually a program remembers its previous position when it closes in registry for next launch. I would control that. For more information, refer to http://www.mywindowsclub.com/resources/3016-Start-up-position-programs-Windows.aspx

Prevent Process 'A' from spawning Process 'B' which then shows up on top of what should be the "TopMost" Process 'C'

I have a windows form application which needs to be the TopMost. I've set my form to be the TopMost and my application works as I'd like it to except for in one case.
There is a 3rd party application (referred to as player.exe) that displays SWF movie files on a portion of the screen that popup on top of my application.
Using Process Monitor I determined that player.exe application calls
flash.exe <PositionX> <PositionY> <Width> <Height> <MovieFile>
in my case:
flash.exe 901 96 379 261 somemovie.swf
Since flash.exe is being spawned in a new process after my form has been set to the TopMost it is appearing on top of my application.
First thing I did was make my application minimize the player.exe main application window hoping that this would prevent the Flash from appearing also. But, unfortunately it doesn't... even with the window minimized whenever the flash movie starts it shows up at the pixel location (901,96). I then tried creating a timer to keep setting the form.TopMost property to true every 10ms. This sort of works but you still see a very quick blip of the swf file.
Is there some type of Windows API call which can be used to temporarily prevent player.exe from spawning child processes which are visible? I admit it sounds a little far fetched. But, curious if anyone else has had a similar problem.
Addendum:
This addendum is to provide a reply to some of the suggestions layed out in Mathew's post below.
For the emergency situation described in the comments, I would look at possible solutions along these lines:
1) How does the third party application normally get started and
stopped? Am I permitted to close it
the same way? If it is a service, the
Service Control Manager can stop it.
If it is a regular application,
sending an escape keystroke (with
SendInput() perhaps) or WM_CLOSE
message to its main window may work.
Easiest way to close the app is to CTRL-ALT-DEL, then kill process. -OR-
The proper way is to Hold ESC while clicking the left mouse button... then input your username and password, navigate some menu's to stop the player.
There is no PAUSE command... believe it or not.
I don't think using WM_CLOSE will help since minimizing the application doesn't. Would that kill the process also? If not, how do you reopen it.
2) If I can't close it nicely, am I permitted to kill it? If so,
TerminateProcess() should work.
I can't kill the process for two reasons. 1) Upon relaunch you need to supply username/password credentials... There may be a way to get around this since it doesn't prompt when the machine is rebooted but... 2) Whenever I kill the process in task manager it doesn't die gracefully and asks if you want to send an error report.
3) If I absolutely have to leave the other process running, I would try
to see if I can programmatically
invoke fast user switching to take me
to a different session (in which there
will be no competing topmost windows).
I don't know where in the API to start
with this one. (Peter Ruderman
suggests SwitchDesktop() for this
purpose in his answer.)
I got really excited by this idea... I found this article on CodeProject which provides a lot of the API Wrapper methods. I stopped implementing it because I think that in order for desktop's to work you must have explorer.exe running (which I do not).
EDIT2: On second thought... maybe explorer.exe isn't needed. I'll give it a try and report back.
Edit3: Was unable to get the code in that article working. Will have to put this on hold for a moment.
Answer Summary
As one might have expected, there is no simple answer to this problem. The best solution would be to problematically switch to a different desktop when you need to guarantee nothing will appear over it. I was unable to find a simple C# implementation of desktop switching that worked and I had a looming doubt that I would just be opening a whole new set of worms once it was implemented. Therefore, I decided not to implement the desktop switching. I did find a C++ Implementation that works well. Please post working C# virtual desktop implementations for others.
Setting the TopMost property (or adding the WS_EX_TOPMOST style to a window) does not make it unique in the system. Any number of topmost windows may be created by any number of applications; the only guarantee is that all topmost windows will be drawn 'above' all non-topmost windows. If there are two or more topmost windows, the Z-order still applies. From your description, I suspect that flash.exe is also creating a topmost window.
Aside from periodically forcing your window to the top of the Z-order, I think there is little you can do. Be warned, however, that this approach is dangerous: if two or more windows are simultaneously trying to force themselves to the top of the Z-order, the result will be a flickering mess that the user will likely have to use the task manager to escape.
I recommend that your program not attempt to meddle with other processes on the computer (unless that is its explicit purpose, e.g. a task manager clone). The computer belongs to the user, and he may not value your program more highly than all others.
Addendum:
For the emergency situation described in the comments, I would look at possible solutions along these lines:
How does the third party application normally get started and stopped? Am I permitted to close it the same way? If it is a service, the Service Control Manager can stop it. If it is a regular application, sending an escape keystroke (with SendInput() perhaps) or WM_CLOSE message to its main window may work.
If I can't close it nicely, am I permitted to kill it? If so, TerminateProcess() should work.
If I absolutely have to leave the other process running, I would try to see if I can programmatically invoke fast user switching to take me to a different session (in which there will be no competing topmost windows). I don't know where in the API to start with this one. (Peter Ruderman suggests SwitchDesktop() for this purpose in his answer.)
You can use the Process class to start flash.exe directly - and use an appropriate ProcessStartInfo settings to show the window in a hidden state - or with a WindowStyle of hidden or minimized.
You could also consider using the SetWindowsHookEx API to intercept the process start API calls, and when the process is flash.exe run some code to restore you window to top-most status.
Matthew's answer is excellent, but I suspect you may be asking the wrong question. Why does your application need to be topmost? If you're trying to create a kiosk or some such, then topmost is not the way to go.
Edit: After reading your response to Matthew's comment, I'd suggest creating a new desktop and switching to it before displaying your alert. (See CreateDesktop and SwitchDesktop in MSDN.)

Categories

Resources