• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1687
  • Last Modified:

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?
0
trondsorensen
Asked:
trondsorensen
  • 3
  • 3
  • 2
  • +1
1 Solution
 
trondsorensenAuthor Commented:
Edited text of question.
0
 
mcriderCommented:
Are you doing:

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

on mousemove, mouseup events and scroll events?

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

Cheers!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
trondsorensenAuthor Commented:
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?
0
 
mcriderCommented:
It will take up processor time, but I think thats going to be your only way to get it to work...


Cheers!
0
 
Erick37Commented:
If you subclass the form, couldn't you intercept the appropriate windows messages and call SetWindowPos in the new WndProc?
0
 
trondsorensenAuthor Commented:
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?
0
 
Erick37Commented:
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
0
 
Bob LearnedCommented:
You can use SWP_NOACTIVATE = &H10, that will not activate the window, and bring it to the top.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now