Search This Blog

Friday, April 12, 2013

How to Paste in MFC Editbox from Clipboard?

When we automating a process, sometime we need to copy some values to clipboard and paste it to a edit box from the clipboard.

In the below example, I created a edit box with the name m_edEditbox, then I am setting focus to that edit box.

Normally we use ctrl+v as the shortcut to paste in windows.

I am generating the ctrl+v keyboard event programatically using the following code.
 
 

    m_edEditBox.SetFocus();
    Sleep(100);
    keybd_event( VK_CONTROL, MapVirtualKey( VK_CONTROL, 0 ), 0, 0 );
    Sleep(100);
    keybd_event( 'V', MapVirtualKey( 'V', 0 ),  0, 0 );
    Sleep(100);
    keybd_event( 'V', MapVirtualKey( 'V', 0 ), KEYEVENTF_KEYUP, 0 );
    Sleep(100);
    keybd_event( VK_CONTROL, MapVirtualKey( VK_CONTROL, 0 ), KEYEVENTF_KEYUP, 0 );
    Sleep(100);

No comments:

Post a Comment