?
Solved

Using CWnd::SendMessage ()...

Posted on 2000-02-03
8
Medium Priority
?
758 Views
Last Modified: 2013-11-20
What is wrong with this function call:

  pWnd->SendMessage (WM_CHAR,VK_RETURN,0);

..to send a return key press to a window?

pWnd is a valid (I checked) pointer to a main window or button, etc.

Do I need to typecast the wParam/lParam parameters?  Basically, I am simply trying to simulate a RETURN key press on a button with the current focus, using this function.
0
Comment
Question by:s_ecant
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:GlennDean
ID: 2488077
Do you have a handler for WM_CHAR?
0
 

Author Comment

by:s_ecant
ID: 2488150
Well actually, I am trying to automate another program I wrote, and trying to do it without editting the code.  I simply want my new prog to send messages to the other to fill in text, push buttons, etc.  I can fill in the textboxes, but cannot seem to send key presses such as TAB, RETURN, SPACE..
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2488157

 > What is wrong with this function call:
 >  pWnd->SendMessage (WM_CHAR,VK_RETURN,0);
 > ..to send a return key press to a window?

Faking messages to poke content at applications is bad.  Your phony message doesn't correctly show the target application the state of the system at the time the key message should be sent.

You should use the keybd_event() API. It's simple. Ideally, the way to go is a journal playback hook.

..B ekiM
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 23

Expert Comment

by:chensu
ID: 2488168
Use the keybd_event function.

::keybd_event(VK_RETURN, 0, 0, 0);
::keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);

or

// if pWnd is the pointer to the button.
pWnd->PostMessage(BM_CLICK);
0
 

Author Comment

by:s_ecant
ID: 2493764
Hmm, none of those answers/comments actually do the job.  It doesn't seem to want to accept the button push, even BM_CLICK.  I have tested the pointer and it is valid (gives me the correct window name, etc).
I am sorry, but this all doesn't solve the problem.
I have had problems with this type of question in the past..
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 2494510
What's BM_CLICK got to do with it?  Are you trying to send the ENTER key to a button? You've never mentioned a button.

If you're using TAB and ENTER to try and navigate controls in the other app, you're barking up the wrong tree.  You should use SetFocus() to change the focus instead of using TAB.  If you want to send ENTER, you need to send it to the dialog box while the button you're interested in has focus; not to the button itself.

That's all assuming, of cousre, you have a dialog box.

..B ekiM
0
 
LVL 23

Expert Comment

by:chensu
ID: 2494667
mikeblas> You've never mentioned a button.

s_ecant's original question says

"Basically, I am simply trying to simulate a RETURN key press on a button with the current focus, using this function."
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2494683
> "Basically, I am simply trying to simulate a RETURN key
 > press on a button with the current focus, using this function."

Oh!  I read the part that said "to send a return key press to a window".  Since the sentence you're quoting was in a paragraph that began with a sentence about casting wParam or lParam, I skipped it.  Sorry!

There are subtly different things that need to be done to send different input to different controls using keybd_event(). I've already cited some.  Journal hooks don't have this problem.

..B ekiM
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question