Starting/Stopping a function with Button Control

I'd like to be able to start and stop the running of a function on the
action of some button controls... unfortunately, the function I'd like
to start is in a seperate class from the GUI/API class. What would be
the best way to do this? I thought of perhaps creating an array class
that would house a single Boolean value which would be added on the
action of the button controls (True for Start, False for Stop). Then I
would be able to use a simple call from the function for the Boolean
value to know wether to proceed or return. I'm not sure if this is just
a hack and there are better/more efficient ways.

Any input would be greatly appreciated,
Marcus

0
mcdesigns (46)
8/14/2005 2:46:34 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
600 Views

Similar Articles

[PageSpeed] 56

Marcus wrote:
> I'd like to be able to start and stop the running of a function on the
> action of some button controls... unfortunately, the function I'd like
> to start is in a seperate class from the GUI/API class. What would be
> the best way to do this? I thought of perhaps creating an array class
> that would house a single Boolean value which would be added on the
> action of the button controls (True for Start, False for Stop). Then I
> would be able to use a simple call from the function for the Boolean
> value to know wether to proceed or return. I'm not sure if this is just
> a hack and there are better/more efficient ways.
> 
> Any input would be greatly appreciated,
> Marcus
> 

When your function is executing the program will ignore button clicks. 
You only get button clicks after returning to the MFC message 
dispatcher.  In order to continue responding to clicks and other 
messages your functions have to be brief and then return.

To execute a lengthy time-consuming operation without blocking the GUI 
message processing put the time-consuming operation in another thread. 
Call AfxBeginThread with a function name.  It will begin executing 
concurrently with the main GUI thread.  To start/stop it you can use a 
bool or SetEvent/WaitForMultipleObjects.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
8/14/2005 4:29:57 AM
I tried to do something with an extra thread, but ran into a difficulty. My 
loop was not only supposed to stop when a button was pressed, it was also 
supposed to update edit controls and an image on the dialog with the buton 
that started it. Once I was in another thread, I couldn't access the dialog 
directly without getting an ASSERT warning me that I couldn't do that. When 
I tried to use the handle of the dialog to create a new DMyDialog object, it 
was also not updating the actual dialog. How to get around that difficulty?

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message 
news:%23aH1UCIoFHA.3568@TK2MSFTNGP10.phx.gbl...
> Marcus wrote:
>> I'd like to be able to start and stop the running of a function on the
>> action of some button controls... unfortunately, the function I'd like
>> to start is in a seperate class from the GUI/API class. What would be
>> the best way to do this? I thought of perhaps creating an array class
>> that would house a single Boolean value which would be added on the
>> action of the button controls (True for Start, False for Stop). Then I
>> would be able to use a simple call from the function for the Boolean
>> value to know wether to proceed or return. I'm not sure if this is just
>> a hack and there are better/more efficient ways.
>>
>> Any input would be greatly appreciated,
>> Marcus
>>
>
> When your function is executing the program will ignore button clicks. You 
> only get button clicks after returning to the MFC message dispatcher.  In 
> order to continue responding to clicks and other messages your functions 
> have to be brief and then return.
>
> To execute a lengthy time-consuming operation without blocking the GUI 
> message processing put the time-consuming operation in another thread. 
> Call AfxBeginThread with a function name.  It will begin executing 
> concurrently with the main GUI thread.  To start/stop it you can use a 
> bool or SetEvent/WaitForMultipleObjects.
>
> -- 
> Scott McPhillips [VC++ MVP]
> 


0
Bill
8/15/2005 6:32:35 AM
Hi,

See below..



"Bill Brehm >" wrote:

> I tried to do something with an extra thread, but ran into a difficulty. My 
> loop was not only supposed to stop when a button was pressed, it was also 
> supposed to update edit controls and an image on the dialog with the buton 
> that started it. Once I was in another thread, I couldn't access the dialog 
> directly without getting an ASSERT warning me that I couldn't do that. When 
> I tried to use the handle of the dialog to create a new DMyDialog object, it 
> was also not updating the actual dialog. How to get around that difficulty?

What you need to do is implement a user-defined message. First, define a
message id like this:

const UINT WM_UPDTAE_MY_DLG = WM_USER + 5;

Second, declare and define a handler for CYourDlg class:

LRESULT CMyDlg::OnUpdateMyDlg(WPARAM w, LPARAM l)
{
      // the code to update..
      return 0;
}

// And finally, assign the message id with the handler:

ON_MESSAGE(WM_UPDATE_MY_DLG, OnUpdateMyDlg)

Now, your loop, having the dlg's hanlde, can send the message
to the dlg. Assume your thread's controller's PVOID parameter contains
the dlg's handle (HWND):

HWND hDlg = (WHND) pParam; // PVOID lpParam;
::SendMessage(hDlg, WM_UPDATE_MY_DLG, 0, 0);

You are supposed to start your thread from the dlg class like this:

AfxBeginThread(YourThreadController, GetSafeHwnd());

> "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message 
> news:%23aH1UCIoFHA.3568@TK2MSFTNGP10.phx.gbl...
> > Marcus wrote:
> >> I'd like to be able to start and stop the running of a function on the
> >> action of some button controls... unfortunately, the function I'd like
> >> to start is in a seperate class from the GUI/API class. What would be
> >> the best way to do this? I thought of perhaps creating an array class
> >> that would house a single Boolean value which would be added on the
> >> action of the button controls (True for Start, False for Stop). Then I
> >> would be able to use a simple call from the function for the Boolean
> >> value to know wether to proceed or return. I'm not sure if this is just
> >> a hack and there are better/more efficient ways.
> >>
> >> Any input would be greatly appreciated,
> >> Marcus
> >>
> >
> > When your function is executing the program will ignore button clicks. You 
> > only get button clicks after returning to the MFC message dispatcher.  In 
> > order to continue responding to clicks and other messages your functions 
> > have to be brief and then return.
> >
> > To execute a lengthy time-consuming operation without blocking the GUI 
> > message processing put the time-consuming operation in another thread. 
> > Call AfxBeginThread with a function name.  It will begin executing 
> > concurrently with the main GUI thread.  To start/stop it you can use a 
> > bool or SetEvent/WaitForMultipleObjects.
> >
> > -- 
> > Scott McPhillips [VC++ MVP]
> > 
> 
> 

-- 
======
Arman
0
armancho_x1 (249)
8/15/2005 7:08:05 AM
Bill Brehm < wrote:
> I tried to do something with an extra thread, but ran into a difficulty. My 
> loop was not only supposed to stop when a button was pressed, it was also 
> supposed to update edit controls and an image on the dialog with the buton 
> that started it. Once I was in another thread, I couldn't access the dialog 
> directly without getting an ASSERT warning me that I couldn't do that. When 
> I tried to use the handle of the dialog to create a new DMyDialog object, it 
> was also not updating the actual dialog. How to get around that difficulty?

Updating windows and controls must be done by the thread that created 
them.  Use interthread messaging to ask the main thread to do the update:

http://www.mvps.org/vcfaq/mfc/12.htm

-- 
Scott McPhillips [VC++ MVP]

0
Scott
8/15/2005 1:15:15 PM
Reply:

Similar Artilces:

Starting up on start-up help!
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Hello all, <br><br>I'm new here so Hello. I just have a question to see if anyone can help here. I just recently bought a new MacBook Pro, and I got the Microsoft Office for it too. Well, I recently noticed that on start up, entourages My Day keeps opening up. Well when I right click the menu, I check off the box where it says to start on login. <br><br>Well here is the problem. Everytime I uncheck it, it still keeps opening up on start up. <br><br>Anyone know why?...

Deleting "Suggested Sites" Button
How can I permanently delete the "Suggested Sites" button from the IE8 toolbar? Frequently the button returns to the favorites bar even though I previously delete it. -- Jim Benet Hi Jim, Try, Display the Favorites bar (Ctrl+Shift+I) and pin it to the side (for the time being). Drag and Drop the Suggested Sites Web slice from the 'Favorites Bar' to the Favorites Pane to move it from the Favorites Bar. On the Favorites Pane select the Suggest Sites link you just dropped there and right click to display the context menu. Select Delete. You will s...

Edit Comment Function
I have rec'd a spreadsheet containing comments in several cells. Problem-- Select cell to edit comment. Right mouse click to edit comment. The edit comment selection is not grayed out. Select edit comment and nothing happens. The dialog box goes away. The comment can be viewed by moving the pointer over the cell. Some cells with comments do work properly with edit comment. Any suggestions on how to correct the problem? -- Bonita I see this is your second posting and apparently have not received any replies. Some Comments being editable and others not is a mystery. I...

Need advice to start off a project
Hello! I have never really used Excel much but I have had an idea which could make some of the work I do a lot easier. I know Excel is powerful but I don't know the best way to approach it so can anyone out there help me? I make visits to places and record what kind of visit it was on a spreadsheet with the values in each cell being the date. At the bottom there is a summary box which shows, on each date, how many visits I made of each type. At the moment this is done manually but I am sure it can be done automatically only how? On a different sheet I would then like to have a summary of...

Cannot start Outlook 2002
My computer is usualy connected to an MS Exchange server at work. However I'd like to use Outlook at home with another e-mail account. When I try to start Outlook I get an error message : Cannot connect to exchange server. So I click work offline. Then, get another error message: Cannot start Outlook. Could not open information store. The the program quits. Anyone know a work around? Thanks. Create a new profile for your home account. Then set Outlook to prompt for profile. Select your home profile and Outlook will not try to connect to Exchange. --� Milly Staples [MVP - Outlook...

User ID stops working on one workstation
Can someone please help to explain why an existing user that has been working for years, just stops working on one workstation? I have even deleted the user and recreated it. It still does not work on my workstation, yet works on all our citrix servers. The sa login works on my workstation, plus other users. The ODBC has never been changed. There is nothing wrong with the user setup (ie works on other machines) and there is nothing wrong with the ODBC setup. The only way it will work is if I create a brand new ODBC datasourse. Is Great Plains storing user login information somewhe...

Exchange Services Do not Start After a Restart #2
I have a SBS 2003 Running and for some reason some of my Exchange Service do not start after a restart. System Attendand tries to start shuts down unexpectedly. I can go to services right after logging in and start the services and they start with no problem. Right before the error that service did not start, I get this warning: "A service process other than the one launched by the Service Control Manager connected when starting the Microsoft Exchange System Attendant service. The Service Control Manager launched process 2448 and process 3688 connected instead. Note that if this se...

#ERROR message for custom field function
I hope someone can help me understand this bizarre problem with a project plan that I've been using and evolving for the past 1 1/2 years to track a number of projects on a very high level (Project Portfolio Reporting): All of a sudden my custom field functions no longer work - even a simple Today = Now() function. It results in "#ERROR" being displayed. I checked to make sure that I did not remove any necessary custom fields, tables, etc. that are used by other calculations. (All looks good) I confirmed that I have the auto-calculate value set under Tools ->...

Submit button to email
Hello everyone, I am trying to code a submit button on my form that will export the data entered and then send it in email format. Any suggestions would help. Create a report based on the current record and then use SendObject to send the e-mail. -- Hope this helps, Daniel P "shwinn" wrote: > Hello everyone, > > I am trying to code a submit button on my form that will export the data > entered and then send it in email format. Any suggestions would help. ...

Countif Function -Nested
I'm trying to create a countif function with three criteria, but for the life of me I can't figure out the nested function. For example, I want to countif column A=1, and column b=2 and column c=3. Can anyone help me with this? Thank you so much! try =sumproduct((a2:a200=1)*(b2:b200=2)*(c2:c200=3)) -- Don Guillett SalesAid Software donaldb@281.com "Angi" <Angi@discussions.microsoft.com> wrote in message news:EEBFF6F0-99F4-406F-87E7-B42B5A5870DE@microsoft.com... > I'm trying to create a countif function with three criteria, but for the life > of me I c...

Macro or Lookup? Not sure where to start.
I have created two worksheets: 1) Auction Items Item# Table# Location# ItemDescription WinBid are the headers of the data. 2) Bidders Bidder# FirstName LastName I would like to be able to create a macro or something that will allow me to enter the item#, bidder# and winning bid price and have a sheet filled with. ie. Item# 2 (Handcrafted Table) Bidder# 12 (John Doe) Winning Bid $250 Can excel pull from two sheets and created another sheet with all the final details? I am a little new to excel (version 2000) it is the only tool/application available to us at this time. If anyone can poi...

Outlook starting problem
"Cannot start Microsoft Outlook. A dialog box is open. Close it and try again." ...

Remove Options under Account Actions Button
Can anyone tell me how I can hide specific items under the Account > (Actions Button) for example remove "Delete Account" from the drop down menu? Hi, Remove the rights of deletion of Account from the roles and "Delete Account" button will disappear. -- uMar Khan :: MS CRM MVP CRM Freelance Consultant Email :: imumar at gmail dot com Blog :: http://umarkhan.wordpress.com MVP :: https://mvp.support.microsoft.com/default.aspx/profile/umar.khan "Sixty4" wrote: > Can anyone tell me how I can hide specific items under the Account > > (Actions Button)...

Function help
I'm trying to create a spreadsheet, whereas values from column 1 are being used to calculate multiplied by column 2, showing the results in column 3. I also need to show such values from column 3 in another column (4) as hard data. However, if the value in column 3 equals 0.00, I want the value to be blank in column 4. Can anyone help with an appropriate function to use? I consider myself to be an intermediate Excel user, but, this one is absolutely baffling me???? Hi, Hope I understand the problem: In C1 use =A1*B1, copy this formula down the column In D1 =IF(C1=0," "...

Money 2001 Statement download stopped working
Within the past three weeks I have repeatedly attempted to download transactions from my bank (RBC). The program connects with the bank, the download process appears to occur but no new transactions ever show up in either my bank or Visa accounts. This process always worked flawlessly. Is anyone else having this problem? and is there a patch / upgrade or fix that is needed? I'm having the same problem. I use San Diego County Credit Union. I even contacted them thinking their end was broken, and they said it worked just fine. I have Money 2001 which came with my computer....

Setting the display format of a query using the DateDiff function
I have a question concerning the display of a calculated field based on the DateDiff function. Assume there exist “Start Time” and “End Time” fields that contain valid date & time information, and the date and time difference between these two fields is 75 minutes. I have created the following queries successfully… Duration (Min): DateDiff("n",[Start Time],[End Time]) Duration (Hrs): DateDiff("h",[Start Time],[End Time]) The “Duration (Min)” query shows the following result: 75 The “Duration (Hrs)” query shows the following result: 1 I am trying to find a method...

Running CHKDSK at start up
Is there a way to run chkdsk f/r on all five drives on one PC at start up? PC runs Windows XP Pro SP3. This way all drives would be checked and errors fixed, if necessary, in one go, at start up on this machine. We intend to do this on this heavily used PC from time to time - we do not need the desired chkdsk functionality to kick in at every boot! Regards and TIA. Avatar -------- "Avatar" <Avatar@re.birth> wrote in message news:hrb4n2$53i$1@news.eternal-september.org... > Is there a way to run chkdsk f/r on all five drives on one PC at start up? ...

How do I add consecutive numbers but start over at a break in the.
add consecutive numbers but start over at a break in them. I'm trying to calculate consecutive days of attendance. ...

Starting a new paragraph within a cell
How do you create a line break within a cell? For example, if wanting to list 2 or more items it looks better if each one is printed under the other as a list. Or in a comment column when needing to start a new paragraph, again within the cell. Hi. You can press Alt + Enter to create a line break within a cell. Kath firman wrote: > How do you create a line break within a cell? For example, if wanting to list > 2 or more items it looks better if each one is printed under the other as a > list. Or in a comment column when needing to start a new paragraph, again > within th...

Can't Start Any Program
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel It has been two weeks since I can open an Office Program. Please HEEELP! This is my word error report: Microsoft Error Reporting log version: 2.0 Error Signature: Exception: EXC_BAD_ACCESS Date/Time: 2009-09-09 19:04:02 -0400 Application Name: Microsoft Word Application Bundle ID: com.microsoft.Word Application Signature: MSWD Application Version: 12.2.0.090605 Crashed Module Name: CoreFoundation Crashed Module Version: unknown Crashed Module Offset: 0x00075354 Blame Module Name: CoreFoundation Blame Module Version: unk...

Weighted Average function
Is there a weighted average function in Excel? if not, any clever ideas on how to create one? -- shekala ------------------------------------------------------------------------ shekala's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=27986 View this thread: http://www.excelforum.com/showthread.php?threadid=492080 I am sure sumproduct would do it -- duane ------------------------------------------------------------------------ duane's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=11624 View this thread: http://www.excelforu...

"Next" button for reading NG from Internet
I am using Microsoft's site to read the posts in NG. (http://www.microsoft.com/office/community). There is a minor problem which wastes time. After reading a post, in order to read next one, I have to go back to previous page and click the next post. However if there could be a "Next" button in the end of posts, upon reading a post, it could be easier to go to next post. If possible please add a "Next" button to the end of posts in your NG site. Thanks in advance. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions ...

How to: Enable a control that is currently disabled???
I have a form with controls that are disabled by default. The form is used to display part information. However, if the form calling this form contains a part number not already in the system, I would like to enable all of the controls so the needed information can be entered for this new part number. I've looked at the Enable property but can not figure out the syntax. Please help. Thanks. On Jan 5, 3:06=A0pm, Weeble <Wee...@discussions.microsoft.com> wrote: > I have a form with controls that are disabled by default. The form is use= d to > display part infor...

CD does not start
After installing XP on a new disk everything appeared normal. I was able to install a few applications from their cds. Then I attempted to install an application from a downloaded file, but it did not work. So I installed MS frame works and windows installer. Then I was able to install the application from the downloaded file. When I attempted to install another application from its cd (with autorun), nothing happened, namely it fail to start. If I force the setup.exe from Explorer, the error message shows up: "the application configuration is incorrect". Thinking for...

To resize the font on the buttons in MFC GUI, Windows CE
I have a GUI written in MFC for a Windows CE device. However I need to resize some of the buttons and their corresponding text. I can't figure out how to change font size. The following code fragments did not help: Trial 1: *CFont fnt2; fnt2.CreateFont(10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, L"MS Shell Dlg"); m_btnForceAnalog.SetFont(&fnt2); fnt2.Detach(); Trial 2: LOGFONT lf; memset(&lf,0,sizeof(LOGFONT)); lf.lfHeight = 5; // Request a 100-pixel-height font // D...