home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / articles / vbbultn / source / topmost.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-03-01  |  2.0 KB  |  60 lines

  1. VERSION 2.00
  2. Begin Form TopForm 
  3.    Caption         =   "Always On Top"
  4.    ClientHeight    =   2025
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   4380
  8.    Height          =   2430
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2025
  12.    ScaleWidth      =   4380
  13.    Top             =   1140
  14.    Width           =   4500
  15.    Begin CommandButton Command1 
  16.       Caption         =   "Close"
  17.       Height          =   525
  18.       Left            =   1530
  19.       TabIndex        =   1
  20.       Top             =   1350
  21.       Width           =   1245
  22.    End
  23.    Begin ListBox List1 
  24.       Height          =   1005
  25.       Left            =   1530
  26.       TabIndex        =   0
  27.       Top             =   210
  28.       Visible         =   0   'False
  29.       Width           =   1245
  30.    End
  31.    Begin ccSubClass SubClass1 
  32.       CtlParam        =   "TopForm"
  33.       Left            =   450
  34.       Messages        =   TOPMOST.FRX:0000
  35.       Top             =   1200
  36.    End
  37. Option Explicit
  38. Declare Sub SetWindowPos Lib "user" (ByVal hWnd%, ByVal hwndinsertafter%, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, ByVal wFlags%)
  39. Dim msgcount As Integer
  40. Sub Command1_Click ()
  41. Unload Me
  42. End Sub
  43. Sub SubClass1_WndMessage (wnd As Integer, msg As Integer, wp As Integer, lp As Long, retval As Long, nodef As Integer)
  44. Static settop As Integer    'need this to prevent infinite loop
  45.     If settop Then  ' we're in the process of setting this window to topmost
  46.         settop = False
  47.         Exit Sub
  48.     End If
  49.     ' FYI - Shows how many times this message is processed
  50.     List1.AddItem Str$(msgcount)
  51.     List1.ListIndex = msgcount
  52.     msgcount = msgcount + 1
  53.     'calling the SetWindowPos API function triggers a WM_WINDOWPOSCHANGING
  54.     'message, set a flag to prevent infinite loop
  55.     settop = True
  56.     ' set topmost window
  57.     SetWindowPos TopForm.hWnd, -1, 0, 0, 0, 0, 3
  58.     nodef = True
  59. End Sub
  60.