473,398 Members | 2,088 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,398 software developers and data experts.

Explaination: Window Code

In the following code snipet, what does this code do? Where does it return a
bool to... OS? Does it import a User32.dll library? The code is part of
creating a singleton [tempate] instance of an appication. The complete code
is located at
http://www.c-sharpcorner.com/FAQ/Cre...tanceAppSC.asp
//the Process is the appl that's aready running -want ony one instance
public static void HandleRunningInstance(Process instance)
{
//Make sure the window is not minimized or maximized
ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL);

//Set the real intance to foreground window
SetForegroundWindow (instance.MainWindowHandle);
}

[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

private const int WS_SHOWNORMAL = 1;
}
Nov 16 '05 #1
2 1395
Hi Steve,
"Steve B." <St****@discussions.microsoft.com> schrieb
In the following code snipet, what does this code do? Where does it
return a
bool to... OS? Does it import a User32.dll library? The code is part of
creating a singleton [tempate] instance of an appication. The complete
code
is located at
http://www.c-sharpcorner.com/FAQ/Cre...tanceAppSC.asp
//the Process is the appl that's aready running -want ony one instance
public static void HandleRunningInstance(Process instance)
{
//Make sure the window is not minimized or maximized
ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL);

//Set the real intance to foreground window
SetForegroundWindow (instance.MainWindowHandle);
}

[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

private const int WS_SHOWNORMAL = 1;
}


Almost the same code can be found here:
http://www.bobpowell.net/singleinstance.htm
The code is explained there.

A better possibility to make sure that only one instance of your application
runs at a time using a mutex:
http://www.yoda.arachsys.com/csharp/...ation.instance

Cheers

Arne Janning
Nov 16 '05 #2
Thank you for your response. I'm digesting the info now, great web sites.
My 2 requirements follow:

1. I have a network application. I want users to start the application
from the network but only allow one instance of the application to run on
EACH users machine while, at the same time, allowing various users [on the
network] to execute the application (i.e. different machines).

2. However, within the application is a database (MS-Access) ADO stuff
(DataGrid, etc). For these database forms, in the application, I want only
one network instance running because I'm afraid IF muliple users are saving
or changing database records it will create DataSet problems, etc.

Or I'm I missing something?

Steve

"Arne Janning" wrote:
Hi Steve,
"Steve B." <St****@discussions.microsoft.com> schrieb
In the following code snipet, what does this code do? Where does it
return a
bool to... OS? Does it import a User32.dll library? The code is part of
creating a singleton [tempate] instance of an appication. The complete
code
is located at
http://www.c-sharpcorner.com/FAQ/Cre...tanceAppSC.asp
//the Process is the appl that's aready running -want ony one instance
public static void HandleRunningInstance(Process instance)
{
//Make sure the window is not minimized or maximized
ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL);

//Set the real intance to foreground window
SetForegroundWindow (instance.MainWindowHandle);
}

[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

private const int WS_SHOWNORMAL = 1;
}


Almost the same code can be found here:
http://www.bobpowell.net/singleinstance.htm
The code is explained there.

A better possibility to make sure that only one instance of your application
runs at a time using a mutex:
http://www.yoda.arachsys.com/csharp/...ation.instance

Cheers

Arne Janning

Nov 16 '05 #3

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

Similar topics

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...
2
by: coz | last post by:
I created a wrapper class for a dll written in C. Will the following code prevent the "ENTIRE ARRAY" from being moved, not just the first array element? The Wrapper class will be instantiated in...
0
by: priya | last post by:
hello, I am new to the window hook development area. I found the following code in a link,i am not able to understand this. Please explain me wat this does. The code has the KeyEventArgs and this...
5
by: Andrew Poulos | last post by:
I tested the JSON parse/to code from json.org and it works but I don't understand how. Could someone explain how something in this format works: (function() {...})(); Andrew Poulos
0
by: Joe | last post by:
Hi Could someone give me a simple explaination of this XSD which is a DataSet with relations The tables are fgFAT,e0,e1,e2,e3 which I have deleted I am trying to make sense of the part below...
8
by: josh | last post by:
hi all, If I have an interfacce file i.e. Time.h (where inside it I've #ifndef/ #define / #endif directives) and then an implementation file i.e. Time.cpp in which I include Time.h and then a...
4
by: Drew | last post by:
I recently saw this website: http://www.norvig.com/spell-correct.html All the code makes sense to me save one line: def known_edits2(word): return set(e2 for e1 in edits1(word) for e2 in...
72
by: goacross | last post by:
char ch='a'; int v=sizeof ++ch; cout<<ch<<endl;// output: 'a' why not 'b'? thanks
1
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Found some code that works for me to allow me to highlight text when I re-enter a textbox. I was curious if someone could explain how BeginInvoke is working??? I know it causes execution...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.