Link to home
Start Free TrialLog in
Avatar of trondsorensen
trondsorensen

asked on

SetWindowPos

I made a application consisting of a borderless nomoveable window wich I want to always stay behind all other applications.
The idea is to make it behave as part of the desktop.

The code I use is as follows:

In module:
Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Global Const HWND_TOPMOST = -1
Global Const HWND_NOTOPMOST = -2
Global Const HWND_BOTTOM = 1
Global Const HWND_DESKTOP = 0


In form declaration:
Dim Success%

On every object and event
    Success% = SetWindowPos(frmMain.hWnd, HWND_BOTTOM, 0, 0, 0, 0, Flags)

This works, but not as if the program was part of the desktopp.
Sometimes it pops to the front when I start other programs like
Novell NDS Manager.
Other times when I drag the scrolbar on a textbox on the application it pops to the front.
What does the HWND_DESKTOP do?

Is there another way to get the effect I am looking for?
Avatar of trondsorensen
trondsorensen

ASKER

Edited text of question.
Are you doing:

 Success% = SetWindowPos(frmMain.hWnd, HWND_BOTTOM, 0, 0, 0, 0, Flags)

on mousemove, mouseup events and scroll events?

Cheers!
You may want to consider adding a TimerEvent to your form that will also execute the SetWinsowPos...

Cheers!
I am doing the code on every (All) events.
I have thought about adding it to a timer, but I dont think it is a good way of coding. How much processortime will it take up?
It will take up processor time, but I think thats going to be your only way to get it to work...


Cheers!
If you subclass the form, couldn't you intercept the appropriate windows messages and call SetWindowPos in the new WndProc?
Whoa, Eric, the two of us are abiously in two defferent planets here ;) I almost dont know what you are talking about.
Can you please explain a little betther?
Subclassing allows your application to intercept Windows messages that are not exposed thru VB.  The following MS article explaines how to determine when your app gains focus.  You might be able to send your window to the background each time Windows sends the WM_ACTIVATEAPP message.  Just a theory.

"HOWTO: Determine When Your Application Gains or Loses Focus"
http://support.microsoft.com/support/kb/articles/Q186/9/08.ASP
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial