PDA

Click to See Complete Forum and Search --> : Why is it different


Paul Warren
Nov 3rd, 2000, 05:44 AM
Does anyone know why this works for VB 5&6 but not with 4 ?


Private Declare Function SetWindowPos Lib "user32" (ByVal h%, ByVal hb%, ByVal X%, ByVal Y%, ByVal cx%, ByVal cy%, ByVal f%) As Integer

Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Public Sub Make_Top()
' Make sure the user cannot send the form to the back and ignore it

Dim lngRes As Long

lngRes = SetWindowPos(PCDetails.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)

End Sub


It's a damn useful bit of code which I picked up from somewhere ( can't remember where ) so if anyone wants to use it, feel free.

Thanks for any help.

paulw
Nov 3rd, 2000, 05:58 AM
This API returns a Long - might it be the declaration As Integer?

I have a feeling that I know this but the mists of time have clouded my memory somewhat. I'll have a dig...

Cheers,

Paul.

rfo
Nov 3rd, 2000, 07:10 AM
I don't know why it works in VB5, but you should use this declare in a 32-Bit app.


Declare Sub SetWindowPos Lib "user32" (ByVal hwnd&, ByVal hWndInsertAfter&, ByVal X&, ByVal Y&, ByVal cx&, ByVal cy&, ByVal wFlags&)

Paul Warren
Nov 3rd, 2000, 08:03 AM
I've copied the correct declare from the API viewer, complete with the long datatype and all the correct parameters but it still returns a code of 1. This is the declare I've used :


Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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


Thanks for looking at it guys.

Paul Warren
Nov 3rd, 2000, 08:14 AM
Now it's working ! Something I've changed has done the trick. Thanks for your help guys.

Here's the final code if you want ot use it :


Option Explicit

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

Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Public Sub Make_Top()
' Make sure the user cannot send the form to the back and ignore it

Dim lngRes As Long

lngRes = SetWindowPos(PCDetails.hwnd, HWND_TOPMOST, 0, 0, 1, 1, FLAGS)

End Sub



thanks again.