40 out of 103 rated this helpful Rate this topic

Windows API Reference

The following topics provide information about the programming elements included in the Windows API.

 

 

Build date: 3/25/2010

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
A MessageBox to save
I suppose we all have wondered how do some softawares ask to save before exiting. Here's a simple code to do that.
If you have better than mine, thank you for telling me, I will add it.
As always, I'll comment after.
Here's the prototype:

void beforeExiting (int, int);

Here is the function body:

void beforeExiting (int close, int order)
{
   
int resul = 0;
   
if (close == 0)
  
{
       
if (command == 0)
       
resul = MessageBox (MainWindow, "File not saved. Do you want to save before exiting?", "Warning!" MB_ICONWARNING |MB_YESNOCANCEL);

       
else if (command == 1)
       
resul = MessageBox (MainWindow, "File not saved. Do you want to save before exiting?", "Warning!" MB_ICONWARNING | MB_YESNO);

       
if (result == IDNO) exit (0);
       
else if (result == IDYES) (SendMessage (fenetrePrincipale, WM_COMMAND, ID_ENR, 0) exit (0);)
  
}
   
else
   
exit (0);
}


Here's where to call:

case ID_LEAVE:
            beforeExiting
(close, 0);

case WM_DESTROY:
          
beforeExiting (close, 1);

And that's it!
This code gives a message backup before leaving with yes and no if it has already closed the window, yes, no and cancel if the window still exists.
"Close" is determined as follows: If you save, turn passes to 1. If the text window should redraw itself, close goes to 0.

The method is simple: when a control should redraw itself, it sends a message with its own ID. Simply assign an ID to the edit control to monitor and add a box for him. I show you:


case WM_COMMAND:
           
switch (LOWORD (wParam))
          
{
                
IDC_CHILD_EDIT box:
                
close = 0;
                
break;
                
ID_B_USE box:
                
.
                
.
                
.

IDC_CHILD_EDIT which is the ID that I have attributed to the control to follow.
Use it well