Software Archive
Read-only legacy content
17061 Discussions

Pressing Return when OK button has focus

davidgraham
Beginner
562 Views
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
0 Kudos
3 Replies
finnis_m
Beginner
562 Views
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.)
0 Kudos
davidgraham
Beginner
562 Views
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
0 Kudos
finnis_m
Beginner
562 Views
"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."
0 Kudos
Reply