سؤال

I have the code;

HWND MShwnd = FindWindowA("MapleStoryClass", NULL);
        PostMessage(MShwnd, WM_KEYDOWN, 0x09, MapVirtualKeyA(0x09, 0) << 16);

which works just fine. Before hand, I copied to the clipboard a text.

What I want to know is how can I use postmessage and paste the text.

I searched everywhere and do not understand.

Thanks.

هل كانت مفيدة؟

المحلول

This is a C# code convert it or make a c# dll with my code: (You need to add reference Microsoft.VisualBasic)

public string GetClipboardText()
{
    Microsoft.VisualBasic.Devices.Computer c = new Microsoft.VisualBasic.Devices.Computer();
    return c.Clipboard.GetText();
}

public void SetClipboardText(string stext)
{
    Microsoft.VisualBasic.Devices.Computer c = new Microsoft.VisualBasic.Devices.Computer();
    c.Clipboard.SetText(stext);
}

Update C++ code :

System::String^ GetClipboardText()
{
    Microsoft::VisualBasic::Devices::Computer^ c = gcnew Microsoft::VisualBasic::Devices::Computer();
    return c->Clipboard->GetText();
}

void SetClipboardText(System::String^ stext)
{
    Microsoft::VisualBasic::Devices::Computer^ c = gcnew Microsoft::VisualBasic::Devices::Computer();
    c->Clipboard->SetText(stext);
}

Update 2

I suppose that you need native code, so you didn't use my code up there that didn't require a handle, plus if you acheive HWND MShwnd = FindWindowA("MapleStoryClass", NULL); so you have a handle... Any way i suggest one last method is the following:

keybd_event(0x11, 0, 0, 0); // press ctrl
keybd_event(0x56, 0, 0, 0); // press v
keybd_event(0x56, 0, 2, 0); // release v
keybd_event(0x11, 0, 2, 0); // release ctrl
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top