Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to realize this in vc++?

Status
Not open for further replies.

hmsheng

Full Member level 4
Full Member level 4
Joined
Dec 17, 2003
Messages
219
Helped
26
Reputation
52
Reaction score
10
Trophy points
1,298
Location
China
Activity points
1,556
peekmessage pumpmessage

I'm a beginer of vc programming. I have a question.

This is a dialog based progrem. Two buttons on the dialog: start button and stop button.

I want:
When click start button a loop begin to run.
When click stop button the loop running stop.

I can start the loop but can't stop the loop because of no responce.
How to solve this problem?
tks.
 

Hi,

Read in MSDN: "Using Processes and Threads"
there is example how to make.

Enjoy
 

You may need to start the loop within a different working thread

afxBeginThread (yourFunction);

"yourFunction" should monitor a global variable toggled by the "stop" button in order to terminate de working loop.
 

No, you don't need use a second thread. You can find other way. I can not remember the function name. The reason you can not stop because the cpu is busy with your loop computation and not receive the message from user interface. You can use one function to get some cpu time to look at the message quene to process it.
 

try this one. no another thread.

void DoEvents()
{
MSG dispatch;

while :):peekMessage( &dispatch, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetThread()->PumpMessage());
}
}


in your loop call call DoEvents();

while (...........)
{
........
........
DoEvents();
}
 

also you may try

void DoEvents(void)
{
MSG msg;

while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

it is working but application doesn't gracefully terminated...

you must exit from this loop.
while ((PeekMessage(&msg,NULL,0,0,PM_REMOVE)) && (!bAppClosing))
{

TranslateMessage(&msg);
DispatchMessage(&msg);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top