home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_refer / dgridtxt / dgrid_.txt
Text File  |  1993-11-05  |  3KB  |  96 lines

  1. Nov 5, 1993    Revision 0    Uploaded by CompuServe ID 76640,312
  2.  
  3. The following routines allow CUT, COPY and PASTE availability to applications using Sheridan's 
  4. DataGrid. In this example the features are available to the user by accessing the menu bar.
  5. Only the text format of the clipboard is supported. Other types of text controls will work fine,
  6. but only TextBox and MaskEdBox have been tested.
  7. The CUT, COPY and PASTE menu items will be enabled or disabled according to the contents of the 
  8. clipboard and the selection status of the currently active edit control.
  9. The property 'ActiveForm' is used to access child forms from an MDI main form.
  10. You can use Screen.ActiveControl instead of Form1.ActiveForm.ActiveControl if your main form
  11. is not an MDI form.
  12.  
  13. '   Place in Global Module
  14. Global Const WM_USER = &H400
  15. Global Const EM_GETSEL = WM_USER + 0
  16. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  17.  
  18. On the form that you are planning to offer the EDIT functions CUT, COPY and PASTE,
  19. create four menu items and name them as follows:
  20.  
  21.    MEdit
  22.    ....MCut
  23.    ....MCopy
  24.    ....MPaste
  25.  
  26. Place the following code in the respective Menu_Click events:
  27.  
  28. Sub MEdit_Click ()
  29.     On Error Resume Next
  30.     Dim ctl As control
  31.     If clipboard.GetFormat(1) Then      'text in clipboard?
  32.         MPaste.Enabled = True
  33.     Else
  34.         MPaste.Enabled = False
  35.     End If
  36.     Set ctl = Form1.ActiveForm.ActiveControl
  37.     If TypeOf ctl Is SSDataGrid Then
  38.         Dim r As Long
  39.         ctl.SetFocus
  40.         r = SendMessage(ctl.HwndEdit, EM_GETSEL, 0, 0)
  41.         If r = 0 Then
  42.             MCut.Enabled = False
  43.             MCopy.Enabled = False
  44.         Else
  45.             MCut.Enabled = True
  46.             MCopy.Enabled = True
  47.         End If
  48.         Exit Sub
  49.     End If
  50.     If ctl.SelLength = 0 Then
  51.         MCut.Enabled = False
  52.         MCopy.Enabled = False
  53.     Else
  54.         MCut.Enabled = True
  55.         MCopy.Enabled = True
  56.     End If
  57. End Sub
  58.  
  59. Sub MCut_Click ()
  60.     Dim ctl As control
  61.     Set ctl = Form1.ActiveForm.ActiveControl
  62.     If TypeOf ctl Is SSDataGrid Then
  63.         ctl.SetFocus
  64.         SendKeys "+{DELETE}", True
  65.     Else
  66.         clipboard.SetText Form1.ActiveForm.ActiveControl.SelText
  67.         ctl.SelText = ""
  68.     End If
  69. End Sub
  70.  
  71. Sub MCopy_Click ()
  72.     Dim ctl As control
  73.     Set ctl = Form1.ActiveForm.ActiveControl
  74.     If TypeOf ctl Is SSDataGrid Then
  75.         ctl.SetFocus
  76.         SendKeys "^{INSERT}", True
  77.     Else
  78.         clipboard.SetText Form1.ActiveForm.ActiveControl.SelText
  79.     End If
  80. End Sub
  81.  
  82. Sub MPaste_Click ()
  83.     On Error Resume Next
  84.     Dim ctl As control
  85.     Set ctl = Form1.ActiveForm.ActiveControl
  86.     txt = clipboard.GetText(1)
  87.     If TypeOf ctl Is SSDataGrid Then
  88.         ctl.SetFocus
  89.         SendKeys "+{INSERT}", True
  90.     Else
  91.         ctl.SelText = txt
  92.     End If
  93. End Sub
  94.  
  95. That should do it.
  96.