Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Forms Code Examples

How to make a form stay 'on top' of all other windows 32bit.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
How to make a form stay 'on top' of all other windows 32bit. 'This version has been tested with VB4-32 'Here's a cool little API function for VB4 on Win 32s. 'It basically allows a window to "Always be on top" This goes in the declarations section of a module Global Const SWP_NOMOVE = 2 Global Const SWP_NOSIZE = 1 Global Const HWND_TOPMOST = -1 Global Const HWND_NOTOPMOST = -2 Global Const FLOAT = 1, SINK = 0 Public Declare Sub 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) This is a sub within the module Sub FloatWindow(X As Integer, action As Integer) ' When called by a form: ' ' If action <> 0 makes the form float (always on top) ' If action = 0 "unfloats" the window. ' Dim wFlags As Integer, result As Integer wFlags = SWP_NOMOVE Or SWP_NOSIZE If action <> 0 Then ' Float Call SetWindowPos(X, HWND_TOPMOST, 0, 0, 0, 0, wFlags) Else ' Sink Call SetWindowPos(X, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags) End If End Sub Then to call the procedure you use this code Dim f as integer f = Screen.ActiveForm.hWnd Call FloatWindow(f, FLOAT) to "float" the form, ie. allways ontop or Dim f as integer f = Screen.ActiveForm.hWnd Call FloatWindow(f, SINK) to sink. Alternatively instead of Screen.ActiveForm.hWnd you can specify a window, ie Me.hWnd to float/sink the current form.