Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get HWND of previously running app.

Status
Not open for further replies.

LPlates

Programmer
Jun 5, 2003
554
AU
How can i get the HWND from the previously running app?
I can call a function to find out if there is a prevoius instance of my app. running but Im trying to find the HWND of that previous instance, any ideas?
From the hPreviousInstance ?

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
 
In Win32API it is quite impossile. There is an other method to do it:
This is a piece of one of my servers. "IonFilipski-db2orb-v3-server" is just a name for a segment which could be any other names. The segment with this name is shared and variables inside it are accessible to any applications using this segment. If the flag isRunningAlready is true, show server window and exit application. So will be shown only the first instance of application. You should add explicitly /section:IonFilipski-db2orb-v3-server,rws to the linker. RWS means read/write/shared.


.....
#pragma data_seg("IonFilipski-db2orb-v3-server")
//begin of segment
static bool isRunningAlready = false;
HWND hServerWnd = 0;
#pragma data_seg() //end of segment
....
//linker:/section:IonFilipski-db2orb-v3-server,rws

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
if(!isRunningAlready)
{
isRunningAlready = true;
}else
{
if(hServerWnd)
{
ShowWindow(hServerWnd, SW_SHOW);
SetForegroundWindow(hServerWnd);
}
return 0;
}
.....
...
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
put this directive in your code to make it running:

#pragma comment(linker, "/section:IonFilipski-db2orb-v3-server,rws")

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top