open a .exe as a window in an mdi form? - c#

I wanted to create a program that would allow me to open instances of a already exsiting program (i just have the exe) as windows inside (i belive its called mdi)
Is that something i could do? can anyone point me to an example?
Thanks

Maybe this is the answer you are looking for here. It can be done...look in the sample on that link given.
Hope this helps,
Best regards,
Tom.

When Windows starts a program its parent is the Desktop Window.
If you could somehow manipulate that, it may work.
However, I doubt it is possible, as why would I want to allow you to run my application in your window? Especially MDI? Besides that - running in a child window isn't quite the same as running in the "main" window.
Having said that there is an application out there (can't think of it's name OH) that does place individual applications in tabs. Pretty nifty if you're not on Windows 7. The folks over at the Business of Software forum might be able to help you find it.

Well, after starting the app and storing its PID, you could start monitor the windows that get created, either thru a CBTHook or by just using a timer and the GetWindows to find when a top level window gets created by the PID in question.
Then you can use SetParent to make that window a child to your MDIChild (I doubt you can make it your MDIChild directly).
That should get you going. What you'll run into after that I really don't know. I guess you must correlate any movement of either your app or the external app so that thir windows appears to be stuck together...
Maybo you could strip away the caption from the external app (Get/SetWindowsLong). That could make it look better...

Related

How to be OnTop but not OnTop of a full screen application

So I have tried searching for the better part of a day for the answer to a simple question. I want my C# application to popup another winform on a timer and then close it after a delay. Simple enough, done and done. Now my issue is that I want it to actually be on top of other applications UNLESS they are full screen. By that I mean a true full screen application such as a game. I do not want to interfere with such an application since it should take priority over my application.
The issue is that I am using the 'OnTop' property on the popup form and, while it works perfectly for any other applications I have been testing it while playing a full screen game and the form, when it "Show()"s, takes the full screen application and drops it into windowed mode.
Is this the intended effect of the 'OnTop' property with full screen applications? If so is there a way that I can have my form popup on top of normal windowed windows and not interfere with full screen applications?
Any links, example, a kick in the general direction is great. The only hits that I come up with when searching for winforms involving full screen is people trying to get their application into full screen or having their application take focus away from another application.
Thanks on advance.
(I didn't post any code due to it just being a simple winform that is "formX:Show()" on a timer with the "onTop" property set)
(EDIT) So thanks to awilson53 for putting me on the right track I was able to find a method (albeit somewhat picky) to determine if an application is full screen. Seems kinda simple, and an "well duh", answer after all is said and done.
95% of the credit goes to the author of the article: http://www.richard-banks.org/2007/09/how-to-detect-if-another-application-is.html
~5% goes to awilson53 for getting me on the right track. :)
Check out this wrapper for the EnumWindows function. This will allow you to enumerate all open windows and determine their window state. You will want to check the EnumWindowItem.Maximized property, and if it is true set your OnTop property to false. If none of the EnumWindowItem's return Maximised you can set OnTop to true.

Multimonitor taskbar in .Net

I have an idea to write a multimotor taskbar application in c# for windows xp. So, does anyone have any information how
to put a taskbar on the second
monitor,
to make it use windows styles,
to prevent aplications running on the
second monitor to appear in default
taskbar,
so on...
Any help would be ...helpful )))
You can P/Invoke SHAppBarMessage() to create a task bar. The APPBARDATA.hWnd you'll need could simply be the Handle of a Form class. Anything goes as far as what you display.
Getting the notifications you'll need to make the task bar display active windows is going to be a whole lot more difficult. You'll need to use the global WH_SHELL hook, set by SetWindowsHookEx() to receive the notifications you'll need. You cannot set this hook in C#, it requires an unmanaged DLL that you can inject into a process. You'll find crucial help in this project.
Getting the Windows taskbar to not do its normal job is going to be impossible unless you somehow find the undocumented information you'll need. Microsoft doesn't document this for a good reason, the taskbar is an important part of the way they innovate on the Windows look-and-feel. Quite visible in Win7. They don't want any code to take a dependency on this, they'd have a near-impossible job of keeping the next version of Windows compatible. I'd have to recommend you completely disable the Windows taskbar and replace it by your own.

How can you read values from an open application in Windows?

I want to create a program or use a program that will read the memory values out of another application. Does anyone know of an application/library that will do this?
The target app is this. I would like to read the exchange rate values from it.
I'm an experienced c# programmer, but have never worked with the Win32/user32 api which is what I'm assuming I'll have to deal with to pull this off.
Any help that gets me going in the right direction is greatly appreciated.
Update:
I managed to use Spy++ to get the window handle, so I'm sure I can get the values some how.
Have you looked into AutoIT or AutoHotKey?
Both of these open source options have well documented abilities to read text from application windows (and send keystrokes or mouseclicks to them).
AutoIT is very easy to use and well documented.
An example of reading text from a window would be:
$text = WinGetText("title of window", "")
MsgBox(0, "Text read was:", $text)
This can be compiled into an executable.
Typically an application creates controls in a dialog in a consistent manor, same ID, same order etc, so finding a control programatically is fairly simple. Using Spy++ find the control's ID and then you can search the windows created by the application for the desired control. Not being familiar with the app in question I cannot give specifics, but if Spy++ shows the value you desire, it is likely not difficult to obtain the value in your code.
What type of control is the value displayed in? You'll may be able to use GetDlgItemText to obtain the value once you have the parent window handle and control ID? To get the parent window try using EnumWindows.
It might be easier to scrape their data by automating a screenshot and then ocr process. If that's your goal.
Potentially relevant links:
get-a-screenshot-of-a-specific-application
ocr-with-the-tesseract-interface
May be this article helps - http://msdn.microsoft.com/en-us/magazine/cc163617.aspx, but I think it's not universal and for your task is better to get access directly to Forex API/Web-Service or try to catch needed data on network.
It is possible to screen-scrap things created with native windows controls; if that is the case, you should be able to see the controls using Spy++. But some times controls are implemented "by hand", and there is no way to screen-scrap them (e.g. some Java graphic toolkits play directly with the graphics, so everything day do is meaningless from the outside, or even some Office menus are implemented without using the menu control).
The Windows accessibility API is a possible way to screen-scrap the values; check if "Narrator", the screen reader that comes with windows, is able to read aloud your target application.

Closing a Windows Mobile Console Application

What is the best and cleanest way to close a console application on windows mobile?
The application by default is invisible and you cannot see it in the running programs, which is great for running a background process, but sometimes the user might need to close it..
Exit Main. Seriously. If you need someone to be able to exit is manually, there needs to be some mechanism like a shell icon and menu or a program in the Programs folder of something. How else would the user even know it's running? Any one of those visual cues would then set a named system event, and inside your Console app you'd have something listening for the same event (likely a worker). When it gets set, you take the actions required to shut down.
How would a user be able to close it if the application is not visible in the UI?
That's a great question. I once spent a long time trying to figure this out. Of course, we are assuming you can not (easily) return from Main. The correct answer on the desktop is System.Environment.Exit; But that method is conveniently not supported on CF.
An apparent second option is Application.Exit. That is on CF, but only applies to WinForms, and is in fact not guaranteed to exit your application.
So, throw an unhandled exception. ;)
EDIT: To kill it programatically from another app, you can look at Process.GetProcessById, and Process.Kill. Both of these are available on CF. You will have to somehow let the "killer" app figure out the "victim"'s ID. More convenient methods like Process.GetProcessesByName are not available on CF.
This technique isn't that elegant, though, and there may be permissions issues.
You could also consider some kind of IPC (inter-process communication), perhaps one overviewed in this previous Windows Mobile answer.
I decided to to read a boolean (keep alive) in the config file and have another application set it to false when I want to exit.
Its not that responsive but at least I can exit cleanly..

How can we prevent popup windows appearing on top of the application?

I have a fullscreen window, and I want to prevent pop up windows that appear at the right bottom corner of my screen. I set the Topmost property to true, but apparently it does not help. I also tried activating the form and giving it the focus once it got deactivated, but that did not help either. What is a way to ignore such windows while the user is engaged with the fullscreen app? I am .NET programming in C#.
You can't do it, this fails the "what if two programs tried to do this" test:
those popups are just normal windows like yours, they also use the same top-most style you are using.
if there was a way to always be above other topmost windows they would have used it too rendering it useless (because the authors of the other apps are just as concerned about the user missing their "super important" notifications as you are about them interfering with your full screen app).
You can try and play dirty tricks to force your window to the top of the top-most z-order, but those popups are likely to use the exact same tricks, again making this all useless (and as an extra bonus all those dirty tricks can turn your app into a compatibility nightmare).
You can disable these balloon notifications using these steps:
Click Start, Run and type regedit
Navigate to the following subkey:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
In the right pane, create a DWORD value named EnableBalloonTips
Double-click the new entry, and give it a value of 0.
Quit Registry Editor.
Log off Windows (this is not very cool...), and then log back on for the changes to take effect.
if you need help in how doing this by program, don't hesitate to ask ;)
I don't think that you can block all the popups, windows might not let you do that. But you can try with SetWindowPos function and pass it HWND_TOP parameter. It might work a little better than Topmost = true.
I used a sys tray popup control on my personal project SvnRadar written in WPF.
The control is at the http://www.hardcodet.net/projects/wpf-notifyicon written by Philipp Sumi.
Very nice.Only thing you will be need to "detach" it from the SysTray screen coordinates and
make it appear where you wish.
Hope it helps.
Good luck.

Categories