Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

How to realize this in vc++?

Status
Not open for further replies.

hmsheng

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.
 

tcsa35

Full Member level 3
Joined
Mar 19, 2002
Messages
171
Helped
10
Reputation
20
Reaction score
8
Trophy points
1,298
Activity points
1,507
Hi,

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

Enjoy
 

jmantilla

Junior Member level 2
Joined
Oct 4, 2004
Messages
20
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
Colombia
Activity points
206
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.
 

fath

Junior Member level 2
Joined
Oct 10, 2004
Messages
22
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
163
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.
 

ben123

Member level 1
Joined
Aug 27, 2003
Messages
32
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
372
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();
}
 

ben123

Member level 1
Joined
Aug 27, 2003
Messages
32
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
372
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top