Solved

Catch a button press action

Posted on 1998-09-29
3
171 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 193
Error on moodle after upgrade 3 130
WinWaitActive parameters 12 31
firstChar challenge 13 114
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now