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!

How to force form on top of all windows 2

Status
Not open for further replies.

dbero

Technical User
Mar 31, 2005
109
US
I use some auto-shutdown code to detect db inactity. A form opens to notify the user. However, the new form opens on top of access, not on top of other windows. Is it possible to force the opening form to open on top of all other windows?

Thank you!
 
Simple answer, no.

The whole idea of windows and any other modern OS is based upon multitasking so it doesn't make much sense to provide mechanism whereby a process / application can grab the undistracted attention of the user.

You can prevent YOUR application moving onwards with the Modal and popup properties set to true but it's unfair to try and cease all other processes.

If you want to be a royal pain in the arse you could look at doing some stuff with the on timer event ;)

Laterz mate
 
JBinQLD said:
The whole idea of windows and any other modern OS is based upon multitasking so it doesn't make much sense to provide mechanism whereby a process / application can grab the undistracted attention of the user.

It's been forever since I've played with the windows API, but I am pretty sure you can force your app to have focus. As to your quote directly, doesn't Windows itself do this often?

I'm gonna say maybe you can. Unless, JBinQLD can give an authoritative reference.



One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Mate, it's possible for sure but by "Simple answer..." I meant just that. And I still stand by my ssttatement of it not making much sense to povide a mechansim for an application to cease all others.

The OS, being the daddy of all these processes perhaps can perhaps have a reason to stop everyone doing everything, but that's the glory of being an OS rather than an application running under/within an OS.

Naturally, these are just my thoughts, I just chuck 'em out there for consideration - after all, although it IS possible, maybe dbero will now recapitulate about whether this is truely a good idea or not.

Laterz all :)
 
JBinQLD,

Man I misread stuff all the time. But is dbero asking to cease all other applications? Is there another reasonable alternative if an application truly cannot be brought to focus?

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
dbero,

Try this:

In a module put this code
Code:
Private Declare Function SetWindowPos Lib "user32" _
         (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, _
          ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1


Public Function PutMyAppOnTop(pFrm As Form)
  Dim lngWindowPosition As Long
  
  lngWindowPosition = SetWindowPos(pFrm.hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

End Function

Call it from a form like this:
Code:
Call PutMyAppOnTop(frmExitNonUse)

This will force the form to have the focus and the user can not click on another form. They are forced to deal with the form to make it "go away".
 
ahh...hit post to soon...

I use this in several applications. Why? It's a suttle reminder to the user that if you don't need me then please close me. I also use it in places where the users are updating information that will be visible to others once complete. Keeps them from getting to far side tracked. Is it annoying or bothersome. I've never had anyone complain about it.
 
jadams0173,

I thought there was a way, I looked for JBinQLD, but it had just been too long since I have played with the windows API to find the right stuff. Well done.

Now, I was playing around with you code some, and I have a question for you (as a note, I was using the hwnd for Access not just a form).

Code:
Option Compare Database

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Const WM_SYSCOMMAND = &H112
Const SC_MAXIMIZE = &HF030&
Const SC_MINIMIZE = &HF020&

And then I make the call for them inside one of my functions this way:

Code:
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MAXIMIZE, 0

SetWindowPos Application.hWndAccessApp, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE

This way, I first maximize Access, then bring it to the front. I also included the constants for minimizing and for notopmost, just in case you needed to undo some of those changes. i.e.

Code:
SetWindowPos Application.hWndAccessApp, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE

Now, here is my question:

I looked up SWP_NOMOVE and SWP_NOSIZE at MSDN and I don't understand what you personally accomplish with them in your code. I messed around with them some, but apparently just don't understand those parameters. Could you explain them and your use of them to me?

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Edit: I meant "I looked for [red]dbero[/red]" not "I looked for JBinQLD".

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
SWP_NOMOVE retains the current position. It ignores the X and Y parameters in the call.

SWP_NOSIZE Retains the current size. It ignores the cx and cy parameters in the call


Otherwise you could pass in values for the variables and change the position and size of the form.
 
Okay, so, if it was minimized, I would have to either maximize it first then make that call or I would not use those flags and use the other parameters to set it position, right?

Would you just put 0 in place of SWP_NOMOVE and SWP_NOSIZE if you are resizing it this way?

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top