Re: Pasting to any window
Try to use SendInput API rather than sending WM_CHAR message.
Re: Pasting to any window
Still the same results - works on notepad but not in Word or in browser's textboxes
This is what I've used:
(should I try to change anything ?)
INPUT *key;
key = new INPUT;
key->type = INPUT_KEYBOARD;
key->ki.wVk = VK_CONTROL; // virt key code
key->ki.dwFlags = 0; // flags—see doc
key->ki.time = 0; // time stamp, 0 = dflt
key->ki.wScan = 0; // hw scan code
key->ki.dwExtraInfo = 0; // app-defined
SendInput(1,key,sizeof(INPUT));
//key->ki.dwExtraInfo = KEYEVENTF_KEYUP;
//SendInput(1,key,sizeof(INPUT));
key = new INPUT;
key->type = INPUT_KEYBOARD;
key->ki.wVk = 'V'; // virt key code
key->ki.dwFlags = 0; // flags—see doc
key->ki.time = 0; // time stamp, 0 = dflt
key->ki.wScan = 0; // hw scan code
key->ki.dwExtraInfo = 0; // app-defined
SendInput(1,key,sizeof(INPUT));
//key->ki.dwExtraInfo = KEYEVENTF_KEYUP;
//SendInput(1,key,sizeof(INPUT));
Re: Pasting to any window
Also, FYI: I'm running Vista 64bit
Re: Pasting to any window
Quote:
Originally Posted by
VictorN
Try to use SendInput API rather than sending WM_CHAR message.
:confused:
I do something like that in my Apps: However I go to ClassWizard and created a 'Member Control Variabale of the Edit box of CEdit type':
Code:
CString source;
//put your text in source
source = "Line 1 :\r\n"
"Line2 :\r\n"
"...etc, :\r\n"
".....";
if(OpenClipboard())
{
HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, LPCSTR(source));
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
this->m_CntrlNotes.Paste(); //m_nCntrNotes is a CEdit Control Variable assigned in ClassWizard
this->UpdateData();
AfxMessageBox(m_Notes); //m_Notes is a varaiable assigned to the edit box in ClassWizard
This will copy a string to the clipboard and into an Edit control assigned to an edit box via Classwizard.
Re: Pasting to any window
Still the same results - works on notepad but not in Word or in browser's textboxes
I've added this:
((CEdit*)editControl)->Paste();
instead of editControl->SendMessage(WM_PASTE, 0, 0L);
I wonder if there is some kind of Vista built-in security feature that is preventing me from doing this...
Re: Pasting to any window
Are you trying to paste directly into MS WORD?
Also right into Html code? or into the address bar of the Browser?
Re: Pasting to any window
Yes I was trying to paste into Word,
When I hit a hot key my function do copy the data into clipboard, but on Word it does not do the paste,
however, if I hit Ctrl+V it does copy my value from clipboard,
Also, it does work for the address line of Internet Explorer,
but not for TextBox inside web sites - for example: the search box at the google web page,
Thanks again.
Re: Pasting to any window
Well the Edit box in a browser in NOT a CEdit control, the browser has over written the Ctrl-Paste function. ... I doubt you have access to that via, MFC.
MSWORD is another story. The client area probobly not a CEdit box.
I was doing some stuff a few month's ago where I had to get the address line of the brower, or a specif instance of the Browser. ... i.e, several sites were open.
I had to use FindWindow, and get into the use of that function. It gets pretty messy.
Regarding getting data into MSWORD you might have more success with that. What I posted only works with CEdit Boxes.
Regarding geting data in the edit boxes of the browers client area. I'm not sure if we have access to that via MFC. ..... Like I said I don't do much Internet stuff, so I could be wrong, I just know that those boxes in the Client area are not CEdit boxes.
One way of getting data into the Google Box would be to download the webpage into a file edit it and call that html file via the browser, basically scrub the file.
Re: Pasting to any window
Well here you go, I think this get access to the Client area in the Browser.
http://www.codeguru.com/cpp/i-n/iepr...le.php/c13065/
Re: Pasting to any window
Quote:
Originally Posted by
Yovav
Yes I was trying to paste into Word,
Simply use COM
Re: Pasting to any window
Your SendInput sequence is not entirely correct. Use this one it should work ( works for any of my applications )
Code:
void SendPaste()
{
INPUT Input[4];
memset(Input, 0, sizeof(Input));
Input[0].type = INPUT_KEYBOARD;
Input[0].ki.wVk = VK_CONTROL;
Input[0].ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
Input[1].type = INPUT_KEYBOARD;
Input[1].ki.wVk = 'V';
Input[2].type = INPUT_KEYBOARD;
Input[2].ki.wVk = 'V';
Input[2].ki.dwFlags = KEYEVENTF_KEYUP;
Input[3].type = INPUT_KEYBOARD;
Input[3].ki.wVk = VK_CONTROL;
Input[3].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY;
SendInput(4, Input, sizeof(Input[0]));
}
Re: Pasting to any window
I like your SendInput sequence better, but I'm getting the same results,
if you say its working for you then I really start to think that it is something related to my Vista 64bit
I will try it in some other Windows emulators with Virtual PC and see,
Thanks.
Re: Pasting to any window
Can you show us the exact code you are using at the moment (not only the SendInput sequence ) but all the parts . maybe if you could attach a sample project we could test on our pcs it would help debug the issue.
Re: Pasting to any window
I gave him some links that expllain why he can't post information to Word (think about it, do you really think that Word is just one bigcCEdit Class, .. maybe a Richedit control, but most likely something derivied from CWND!, I havn't read the article but I'm sure he addresses it) .
Regarding posting information into forms: He has to get the content of the web page and parse the contents via CHtmlView->GetHtmlDocuement(); It's not a trivial task, it requires somes knowledge of COM and IHtmlDocument2 with one of the last SDK's if you are using V6 (which I' am and are having problems getting the SDK created in 2003 for V6, to work) or compiler newere than V6, since accessing a HTML Form requires having access to IHTMLelementPTR.
In a nutshell those are not CEdit Classes he is trying to communicate with, sendig a message via CEdit is not going to get you anywhere with those two apps he is trying to communicate with: .... it like the old saying, "Don't send a BOY to do a mans job". Your going to have to roll up your sleeves to get information to WORD and a HTML Form!!!