473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Window Handler issue

We are trying to bring the window on top if its already running(Restore). The
code works fine 90% of the time but sometimes it does not. The reason it does
not work at times is coz the window handle is not returned. need confirmation
on this.

Any help would be greatly appreciated.

Code as follows:
==================================================
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);
[STAThread]
static void Main()
{
try
{
// get the name of our process
string proc = Process.GetCurrentProcess().ProcessName;
// get the list of all processes by that name
Process[] processes = Process.GetProcessesByName(proc);
Process.GetCurrentProcess().StartInfo.WindowStyle =
ProcessWindowStyle.Maximized;
// if there is more than one process...
if (processes.Length 1)
{
// get the window handle
IntPtr hWnd = processes[0].MainWindowHandle;
// if iconic, we need to restore the window
if (IsIconic(hWnd))
{
ShowWindowAsync(hWnd, 9);
}
// bring it to the foreground
SetForegroundWindow(hWnd);
return;
}
else
{
//Added for checking registry entry proper or not
if (CheckForInstallation())
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new frmLogin());
}
else
{
MessageBox.Show(AppGlobalization.GetText("InstallE rror"),
AppGlobalization.GetText("Error"), MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
}
}
}
catch (Exception ex)
{
General.ShowInformation("Application Operations Failed -Main(Program.cs): "
+ ex.Message + " " + "[" + ex.StackTrace + "]", false);
}
}

Dec 7 '07 #1
1 1568
"Sriman" <Sr****@discussions.microsoft.comschrieb
We are trying to bring the window on top if its already
running(Restore). The code works fine 90% of the time but sometimes
It works 0% of the time. ;) This is a VB.Net group.
Armin
Dec 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Foehammer | last post by:
I have the following snippet of code: function ShowTutorial(tutorialPath) { var ret = showModalDialog(tutorialPath, '', 'dialogWidth:' + screen.width + '; dialogHeight: ' + screen.height + ';...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
1
by: Feng | last post by:
Hi, Need help on the following issue. We need to clean up some session specific backend resource when a user ends his session. We have a "Logoff" button on the pages that handles that. But...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
3
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have window.status="Moomin"; why doesn't the statusbar change?...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
1
by: chitra g | last post by:
Hi, I tried all the options below but did not work. Your suggestions please.
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I POST a form to a new window? ----------------------------------------------------------------------- ...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.