Solved

Catch a button press action

Posted on 1998-09-29
3
173 Views
Last Modified: 2013-11-20
My code is doing a lengthy operation (reading one file and sending the readed bytes to serial port) supported by a dialog with a progress control.


In order to have UPDATE working i have done the following:
// BEGIN MY MESSAGE PROCESSING

//test message pending
MSG lpMsg;
PeekMessage( &lpMsg, NULL,WM_PAINT, WM_RBUTTONDOWN,PM_REMOVE);
switch (lpMsg.message)
{
      
case WM_PAINT:
      dlg.UpdateWindow();
      break;

}
The lengthy code is in one Object i´ve created so i have to pass a CDialog reference to it (the reason for dlg).

This piece of code is executed every 200 bytes readed.

In my dialog i have a button so that the user can cancel the operation. Yes, this is the problem.
What to catch to get a cancel and how?
I think i have to make the visual button action!?

                  
            // END MY MESSAGE PROCESSING

0
Comment
Question by:SamGregor
  • 2
3 Comments
 

Author Comment

by:SamGregor
ID: 1322706
My Thanks for reading the question..
0
 
LVL 2

Accepted Solution

by:
prasanth earned 120 total points
ID: 1322707
Use something like the following:

void CMyClass::OnCancel()
{
   if (m_transferring)
       m_cancelled = TRUE;
   else
       CDialog::OnCancel();
}

void CMyClass::OnDoIt()
{
    m_transferring = TRUE;
    while (!m_cancelled)
    {
        StdMsgLoop();
        TransferOneDaoRecord(); // you implement this func
    }
    m_transferring = FALSE;
}

BOOL StdMsgLoop()
{
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetApp()->PumpMessage())
{
::PostQuitMessage(0);
return FALSE;
}
}
return TRUE;
}
0
 

Author Comment

by:SamGregor
ID: 1322708
My enormous thanks for you answer with an example.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question