Using CWnd::SendMessage ()...

What is wrong with this function call:

  pWnd->SendMessage (WM_CHAR,VK_RETURN,0); 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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you have a handler for WM_CHAR?
s_ecantAuthor Commented:
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..

 > What is wrong with this function call:
 >  pWnd->SendMessage (WM_CHAR,VK_RETURN,0);
 > 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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Use the keybd_event function.

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


// if pWnd is the pointer to the button.
s_ecantAuthor Commented:
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..
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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."
> "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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.