views:

685

answers:

1

Hi All,

I'm writing an app in VB.NET that allows the user to call Garmin Mobile XT to get a route.

I've got a form that stays open behind Garmin and upon quitting Garmin, allows the user to go back.

Sometimes, however, this form is automatically hidden by the WM OS.

Any ideas how I can either get the form to stay put - or can I put a check on launching my application to check if the app is already running and the form hidden, and make the form come back to the top?

I've tried setting the form to be TopMost but this then means that the GPS app can't be seen as my form is topmost over the GPS app.

I've tried catching the closing handler for the form but this doesn't fire - I'd guess because WM OS is simply hiding the form and not actually closing it.

I tried a catch on the form Deactivate handler to prevent focus being lost but this then does the same as the TopMost property and I can't see the GPS app.

Anyone any ideas on where I can go from here as I really don't have a clue now!

Thanks, Adam

+1  A: 

I believe this has to be done as in "regular" VB /VBA, through the OS API. Get yourself a winAPI help file :-).

Now I suggest your app iterates all windows, find your GPS app, using:

HWND FindWindow(

LPCTSTR lpClassName,  // pointer to class name
LPCTSTR lpWindowName  // pointer to window name    );

and then you can either change its Z-order (place it above or below some other specific windown):

BOOL SetWindowPos(

HWND hWnd,    // handle of window
HWND hWndInsertAfter, // placement-order handle
int X,    // horizontal position
int Y,    // vertical position
int cx,   // width
int cy,   // height
UINT uFlags   // window-positioning flags    );

, or just ask to restore it (which should automatically bring it to highest Z-order) using:

BOOL SetWindowPlacement(

HWND hWnd,    // handle of window
CONST WINDOWPLACEMENT *lpwndpl    // address of structure with position

data );

jpinto3912