home *** CD-ROM | disk | FTP | other *** search
- Nov 5, 1993 Revision 0 Uploaded by CompuServe ID 76640,312
-
- The following routines allow CUT, COPY and PASTE availability to applications using Sheridan's
- DataGrid. In this example the features are available to the user by accessing the menu bar.
- Only the text format of the clipboard is supported. Other types of text controls will work fine,
- but only TextBox and MaskEdBox have been tested.
- The CUT, COPY and PASTE menu items will be enabled or disabled according to the contents of the
- clipboard and the selection status of the currently active edit control.
- The property 'ActiveForm' is used to access child forms from an MDI main form.
- You can use Screen.ActiveControl instead of Form1.ActiveForm.ActiveControl if your main form
- is not an MDI form.
-
- ' Place in Global Module
- Global Const WM_USER = &H400
- Global Const EM_GETSEL = WM_USER + 0
- Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
-
- On the form that you are planning to offer the EDIT functions CUT, COPY and PASTE,
- create four menu items and name them as follows:
-
- MEdit
- ....MCut
- ....MCopy
- ....MPaste
-
- Place the following code in the respective Menu_Click events:
-
- Sub MEdit_Click ()
- On Error Resume Next
- Dim ctl As control
- If clipboard.GetFormat(1) Then 'text in clipboard?
- MPaste.Enabled = True
- Else
- MPaste.Enabled = False
- End If
- Set ctl = Form1.ActiveForm.ActiveControl
- If TypeOf ctl Is SSDataGrid Then
- Dim r As Long
- ctl.SetFocus
- r = SendMessage(ctl.HwndEdit, EM_GETSEL, 0, 0)
- If r = 0 Then
- MCut.Enabled = False
- MCopy.Enabled = False
- Else
- MCut.Enabled = True
- MCopy.Enabled = True
- End If
- Exit Sub
- End If
- If ctl.SelLength = 0 Then
- MCut.Enabled = False
- MCopy.Enabled = False
- Else
- MCut.Enabled = True
- MCopy.Enabled = True
- End If
- End Sub
-
- Sub MCut_Click ()
- Dim ctl As control
- Set ctl = Form1.ActiveForm.ActiveControl
- If TypeOf ctl Is SSDataGrid Then
- ctl.SetFocus
- SendKeys "+{DELETE}", True
- Else
- clipboard.SetText Form1.ActiveForm.ActiveControl.SelText
- ctl.SelText = ""
- End If
- End Sub
-
- Sub MCopy_Click ()
- Dim ctl As control
- Set ctl = Form1.ActiveForm.ActiveControl
- If TypeOf ctl Is SSDataGrid Then
- ctl.SetFocus
- SendKeys "^{INSERT}", True
- Else
- clipboard.SetText Form1.ActiveForm.ActiveControl.SelText
- End If
- End Sub
-
- Sub MPaste_Click ()
- On Error Resume Next
- Dim ctl As control
- Set ctl = Form1.ActiveForm.ActiveControl
- txt = clipboard.GetText(1)
- If TypeOf ctl Is SSDataGrid Then
- ctl.SetFocus
- SendKeys "+{INSERT}", True
- Else
- ctl.SelText = txt
- End If
- End Sub
-
- That should do it.
-