I'm having trouble getting this to work. I want to warn the user before closing the app if changes were made. I already have the code working when the menu item "Exit" is selected. I just can't seem to intercept the dialog [X] control.
Here are some snippets:
AxiPileDefines.inc
...
#define O_CancelB 6 // cancel button
...
"Exit" is selected. I just can't seem to intercept the dialog [X] control.
Here are some snippets:
AxiPile_Init.src
TabDlg::OnClose(),int
{
CloseDialog(0);
return true;
}
OnControl()
TabDlg :: OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case O_CancelB:
if(nNotifyCode = 0)
{
if(EdittedFlag != 0)
{
answer = MessageBox(null, "Discard Work?", "Warning! work not saved", MB_YESNO);
if (answer == IDYES)
EdittedFlag = 0;
}
if(EdittedFlag == 0)
CloseDialog(1);
}
case TAB_1:
if(nNotifyCode == TCNSELCHANGE)
{
nTab = m_tab1->GetSelectedTab();
StopTimer(); // stop timer when changing tabs
TimerFlag = 0;
select (nTab) // start Tab tests
{
case 0: // about tab
m_abt_btn1->ShowWindow(SWSHOW);
m_abt_txt->ShowWindow(SWSHOW);
...
[code] :D I got it to work!
Apparently, I had to include the do-wait loop to allow the message box time to pop-up before closing the dialog.
AxiPile_Init.src
TabDlg::OnClose(),int
{
if(EdittedFlag != 0)
{
int answer = MessageBox(null, "Discard Work?", "Warning! work not saved", MB_YESNO);
if (answer == IDYES)
EdittedFlag = 0;
}
if(EdittedFlag == 0)
CloseDialog(1);
// CloseDialog(0);
return true;
}
[/code]
global sub main()
global sub main() // Main Subroutine
{
TabDlg AxiPile_Tabs; // AxiPile_Tab is an instance of the class TabDlg (which is a child class of the class Dialog)
// create parent tab dialog (window) with border, minimize and maximize buttons, etc.
AxiPile_Tabs.Create(0, 0, WIDTH+DwgWidth, HEIGHT+20,
AWS_POPUP | AWS_CAPTION | AWS_SYSMENU | AWS_MINIMIZEBOX ,
0, PROG_TITLE + " v0." + VYear + VMonth + Vday, 0);
...
AxiPile_Tabs.ShowDialog();
do{
wait();
} until !AxiPile_Tabs.IsValid();
return;
}
...