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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making my main form the top and active window on the Windows desktop 2

Status
Not open for further replies.

captsnappy

Programmer
Feb 19, 2009
107
US
My exe shows the main form in the Windows desktop but not as the topmost and active window if there are other windows open. I'd like this not to happen.

My main prg has:
SET ESCAPE OFF
SET SYSMENU TO
SET STATUS BAR OFF

It calls a login form then it calls the main form, frmmain, that is
AlwaysOnBottom = .f.
AlwaysOnTop = .f.
ShowWindow = 2 -As Top Form
WindowState = 0 - Normal

and has this in the Init: _SCREEN.Visible=.F.

What am I missing?
 
Thanks for the reply, Mike. Now my main form comes up on top, but, it is Always on top, which I don't want, and it does not come up with the focus, as it were...

Whaddya think?
 
To cure the first problem, set AlwaysOnTop back .F. immediately after you set it to .T.

To give the form focus ... not sure about that. You can't SetFocus on a form. I know you can do it with an API call, but perhaps someone knows an easier way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I haven't tested this, but maybe the following is what you want. Try putting it in the Init of the form:

Code:
DECLARE INTEGER ShowWindow IN Win32API ;
  INTEGER hWnd, INTEGER CmdShow	

ShowWindow(THISFORM.hWnd, 1)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Init would be too soon to call ShowWindow(), wouldn't it? The form isn't "real" until Init returns.

It shouldn't be necessary anyway. Something is messing with the normal processing of stuff here. Is there a control on the form that can accept focus?

(And I think you also need to set .Desktop = .t. on the form.)
 
I set AlwaysOnTop = .t. in the Properties of the main form. Then I put Thisform.AlwaysOnTop = .f. at the end of my Init, right before This.Show(). That makes it appear on top in the Windows desktop. Thanks, Mike.

Dan - I should have mentioned this at first, Desktop=.t. has always been set. I am setting focus on a control right before my Thisform.AlwaysOnTop = .f. in the form's init.

I'll try Mike's API, but I suspect also that this is a workaround for another problem....


 
Mike, the API didn't give the form focus, but at this point having it as the topmost form does (mostly) what I need it to do.

Thanks to both of you.
 
I'm wondering why you're messing with AlwaysOnTop *at* *all*. Was that an attempt to workaround something else that wasn't working?

Ordinarily, you shouldn't have to touch it. When an app runs it is by default "on top". That's just the normal way things work, unless you've messed with something.
 
Dan,

You're right that you shouldn't need to fiddle with AlwaysOnTop, and that the app should be on top by default.

But for some reason that doesn't always happen with VFP apps. I've seen the behaviour that Catpsnappy has observed. Some sort of workaround is usually required.

Also, you're right about the Init being too early for ShowWindow, because the form is still invisible at that piont, but I think calling thisform.Show before the call to ShowWindow should fix that.

I'll experiment with this a bit, when I can find the time.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

Yeah, I keep hearing that "sometimes Fox does this" but it's never done it to *me*. <g>

There's usually a cause, but they can be a bear to discover because it's always the little thing that COULDN'T make a difference so nobody bothers mentioning it. [purpleface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top