Pressing Return when OK button has focus

Pressing Return when OK button has focus

I have a API project which has a dialog with several edit boxes and OK & Cancel buttons.

I have programmed it so that if the user pressed Return on an edit box the focus moves to the next field.

On the last field pressing retun passes focus to the OK button which is displayed with a dotted line round it. If I press Return nothing happens, but if I click on OK I get a response.

Is there something that I am missing?

I have tried renaming IDOK to my own ID name.

I have noticed that the control id I get back on pressing return on the OK button is the same as on the previous edit box.

Thanks,

David

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You don't say how you are setting the focus to the next control. There are 'Windows issues' that cause SetFocus to misbehave; using PostMessage with the WM_NEXTDLGCTL message is safer, e.g.

hwnd=GetDlgItem(dlg%hwnd,IDC_OK)
lret=PostMesage(dlg%hwnd,WM_NEXTDLGCTL,hwnd,TRUE)

should set the focus to the OK button (with id IDC_OK used in dialog dlg) such that it will respond when the Return key is pressed. (PostMessage is defined in the module user32, TRUE is declared as = 1 in module dfwinty which I think is used in module dflogm.)

Thanks, I replaced SetFocus with the call with WM_NEXTDLGCTL and it worked.

By the way, is there a difference between PostMessage and SendMessage?

David

"The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately."

Leave a Comment

Please sign in to add a comment. Not a member? Join today