Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Catch a button press action

Posted on 1998-09-29
3
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

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

Accepted Solution

by:
prasanth earned 480 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 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