newman     VBWeb     VBSource     Portfolio    

SendEditMsg

SelActiveText

TOP TEN

ShellModal
Tells Windows to cut, copy, or paste to or from the current selection and the Windows clipboard as if the user pressed ctrl+X, C, or V.
Syntax
SendEditMsg MessageCode
Call SendEditMsg(MessageCode)
MessageCode - Required long integer representing Cut, Copy, or Paste.

Settings
The MessageCode argument can have the following values:
Constant
Value
Description
WM_CUT &H300 Cuts the current selection out and puts it into the clipboard.
WM_COPY &H301 Copies the current selection into the clipboard.
WM_PASTE &H302 Pastes what's in the clipboard into the current selection.


Remarks
Using the Shortcut property of menu items does not quite have the effect expected. Instead, code the menu items without Ctrl keys (mnu*.shortcut = (none)). Fake the same look by coding the following in Form_Load:
mnuEditCut.Caption = mnuEditCut.Caption & vbTab & "Ctrl+X"
mnuEditCopy.Caption = mnuEditCopy.Caption & vbTab & "Ctrl+C"
mnuEditPaste.Caption = mnuEditPaste.Caption & vbTab & "Ctrl+V"
	
And code the event procedures like this:
	Private Sub mnuEditCopy_Click()
	    On Error Resume Next
	    Call SendEditMsg(WM_COPY)
	End Sub
	Private Sub mnuEditCut_Click()
	    On Error Resume Next
	    Call SendEditMsg(WM_CUT)
	End Sub
	Private Sub mnuEditPaste_Click()
	    On Error Resume Next
	    Call SendEditMsg(WM_PASTE)
	End Sub
	
Source
Const WM_USER = &H400
#If Win32 Then ' 32-bit VB uses this Declare.
    Public Declare Function SendEditMsgApi _
        Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, lParam As Any) As Long
#Else   ' 16-bit VB uses this Declare.
    Declare Function SendEditMsgApi _
        Lib "User" Alias "SendMessage" _
        (ByVal hWnd As Integer, ByVal wMsg As Integer, _
        ByVal wParam As Integer, lParam As Any) As Long
#End If
Global Const WM_CUT = &H300
Global Const WM_COPY = &H301
Global Const WM_PASTE = &H302
Global Const EM_UNDO = WM_USER + 23

Sub SendEditMsg(ByVal Action As Long)
    Dim ReturnCode As Long     'ignore it.
    Dim hWnd As Long

    hWnd = Screen.ActiveForm.ActiveControl.hWnd
    On Error Resume Next
    ReturnCode = SendEditMsgApi(hWnd, Action, 0, 0)
End Sub
	
top

SelActiveText

TOP TEN

ShellModal


Feedback Comments
Return Address (if you want a reply)


Copyright 1997 NEWMAN Services Corp. All rights reserved.
973-228-5753 pres@newmanservices.com
DECONSTRUCT THIS PAGE