home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / pgm_util / move2 / move.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-10  |  10.1 KB  |  241 lines

  1. VERSION 2.00
  2. Begin Form WinStyles 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Windows Style Manipulations"
  5.    Height          =   7035
  6.    Icon            =   MOVE.FRX:0000
  7.    Left            =   945
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   6630
  10.    ScaleWidth      =   7365
  11.    Top             =   1200
  12.    Width           =   7485
  13.    Begin PictureBox Picture3 
  14.       BackColor       =   &H0000FFFF&
  15.       Height          =   855
  16.       Left            =   480
  17.       ScaleHeight     =   825
  18.       ScaleWidth      =   2805
  19.       TabIndex        =   6
  20.       Top             =   5580
  21.       Width           =   2835
  22.    End
  23.    Begin PictureBox Picture2 
  24.       AutoRedraw      =   -1  'True
  25.       Height          =   855
  26.       Left            =   3960
  27.       ScaleHeight     =   825
  28.       ScaleWidth      =   2865
  29.       TabIndex        =   5
  30.       Top             =   5580
  31.       Width           =   2895
  32.    End
  33.    Begin TextBox Text2 
  34.       Height          =   975
  35.       Left            =   3960
  36.       TabIndex        =   4
  37.       Text            =   "Text2"
  38.       Top             =   4500
  39.       Width           =   2895
  40.    End
  41.    Begin CommandButton Command1 
  42.       Caption         =   "Push me !"
  43.       Height          =   975
  44.       Left            =   480
  45.       TabIndex        =   3
  46.       Top             =   4500
  47.       Width           =   2835
  48.    End
  49.    Begin TextBox Text1 
  50.       Height          =   975
  51.       Left            =   480
  52.       TabIndex        =   2
  53.       Text            =   "Text1"
  54.       Top             =   3300
  55.       Width           =   6375
  56.    End
  57.    Begin ListBox List1 
  58.       Height          =   2760
  59.       Left            =   3960
  60.       TabIndex        =   1
  61.       Top             =   360
  62.       Width           =   2895
  63.    End
  64.    Begin PictureBox Picture1 
  65.       AutoRedraw      =   -1  'True
  66.       FontBold        =   0   'False
  67.       FontItalic      =   0   'False
  68.       FontName        =   "MS Sans Serif"
  69.       FontSize        =   8,25
  70.       FontStrikethru  =   0   'False
  71.       FontUnderline   =   0   'False
  72.       ForeColor       =   &H000000FF&
  73.       Height          =   2775
  74.       Left            =   480
  75.       Picture         =   MOVE.FRX:0302
  76.       ScaleHeight     =   2745
  77.       ScaleWidth      =   2865
  78.       TabIndex        =   0
  79.       Top             =   360
  80.       Width           =   2895
  81.    End
  82. ' * You nneed the MOVE.BAS as well ! *
  83. Option Explicit
  84. Dim retInt%, retLng&
  85. Dim oldX%, oldY%
  86. Sub Command1_Click ()
  87.     MsgBox "If you hold down Ctrl you can even move me !", 64, "Notice"
  88. End Sub
  89. Sub Command1_DragOver (Source As Control, X As Single, Y As Single, State As Integer)
  90. ' --> from VB3 used the Mouse_Move event !
  91.     ' this pice of code enables ANY concerned control to be moved freely --> even an entire form !
  92.     ReleaseCapture
  93.     retInt = SendMessage(Command1.hWnd, WM_SYSCOMMAND, MOUSE_MOVE, 0&)
  94. End Sub
  95. Sub Command1_KeyDown (KeyCode As Integer, Shift As Integer)
  96.     ' can be move when Ctrl in pressed !
  97.     If Shift = 2 Then Command1.DragMode = 1
  98. End Sub
  99. Sub Command1_KeyUp (KeyCode As Integer, Shift As Integer)
  100.     Command1.DragMode = 0
  101. End Sub
  102. Sub Form_Load ()
  103.     SetControls
  104.     Show
  105.     ' after the the form build we can insert a text now...
  106.     SetTexts
  107. End Sub
  108. Sub List1_Click ()
  109.     List1.Clear
  110.     For retInt = 1 To 20
  111.         List1.AddItem "Item #" & retInt
  112.     Next retInt
  113. End Sub
  114. Sub List1_GotFocus ()
  115.     ShowFocus List1
  116. End Sub
  117. Sub List1_LostFocus ()
  118.     ShowFocus List1
  119. End Sub
  120. Sub Picture1_GotFocus ()
  121.     ShowFocus Picture1
  122. End Sub
  123. Sub Picture1_LostFocus ()
  124.     ShowFocus Picture1
  125. End Sub
  126. Sub Picture2_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  127.     ' this should only be possible for the LEFT mouse key as usual.
  128.     If Button <> 1 Then Exit Sub
  129.     ' this pice of code enables ANY concerned control to be moved freely --> even an entire form !
  130.     ReleaseCapture
  131.     retInt = SendMessage(Picture2.hWnd, WM_SYSCOMMAND, MOUSE_MOVE, 0&)
  132. End Sub
  133. Sub Picture3_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  134. If Button <> 1 Then Exit Sub
  135. Picture3.ZOrder
  136.     oldX = X
  137.     oldY = Y
  138. End Sub
  139. Sub Picture3_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  140. If Button <> 1 Then Exit Sub
  141.     Picture3.Left = Picture3.Left + X - oldX
  142.     Picture3.Top = Picture3.Top + Y - oldY
  143. End Sub
  144. '                                                         '
  145. ' Here, all the setting are done.                         '
  146. ' *** WARNING ***                                         '
  147. ' This code was just put together for a demonstration.    '
  148. ' (YES, it was tested. THIS code is OK.)                  '
  149. ' Please be careful with YOUR experiments !!!             '
  150. ' Noone will be responsible for your "results" !          '
  151. ' BUT: good results should be given to the public !       '
  152. '                                                         '
  153. Sub SetControls ()
  154.     Dim Style&
  155.     Style = GetWindowLong(Picture1.hWnd, GWL_STYLE)             ' Obtain the actual style
  156.     Style = Style Or WS_THICKFRAME                              ' Give it a Sizable Frame
  157.     Style = Style Or WS_CAPTION                                 ' Give it a Caption
  158.     Style = Style Or WS_MINIMIZEBOX                             ' Give it a MinimizeBox
  159.     Style = Style Or WS_SYSMENU                                 ' Give it a System Menu
  160.     Style = SetWindowLong(Picture1.hWnd, GWL_STYLE, Style)      ' - pass the new style
  161.     retInt = SetWindowText(Picture1.hWnd, "The Picture Box")    ' Give it a Name, too
  162.     Picture1.Height = Picture1.Height                           ' ! REBUILD THE CONTROL !
  163.     Picture1.CurrentY = 700
  164.     Picture1.ForeColor = &HFF0000  ' [blue]
  165.     Picture1.Print " This is a demonstration."
  166.     Picture1.ForeColor = &H0&      ' [black]
  167.     Picture1.Print " Please";
  168.     Picture1.ForeColor = &HFF&     ' [red]
  169.     Picture1.Print " do not add";
  170.     Picture1.ForeColor = &H0&      ' [black]
  171.     Picture1.Print " system menus"
  172.     Picture1.Print " to controls like this here !"
  173.     Style = GetWindowLong(List1.hWnd, GWL_STYLE)                ' Obtain the actual style
  174.     Style = Style Or WS_THICKFRAME                              ' Give it a Dizable Frame
  175.     Style = Style Or WS_CAPTION                                 ' Give it a Caption
  176.     Style = Style Xor WS_MAXIMIZEBOX                            ' Remove the MaximizeBox
  177.     Style = SetWindowLong(List1.hWnd, GWL_STYLE, Style)         ' - pass the new style
  178.     retInt = SetWindowText(List1.hWnd, "The List Box")          ' Give it a Name
  179.     List1.Height = List1.Height                                 ' ! REBUILD THE CONTROL !
  180.     List1.AddItem "Its nice and easy"
  181.     List1.AddItem "to manipulate controls"
  182.     List1.AddItem "this way !!!"
  183.     List1.AddItem "Come on, try it yourself !"
  184.     Style = GetWindowLong(Text1.hWnd, GWL_STYLE)                ' Obtain the actual style
  185.     Style = Style Or WS_BORDER                                  ' Give it a Thin Frame (--> you may leave this out)
  186.     Style = Style Or WS_CAPTION                                 ' Give it a Caption
  187.     Style = Style Xor WS_MAXIMIZEBOX                            ' Remove the MaximizeBox
  188.     Style = SetWindowLong(Text1.hWnd, GWL_STYLE, Style)         ' - pass the new style
  189.     retInt = SetWindowText(Text1.hWnd, "The Text Box 1")          ' Give it a Name
  190.     ' same as: Text1 = "The Text Box"
  191.     ' NOTE: you can alter the text later.
  192.     Text1.Height = Text1.Height                                 ' ! REBUILD THE CONTROL !
  193.     Style = GetWindowLong(Command1.hWnd, GWL_STYLE)             ' Obtain the actual style
  194.     Style = Style Or WS_BORDER                                  ' Give it a border (--> don't leave this out)
  195.     Style = Style Or WS_THICKFRAME                              ' Give it a sizable frame
  196.     Style = SetWindowLong(Command1.hWnd, GWL_STYLE, Style)      ' - pass the new style
  197.     Command1.Height = Command1.Height                           ' ! REBUILD THE CONTROL !
  198.     Style = GetWindowLong(Text2.hWnd, GWL_STYLE)                ' Obtain the actual style
  199.     Style = Style Or WS_CAPTION                                 ' Give it a Caption
  200.     Style = Style Xor WS_MAXIMIZEBOX                            ' Remove the Maximizebox
  201.     Style = SetWindowLong(Text2.hWnd, GWL_STYLE, Style)         ' - pass the new style
  202.     Style = GetWindowLong(Text2.hWnd, GWL_EXSTYLE)              ' Obtain the actual extended style
  203.     Style = Style Or WS_EX_DLGMODALFRAME                        ' Give it a Thick Border
  204.     Style = SetWindowLong(Text2.hWnd, GWL_EXSTYLE, Style)       ' - pass the new extended style
  205.     retInt = SetWindowText(Text2.hWnd, "The Text Box 2")
  206.     ' same as: Text2 = "The Text Box"
  207.     Text2.Height = Text2.Height                                 ' ! REBUILD THE CONTROL !
  208.     Picture2.CurrentX = 270
  209.     Picture2.CurrentY = 180
  210.     Picture2.Print "Step on me and move me !"
  211.     Dim Text$
  212.     Text = "(Don't be shy)"                                     ' center the text correctly
  213.     Picture2.CurrentX = (Picture2.ScaleWidth - Picture2.TextWidth(Text)) / 2
  214.     Picture2.ForeColor = &HFF0008   ' [= blue]
  215.     Picture2.Print Text
  216. End Sub
  217. Sub SetTexts ()
  218.     Text1 = "Hi, I have no sizable border but a caption."
  219.     Text2 = "I have a fixed double border..."
  220. End Sub
  221. '                                                         '
  222. ' Well, we have to help VB a little...                    '
  223. '                                                         '
  224. Sub ShowFocus (Control As Control)
  225.     ' switches the active view of the caption on (and off !)
  226.     ' note: this a toggle function ; retInt receives the old value
  227.     retInt = FlashWindow(Control.hWnd, True)
  228. End Sub
  229. Sub Text1_GotFocus ()
  230.     ShowFocus Text1
  231. End Sub
  232. Sub Text1_LostFocus ()
  233.     ShowFocus Text1
  234. End Sub
  235. Sub Text2_GotFocus ()
  236.     ShowFocus Text2
  237. End Sub
  238. Sub Text2_LostFocus ()
  239.     ShowFocus Text2
  240. End Sub
  241.