开发者

MFC: How to get default button of child dialog to work?

开发者 https://www.devze.com 2023-04-10 10:39 出处:网络
I have a child dialog which I created as a new dialog in the resource editor.Then I used a static control on the parent dialog to act as a placeholder.The child control is displayed where开发者_运维技

I have a child dialog which I created as a new dialog in the resource editor. Then I used a static control on the parent dialog to act as a placeholder. The child control is displayed where开发者_运维技巧 the place holder is using the following code:

CRect rect;
m_optionPanelPlaceholder.GetWindowRect(&rect); // In screen coordinates
ScreenToClient(&rect);
m_optionPanelPlaceholder.ShowWindow(SW_HIDE);

optionsDialogPanel_ = new OptionsDialogPanel(settings_);
// Call Create() explicitly to ensure the HWND is created.
optionsDialogPanel_->Create(OptionsDialogPanel::IDD, this);

// Set the window position to be where the placeholder was.
optionsDialogPanel_->SetWindowPos
    (
    NULL,
    rect.left,
    rect.top,
    rect.Width(),
    rect.Height(),
    SWP_SHOWWINDOW
    );

This all works fine. There is a button on my child dialog which is set as the default button. Clicking the button with the mouse takes the desired action. However I want to just press the Enter key while in any of the edit text boxes on the child dialog and have the default button's action taken. However it's not working; how can I do this?


Make sure your button has its ID set to IDOK and not some IDC_*. MFC takes care of the rest!


When hitting the enter button in a dialog, the Parent::OnOK method is called. So you can probably call the Child::OnOK inside Parent::OnOK method.

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号