[英]CPropertyPage dialogue OnOk should not close the dialogue if there is an error
我有一個繼承自CPropertyPage
類的類。 我有一個OnOk()
方法和一個OnKillActive()
方法。 每當我在對話上按 Ok 時。 OnKillActive()
被調用,但OnOk()
從未被調用。 問題取決於我不想在按下 Ok 時關閉對話的條件。 但是對話即將結束,按下 Ok。
當我按下 Ok 時,如何防止對話框關閉?
代碼:
In MyClass.h:
class MyClass : public CPropertyPage {
}
In MyClass.cpp:
void MyClass::OnOK(){
if (condition true) {
return; // This should prevent the dialogue from closing but still the dialogue closes
}
return CPropertyPage::OnOk();
}
BOOL MyClass::OnKillActive() {
if (condition true) {
CDialog::DoModal();
return FALSE; // This should prevent the dialogue from closing but still the dialogue closes
}
return CPropertyPage::OnKillActive();
}
我不確定你是否可以調用CDialog::DoModal();
因為您的屬性頁面尚未關閉。
當此事件( OnKillActive()
)發生時,您的屬性頁處於非活動狀態。 但是您的屬性頁仍然存在,並且屬性頁中的數據也存在用於驗證。
要返回您的頁面,只需將焦點設置在對話框項目之一中即可。 使用“ GetDlgItem
”獲取對象並使用“ SetFocus
”設置焦點
此處提供了一個示例。
實際上在PropertySheet
類的OnClickedOk()
函數中,有一個EndDialog(IDOK)
。 這就是為什么每次按下 Ok 時它都會關閉的原因。
我只是在EndDialog()
之前進行了條件檢查並且它起作用了。 感謝您的回復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.