home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 4.00 Begin VB.MDIForm fMhSubClass AutoShowChildren= 0 'False BackColor = &H8000000C& Caption = "MDIForm1" ClientHeight = 6375 ClientLeft = 1110 ClientTop = 1485 ClientWidth = 9435 Height = 6780 Left = 1050 LinkTopic = "MDIForm1" Top = 1140 Width = 9555 Begin VB.PictureBox pixStatus Align = 2 'Align Bottom Height = 375 Left = 0 ScaleHeight = 315 ScaleWidth = 9375 TabIndex = 0 Top = 6000 Width = 9435 Begin MhcallbLib.MhSubclass MhSubclass2 Height = 420 Left = 4320 TabIndex = 3 Top = 0 Width = 420 _version = 65536 _extentx = 741 _extenty = 741 _stockprops = 64 tintcolor = 16711935 style = 0 End Begin MhcallbLib.MhSubclass MhSubclass1 Height = 420 Left = 600 TabIndex = 2 Top = 0 Width = 420 _version = 65536 _extentx = 741 _extenty = 741 _stockprops = 64 tintcolor = 16711935 style = 0 End Begin VB.Label lblStatus BorderStyle = 1 'Fixed Single Height = 375 Left = 0 TabIndex = 1 Top = 0 Width = 9375 End End Attribute VB_Name = "fMhSubClass" Attribute VB_Creatable = False Attribute VB_Exposed = False Option Explicit Private Sub MDIForm_Activate() 'Setting the hWnd allows us to intercept messages MhSubclass1.hWndSubclass = fChild.hwnd MhSubclass1.MsgList(0) = WM_MOVE MhSubclass1.MsgList(1) = WM_LBUTTONUP MhSubclass1.MsgList(2) = WM_LBUTTONDOWN MhSubclass1.MsgList(3) = WM_RBUTTONDOWN MhSubclass1.MsgList(4) = WM_RBUTTONUP MhSubclass1.MsgList(5) = WM_LBUTTONDBLCLK MhSubclass1.MsgList(6) = WM_RBUTTONDBLCLK MhSubclass1.MsgList(7) = WM_MOUSEACTIVATE MhSubclass1.MsgList(8) = WM_MOUSEMOVE MhSubclass2.hWndSubclass = fMhSubClass.hwnd MhSubclass2.MsgList(0) = WM_MENUSELECT MhSubclass2.MsgList(1) = WM_SYSCOMMAND End Sub Private Sub MDIForm_Load() fMhSubClass.Caption = "MicroHelp MhSubClass Example" fChild.Caption = "Move me, Click me, Move the mouse over me" 'Here we get the menu of the system handle (Declarations and constants for these functions is in the MhSub.Bas file) #If Win32 Then lg_SysMenuHandle = GetSystemMenu(fMhSubClass.hwnd, False) #End If 'Here we put in the separator for the menu. lg_AddMenu = AppendMenu(lg_SysMenuHandle, MF_SEPARATOR, 0, 0&) 'Here we add the menu item. MhSubClass2 will catch it and do something with it. Look in the SubclassMsg event lg_AddMenu = AppendMenu(lg_SysMenuHandle, MF_STRING, lg_ABOUT, "&About . . .") CenterForm ("fMhSubClass") CenterForm ("fChild") fChild.Show End Sub Private Sub MhSubclass1_SubclassMsg(Msg As Integer, wParam As Integer, lParam As Long, ReturnVal As Long) 'Here, we're inserting the messages we catch at the top of the listbox Select Case Msg Case WM_MOVE fChild.lstMsg.AddItem "WM_MOVE", 0 Case WM_LBUTTONUP fChild.lstMsg.AddItem "WM_LBUTTONUP", 0 Case WM_LBUTTONDOWN fChild.lstMsg.AddItem "WM_LBUTTONDOWN", 0 Case WM_RBUTTONDOWN fChild.lstMsg.AddItem "WM_RBUTTONDOWN", 0 Case WM_RBUTTONUP fChild.lstMsg.AddItem "WM_RBUTTONUP", 0 Case WM_LBUTTONDBLCLK fChild.lstMsg.AddItem "WM_LBUTTONDBLCLK", 0 Case WM_RBUTTONDBLCLK fChild.lstMsg.AddItem "WM_RBUTTONDBLCLK", 0 Case WM_MOUSEACTIVATE fChild.lstMsg.AddItem "WM_MOUSEACTIVATE", 0 Case WM_MOUSEMOVE fChild.lstMsg.AddItem "WM_MOUSEMOVE", 0 Case Else fChild.lstMsg.AddItem "Unanticipated message", 0 End Select 'Makes messages more readable If fChild.lstMsg.List(1) <> "" Then fChild.lstMsg.AddItem "", 1 End If 'To make sure the list doesn't overflow, we remove the bottom item 'if the list contains more than 100 items If fChild.lstMsg.ListCount > 100 Then fChild.lstMsg.RemoveItem fChild.lstMsg.ListCount - 1 End If End Sub Public Sub CenterForm(fForm) Select Case fForm 'Centers main form on screen Case "fMhSubClass" fMhSubClass.Left = (Screen.Width \ 2) - (fMhSubClass.Width \ 2) fMhSubClass.Top = (Screen.Height \ 2) - (fMhSubClass.Height \ 2) 'Centers little form on big one Case "fChild" fChild.Height = 4680 fChild.Width = 8355 fChild.Left = (fMhSubClass.Width - fChild.Width) \ 2 fChild.Top = ((fMhSubClass.ScaleHeight - fChild.Height) \ 2) - (fMhSubClass.lblStatus.Height \ 2) End Select End Sub Private Sub MhSubclass2_SubclassMsg(Msg As Integer, wParam As Integer, lParam As Long, ReturnVal As Long) 'Here we catch messages and determine what we're going to do based on additional parameters Select Case Msg 'If the user highlights a menu item, we put some text in a status bar Case WM_MENUSELECT Select Case wParam Case 0 fMhSubClass!lblStatus.Caption = "File menu is selected." Case 2 fMhSubClass!lblStatus.Caption = "Click on this item and the program will end." Case 1 fMhSubClass!lblStatus.Caption = "This is a test menu added so we can demonstrate menu item sequencing." Case 4 fMhSubClass!lblStatus.Caption = fChild!itmOne.Caption Case 5 fMhSubClass!lblStatus.Caption = fChild!itmTwo.Caption Case 6 fMhSubClass!lblStatus.Caption = fChild!itmThree.Caption End Select 'If the user clicks the "About" box of the system menu, we pop up a little About box. Case WM_SYSCOMMAND If wParam = lg_ABOUT Then MsgBox "This subclassing example owes a debt to the article 'Subclass Your Way Around VB's Limitations' by Jonathan Wood and Karl E. Peterson in the September 1995 edition of Visual Basic Programmer's Journal -- Jim McFadden, MicroHelp", 64, "MicroHelp" Exit Sub End If End Select End Sub