Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mutex

Status
Not open for further replies.

BobbyB

Programmer
Feb 19, 2002
44
0
0
CA
Here's the situation... A Modeless Dialog Box(MDB) is open... and a function is running... At a point I want the function to call a method of the MDB and wait right there for the user to push a button in the MDB. When he does, the function will continue...

Does something like this could work?

void Function(){
// code

MDB.CallMethod();
CSingleLock sl(&mutex);
sl.Lock(); // wait for the button to be push

// code
}

OnClick..(){
CSingleLock sl(&mutex);
sl.Unlock(); // function will continue}

samples please.... thanks!
 
If you are waiting for the user to push the button can't you simply make the dialog with the button system modal?
William
Software Engineer
ICQ No. 56047340
 
no... It's more complicated than that... well, if there is a way to play with the modal state of the window by never closing it, that would do.

This window will be called hundreds of time and I don't want it to close and reopened each time...

 
Well call me stupid but I really don't follow you. You wouldn't have to open / close it just disable the button while processing, the when triggered enable the button and idle for a click.

Or am I missing something here. (It won't be the first time!) William
Software Engineer
ICQ No. 56047340
 
I'll try to explain my problem a little better... It's not exactly what I'm doing but it'll be easier to explain what I'm looking for.

what I need to do...
void Process(...){
myDlg dlg;
// open the dlg as a modeless dialog box

// I used DoModal here, but I really mean... stopping
// this code and continue when the user will press a
// button... and I don't want to open and close the dialog
// box!!!
if (dlg.DoModal()){
...
}

// code to be execute when a button will be press in dlg

// give back the control to the already open dlg... so
// DoModal is not right...
if (dlg.DoModal()){
...
}
}

is it more understandable this way?
 
What do you need to acomplish this task is a separate thread (a working thread) for your function in the background.

The sincronyzation is safely done usend an Event object

If you are not familiar with threads and sync objects read from MSDN about CreateThread (worker threads only) and CreateEvent.

HTH,

Although is a little more complicated aproach you will go for a safe solving of your problem, as I have used it safely in the past and on different platforms.

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
I've finally found what I was looking for...

RunModalLoop() makes an already open window modal...
EndModalLoop(0) makes this same window not modal...

maybe it'll help someone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top