home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / system / nomove / nomove.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-02-26  |  5.6 KB  |  152 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    ClientHeight    =   2040
  5.    ClientLeft      =   2130
  6.    ClientTop       =   2865
  7.    ClientWidth     =   3405
  8.    ControlBox      =   0   'False
  9.    Height          =   2565
  10.    KeyPreview      =   -1  'True
  11.    Left            =   2070
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2040
  16.    ScaleWidth      =   3405
  17.    Top             =   2400
  18.    Width           =   3525
  19.    Begin Image Image1 
  20.       Height          =   300
  21.       Index           =   2
  22.       Left            =   900
  23.       Picture         =   NOMOVE.FRX:0000
  24.       Tag             =   "0"
  25.       Top             =   540
  26.       Visible         =   0   'False
  27.       Width           =   300
  28.    End
  29.    Begin Image Image1 
  30.       Height          =   300
  31.       Index           =   1
  32.       Left            =   450
  33.       Picture         =   NOMOVE.FRX:05CA
  34.       Tag             =   "0"
  35.       Top             =   540
  36.       Visible         =   0   'False
  37.       Width           =   300
  38.    End
  39.    Begin Label Label1 
  40.       Caption         =   "Label1"
  41.       FontBold        =   -1  'True
  42.       FontItalic      =   0   'False
  43.       FontName        =   "MS Sans Serif"
  44.       FontSize        =   9.75
  45.       FontStrikethru  =   0   'False
  46.       FontUnderline   =   0   'False
  47.       Height          =   285
  48.       Left            =   630
  49.       TabIndex        =   0
  50.       Top             =   90
  51.       Width           =   720
  52.    End
  53.    Begin Image Image1 
  54.       Height          =   300
  55.       Index           =   0
  56.       Left            =   0
  57.       Picture         =   NOMOVE.FRX:0B94
  58.       Tag             =   "0"
  59.       Top             =   0
  60.       Width           =   300
  61.    End
  62. Dim SavedHeight As Integer ' required to re-adjust form height
  63.                            ' after caption is added or removed
  64. Dim SavedTop As Integer    ' required to re-adjust form top
  65. Dim MouseX As Integer, MouseY As Integer
  66. 'evaluates mouse coordinates to determine if popup should pop up.
  67. Sub Form_KeyUp (KeyCode As Integer, Shift As Integer)
  68. 'this sub allows the user to access the system menu
  69. 'by keying Alt+Space, or to close the form by keying Alt+F4.
  70.     Const ALT_MASK = 4
  71.     Const KEY_F4 = 115
  72.     Const KEY_SPACE = 32
  73.     If Shift = ALT_MASK Then
  74.         Select Case KeyCode
  75.         Case KEY_F4:  End
  76.         Case KEY_SPACE
  77.             Image1_Click 0
  78.         End Select
  79.     End If
  80. End Sub
  81. Sub Form_Load ()
  82. 'This project is in response to a question posed by another MSBASICS
  83. 'forum member: "How can I create a nonmovable window which still has
  84. 'a control box, title bar and minimize button?"
  85. 'This project demonstrates the creation of a form which cannot
  86. 'be moved by the user, even though it has a control menu and
  87. 'title bar.  This is achieved by simulating the control menu and
  88. 'title bar with an image and a label.  I didn't address the minimize
  89. 'button since that can be faked with a bitmap.  I simply added the
  90. 'minimize option to the popup menu.
  91. 'There are two forms in this project; Form1 is visible with no menu,
  92. 'while the invisible Form2 contains a menu for popup use by Form1.
  93. 'Form_Load sets up the visible form, which contains
  94. 'Image1 to hold the control menu bitmap, and label1, which
  95. 'simulates the title bar.  When the user clicks Image1, a
  96. 'popup menu is shown using a menu from the hidden Form2.
  97. 'After Form1 is minimized there is no control menu which appears when
  98. 'the icon is clicked, but a double-click still restores it.
  99. 'THIS IS A BIG KLUGE JOB and I don't guarantee that it's the best
  100. 'solution. I merely got bitten by the 'figure it out if you can' bug.
  101. 'I hope this is helpful and informative, at the least.  If you have any
  102. 'questions, please feel free to email me!
  103. ' Barry Seymour
  104. ' Marquette Computer Consultants
  105. ' CIS 70413,3405
  106.     Const ACTIVE_TITLE_BAR = &H80000002
  107.     Const TITLE_BAR_TEXT = &H80000009
  108.     'setup Form1...
  109.     Me.Caption = ""
  110.     Me.KeyPreview = True
  111.     'position Image1
  112.     Image1(0).Left = Screen.TwipsPerPixelX * -1
  113.     Image1(0).Top = Screen.TwipsPerPixelY * -1
  114.     'position, setup Label1
  115.     Label1.FontName = "System"
  116.     Label1.FontSize = 9.25
  117.     Label1.ForeColor = TITLE_BAR_TEXT
  118.     Label1.BackColor = ACTIVE_TITLE_BAR
  119.     Label1.Left = Image1(0).Left + Image1(0).Width
  120.     Label1.Top = 0
  121.     Label1.Height = Image1(0).Height - Screen.TwipsPerPixelY
  122.     Label1.Width = ScaleWidth - Image1(0).Width + Screen.TwipsPerPixelX
  123.     Label1.Alignment = 2 'centered
  124.     Label1.Caption = "Unmovable Form Demo"
  125.     SavedHeight = Me.Height ' form-level var
  126.     SavedTop = Me.Top ' form-level var
  127.     Load Form2 ' don't show it.
  128. End Sub
  129. Sub Form_Resize ()
  130.     Static resizing As Integer
  131.     If resizing Then Exit Sub Else resizing = True
  132.     If Me.WindowState = 0 And Me.Caption <> "" Then
  133.         'form was just restored.  Clear it's caption and ensure
  134.         'it's correctly sized and positioned. (Required because
  135.         'form height & Top change when caption is removed)
  136.         Me.Caption = ""
  137.         Me.Height = Me.Height + Label1.Height
  138.         Me.Top = Me.Top - Label1.Height
  139.     End If
  140.     resizing = False
  141. End Sub
  142. Sub Image1_Click (Index As Integer)
  143.     'Yields the popup menu
  144.     Image1(0).Picture = Image1(1).Picture
  145.     PopupMenu Form2.mnuMain, 0, Image1(0).Left, Image1(0).Top + Image1(0).Height - Screen.TwipsPerPixelY
  146.     Image1(0).Picture = Image1(2).Picture
  147. End Sub
  148. Sub Image1_DblClick (Index As Integer)
  149.     'closes the program
  150.     End
  151. End Sub
  152.