How Dialog Can Check Thread Status?

I am beginning a thread when a button is pressed in a 
modal dialog. I want to be able send status back to the 
dialog so I can display it in a edit box. The thread is 
running a test on a SCSI device so I want to display 
status as test progresses.  Any help on how I might go 
about accomplishing this would greatly be appreciated.

I am noivce windows programmer so please bare this in mind.
0
8/28/2003 1:58:56 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
811 Views

Similar Articles

[PageSpeed] 35

Steve Heck wrote:
> 
> I am beginning a thread when a button is pressed in a
> modal dialog. I want to be able send status back to the
> dialog so I can display it in a edit box. The thread is
> running a test on a SCSI device so I want to display
> status as test progresses.  Any help on how I might go
> about accomplishing this would greatly be appreciated.
> 
> I am noivce windows programmer so please bare this in mind.

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

--
Scott McPhillips [VC++ MVP]
0
scottmcp (342)
8/28/2003 10:45:24 PM
See my essays on threading on my MVP Tips site. Essentially, you don't "detect" the state
of the thread; the thread informs you explicitly when it is finished.

However, to simply run a thread that sends notifications back is easy, and my essay covers
it in detail.
				joe

On Thu, 28 Aug 2003 06:58:56 -0700, "Steve Heck" <steve.heck@am.sony.com> wrote:

>I am beginning a thread when a button is pressed in a 
>modal dialog. I want to be able send status back to the 
>dialog so I can display it in a edit box. The thread is 
>running a test on a SCSI device so I want to display 
>status as test progresses.  Any help on how I might go 
>about accomplishing this would greatly be appreciated.
>
>I am noivce windows programmer so please bare this in mind.

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/29/2003 2:09:17 AM
Hello Steve,

Thanks for your post. As suggested by Igor, you can pass the HWND of dialog 
to the thread, and then the thread can manipulate the dialog by sending 
message and corresponding functions. I wrote the following code snippet for 
your reference:

//--------------code snippet-------------------
DWORD WINAPI MyThreadFunc( LPVOID lpParam ) 
{ 
   ......
   //Suppose there's an EDIT box (IDC_EDIT) on the dialog
   ::SetDlgItemText((HWND)lpParam, IDC_EDIT1, "Hello World");
   return 0;
}

void CMyDlgDlg::OnButton1() 
{
   DWORD dwThreadId, dwThrdParam = 1;
   HANDLE hThread;

   hThread = CreateThread(
      NULL,
      0,
      MyThreadFunc,
      this->GetSafeHwnd(),
      0,
      &dwThreadId);
   ......
}
//-----------------end of-------------------------

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! �C www.microsoft.com/security
This posting is provided ��as is�� with no warranties and confers no rights.

0
timhuang (89)
8/29/2003 6:44:40 AM
Hello Tian,

This is exactly what I was looking for!

Thanks,
Steve Heck
>-----Original Message-----
>Hello Steve,
>
>Thanks for your post. As suggested by Igor, you can pass=20
the HWND of dialog=20
>to the thread, and then the thread can manipulate the=20
dialog by sending=20
>message and corresponding functions. I wrote the=20
following code snippet for=20
>your reference:
>
>//--------------code snippet-------------------
>DWORD WINAPI MyThreadFunc( LPVOID lpParam )=20
>{=20
>   ......
>   //Suppose there's an EDIT box (IDC_EDIT) on the dialog
>   ::SetDlgItemText((HWND)lpParam, IDC_EDIT1, "Hello=20
World");
>   return 0;
>}
>
>void CMyDlgDlg::OnButton1()=20
>{
>   DWORD dwThreadId, dwThrdParam =3D 1;
>   HANDLE hThread;
>
>   hThread =3D CreateThread(
>      NULL,
>      0,
>      MyThreadFunc,
>      this->GetSafeHwnd(),
>      0,
>      &dwThreadId);
>   ......
>}
>//-----------------end of-------------------------
>
>Hope this helps.
>
>Regards,
>
>HuangTM
>Microsoft Online Partner Support
>MCSE/MCSD
>
>Get Secure! =A8C www.microsoft.com/security
>This posting is provided =A1=B0as is=A1=B1 with no warranties and=20
confers no rights.
>
>.
>
0
8/29/2003 9:10:35 PM
I hope not. It can't work reliably. Don't use it.
					joe

On Fri, 29 Aug 2003 14:10:35 -0700, "Steve Heck" <steve.heck@am.sony.com> wrote:

>Hello Tian,
>
>This is exactly what I was looking for!
>
>Thanks,
>Steve Heck
>>-----Original Message-----
>>Hello Steve,
>>
>>Thanks for your post. As suggested by Igor, you can pass 
>the HWND of dialog 
>>to the thread, and then the thread can manipulate the 
>dialog by sending 
>>message and corresponding functions. I wrote the 
>following code snippet for 
>>your reference:
>>
>>//--------------code snippet-------------------
>>DWORD WINAPI MyThreadFunc( LPVOID lpParam ) 
>>{ 
>>   ......
>>   //Suppose there's an EDIT box (IDC_EDIT) on the dialog
>>   ::SetDlgItemText((HWND)lpParam, IDC_EDIT1, "Hello 
>World");
>>   return 0;
>>}
>>
>>void CMyDlgDlg::OnButton1() 
>>{
>>   DWORD dwThreadId, dwThrdParam = 1;
>>   HANDLE hThread;
>>
>>   hThread = CreateThread(
>>      NULL,
>>      0,
>>      MyThreadFunc,
>>      this->GetSafeHwnd(),
>>      0,
>>      &dwThreadId);
>>   ......
>>}
>>//-----------------end of-------------------------
>>
>>Hope this helps.
>>
>>Regards,
>>
>>HuangTM
>>Microsoft Online Partner Support
>>MCSE/MCSD
>>
>>Get Secure! �C www.microsoft.com/security
>>This posting is provided ��as is�� with no warranties and 
>confers no rights.
>>
>>.
>>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/30/2003 1:26:55 AM
Hi Joe,

Thanks for your feedback.

I knew that AfxBeginThread is the MFC version, while CreateThread is the 
Win32 version. When I use CreateThread, MFC isn't initialized on that 
thread, so stuff like MFC handle maps and what are not actually available 
to the MFC code running in that thread. That's the reason why I pass native 
HANDLE to the Window to thread and simply calls the Win32 API 
SetDlgItemText() which just sends a WM_SETTEXT message to the specified 
control.

In addition, we should not expect to be able to access any MFC objects not 
created within your thread even with AfxBeginThread. Because each thread 
gets its own handle map within MFC, which means, for instance, that a 
handle to a CWnd passed to a thread method may be invalid inside the 
thread. Instead, we should pass handles to threads as their native HANDLE 
type, and then use the FromHandle or Attach methods to obtain a handle to 
an MFC object.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! �C www.microsoft.com/security
This posting is provided ��as is�� with no warranties and confers no rights.

0
timhuang (89)
8/31/2003 10:57:31 AM
Reply:

Similar Artilces:

Howto: Check if Task Accepted or Declined
Hello all I use custom Exchange mailbox store global event sink. My COM sink processed any item in mailbox store. It occured by OnSave;OnDelete events. My COM sink process assigned taskrequest: if user accepted or declined assigned task. The question is how can i determinate if current task accepted or declined by user? Which MAPI property i can use? Thanks, Alexander. Don't get my words for free, but here is how I'd try: 1. Implement OnSave event (on either IExStoreSyncEvents or IExStoreAsyncEvents) and use the item URL (and possibly the passed IExStoreEventInfo) to get t...

calls to AfxGetThread on non-MFC thread
Hello i'm developing Internet Explorer extension. It uses MFC. It has some dialogs with help buttons. Clicks on help buttons are handled in my CWinApp-derived class message map. When IE opens new window it creates new thread for it, and this is not an MFC thread, and copy of my extension loads in this non-MFC thread. So, when WM_COMMAND from help button is routing in CWnd::OnCmdMsg it's finally have to be routed to CWinApp-derived class message map. To get the thread AfxGetThread is called, but it returns NULL there, cause thread is not an MFC one. I'm using VS2005 now. The p...

I can not see add task in scheduled task in win server 2003
Hi, i have a problem with scheduled task in windows 2003 sd. I cannot see the add a new task in the schedules task panel. I tried wth schtask and th result is this: It has prevented the user to create new tasks. I verified the permisions with cacls and all are rigth. Help! Thanks Fernando "Fernando Martinez" <FernandoMartinez@discussions.microsoft.com> wrote in message news:BE65D03C-E925-4FE6-9D02-DF0D3ECB0714@microsoft.com... > Hi, i have a problem with scheduled task in windows 2003 sd. > I cannot see the add a new task in the schedules task panel. >...

getting message interface error and can't send or receive emails
If I try to move or delete an email I get a message - "The message interface has returned an unknown error. If this problem persists restart outlook." I have restarted outlook several times and also re-booted my PC several times. Still to no avail I cannot send or receive emails now either. While Outlook is closed, rename the Outcmd.dat and *.srs files, then open Outlook again and see if this helped. If not, please post back. Also, please post what version of Outlook you're using. If you have reached the limit on your PST, that could cause the error as well. -- Kathleen...

how can i make furmulas for converting gram to microliter,thanks
please help me to find how i can convert gram to microliter What kind of Liquid are we dealing with !? Micky "aedrion" wrote: > please help me to find how i can convert gram to microliter Hi aedrion, There is no direct conversion - grams are units of mass (weight); microlitres are units of volume. If, of course, you know how many microlitres of a substance weighs 1 gram, then you can do the conversion for that substance. -- Cheers macropod [Microsoft MVP - Word] "aedrion" <aedrion@discussions.microsoft.com> wrote in message news:CDE712...

can I forward mail without opening/viewing?
I know that sounds like a weird question, but my ISP invites users to forward spam to a special mailboxes in their never-ending (heh) effort to reduce the flow of the junk. With Outlook, I cannot figure out how to forward a message without its opening up for viewing. This is exactly what I don't want to do, because if it's html I really don't want to validate my email address. TIA Jason -- reverse my name in email address Jason, What you would have to do is create "rules" to do this, which you can set Outlook to if it receives a certain criteria, it can say FWD ...

can't find registration library
Hi - Opening up my money 2006 software and i get a weird thing: accept money 2006 internet based services policy (i have the software for a while now), when i accept i get an error message : unable to load registration library (dll). anyone aware of this problem? any fix to this problem? In microsoft.public.money, ljmalka wrote: >Hi - Opening up my money 2006 software and i get a weird thing: accept money >2006 internet based services policy (i have the software for a while now), >when i accept i get an error message : unable to load registration library >(dll). anyone awar...

Check out this security update
--dktbsdmag Content-Type: multipart/related; boundary="yhsexyabsgvroelpt"; type="multipart/alternative" --yhsexyabsgvroelpt Content-Type: multipart/alternative; boundary="qrqoxwxqjupwvgr" --qrqoxwxqjupwvgr Content-Type: text/plain Content-Transfer-Encoding: quoted-printable MS Consumer this is the latest version of security update, the "October 2003, Cumulative Patch" update which resolves all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express. Install now to continue keeping your computer secure from th...

How can I apply rules on read email only?
I have an extenive list of mail sorts, but I would like them to run only after I have read my mail. I also have screening tools for deletes, and junk mail and presorts for mail that I don't reglarly read. In order to sort the read mail now, I have to manuallly got into rules and turn on the rules for one pass on the mail at the end ot the day to pick up the mail that I have read. It would be nice to be able to "turn on all rules now" or to have them automaically screen the read mail when I start up Outlook. Any workarounds for this? I am just a few months into using Outlo...

Oops! can I change border now?
Well I've just spent months working on my first Publisher document. I've created a 34 page catalog which looks quite nice... I spent a lot of time making sure the master page was nice and even. I did a test print out and it looked fine...however... I forgot that the pages will be stapled...and that though the catalog is acceptable the way it is...I should really move the entire printed area over slightly to the right. Since all pages have used the same master page layout...is there some simple way to get all objects shifted over...on all pages? It would be way too time consuming to mo...

Can a user update his own information
I've played around with the permissions but cannot seem to give a user permission to update his own phone numbers, email, etc. in CRM. This doesn't seem like an IT function at all but we keep having to update this information for our CRM users. Please help. ...

Outlook data file check
Hello, I am using Outlook 2007 on XPSP2. Quite often on startup I get a message the Outlook is doing a file check and performance may be slow. I also often get on computer startup a message requesting me to send an error report to Microsoft that includes a few episodes of Outlook not responding. Any idea what this could be about and how to prevent both? -- Thanks, Bob ...

Use of Paid Transaction Removal
Hello, I was wondering if anyone can tell me the reason a person would use the Paid Transaction Removal Screen and select only checks and then a date. When I did this in a test environment, it removed all checks before that date. Wouldn't it make more sense to provide a range, so as to not remove so many checks going backwards? Or am I using this tool wrong? Also, what are the ramifications of using this tool, account balancing wise? Thanks JOsh Josh, The Paid Transaction Removal process simply moves transactions from the OPEN status and tables to HIST (Historical) status and...

Check Alignment accounts payable
Hello, What/How do I customize my check alignment to fit my chech stock? How can I move around date, Invoice vendor name etc? Thanks D You will need to use Great Plains' built-in Report Writer to do this. If you don't know how to use it, your best bet is to talk to a local Great Plains partner organization that can teach you how to do it. Alternatively, you could take an ecourse on Report Writer. "David Chang" <DavidChang@discussions.microsoft.com> wrote in message news:F114F827-E848-4FFE-B323-9D8C0D346DE0@microsoft.com... > Hello, > > What/How do I c...

Electronic Bank Reconciliation (eBank Rec) is not ticking off the FIRST check in our download
We are using eBankRec on Great Plains 7.5, and sometimes (usually?) it doesn't tick off the very first check that is in the download file. We have considered that it might be due to the transaction date being later than the bank cleared date, but that is not the case. It is always the FIRST check record in the file... first in terms of the check NUMBER... (not the FIRST RECORD, or even the first check record, but the first (earliest, sequentially) check NUMBER. Any idea why this could be happening? ...

how to get size of text in a Dialog?
MessageBoxes usually size themself according to the text displayed, depending on fontsize and number of chars. can anyone please explain (or point me to an URL where it is explained) how they do it? To keep it simple, lets say we have just a CStatic and a Text in it. How do i get the "optimal" values for the region for MoveWindow() ? ".rhavin grobert" <clqrq@yahoo.de> wrote in message news:1158252329.933561.100380@d34g2000cwd.googlegroups.com... > MessageBoxes usually size themself according to the text displayed, > depending on fontsize and number of char...

how can i add hotmail account in microsoft outlook??
how can i add hotmail account in microsoft outlook?? What version? >-----Original Message----- >how can i add hotmail account in microsoft outlook?? > > >. > office xp "Mark Gable" <mgable@ficomp.com> wrote in message news:023101c34bc3$de3643b0$a301280a@phx.gbl... > What version? > > >-----Original Message----- > >how can i add hotmail account in microsoft outlook?? > > > > > >. > > As far as I know, it's not possible because Hotmail doesn't give out their POP3 and SMTP server information. If you know t...

can't update links...can't find links
I have a workbook (Two.xls) that pulls data from another workbook (One.xls). When opening Two.xls i tell it to update data, and I then receive a message saying that there are links to other workbooks that connot be updated. When searching for the links to this source (One.xls) I am unable to find the links. I search for ".xls" and"[" and find nothing. I have intentional links to One.xls so I can't just break all links, nor can I simply search and delete all instances of .xls, however, the intentional links work correctly (they are able to update)...is there a way...

Can I link *.jpg files to Excel cells?
I would like to connect pictures to cells on a spreadsheet. Ideally, I'd like to connect more than one to a cell. Or to its row. That would work OK also. Can I do it? TIA LAS You can hyperlink a cell to an image stored elsewhere or to an image stored within the workbook. How you do it depends upon the purpose of the linking and the ultimate results you are looking for. Gord Dibben MS Excel MVP On Fri, 25 Jun 2010 17:26:13 -0400, "LAS" <FakeMail@Hotmail.com> wrote: >I would like to connect pictures to cells on a spreadsheet. Ideally, I'd >lik...

Help Can't Find Automatic Security Settings in OL SP3???
I installed SP3 for MS Office 2003. I liked the feature in OL that prevented images from downloading unless you right clicked on them. I thought the settings were in tools->options->security but I could not find a place to set this useful feature. Did SP3 erase this feature or is it located somewhere else? TIA, Pete I was really stupid on this one. When installing Office, I grabbed the wrong set of disks by accident. I installed XP instead of 2003, and should have been tipped off by the different security patches. Sorry, Pete "Peter de B. Harrington" <peter.harr...

What bills can be paid online?
Preface: new to online payments through my bank; using M2006. I am trying to pay a credit card bill using online bill pay. The credit card account is setup in Money. I have all of the address/account information entered correctly, with payment type "Write Check". When I go to the manage bills screen, there is no pay-online check box next to this transaction; however other transactions (such as uitlities) have the check box and I have successfully paid them. While playing with the transaction details, I changed the category from (I can't recall exactly, but Money assig...

Can a workbook be opened w/out Excel on the host machine??
Hi all, I need to distribute my workbook to several sponsors in different locations (cities and states). Some have Excel on their workstations, some don't. Is there a way to package the file to include some sort of self-executable Excel reader -like PowerPoint does-? Does an Excel Reader even exist? The end users will have need to select vba userforms and command buttons to navigate through the workbook, so there does need to be some interactivity capability and not just "read only". Thanks! http://office.microsoft.com/en-gb/officeupdate/CD011347961033.aspx is a free vie...

Why can't I run my query multiple times?
I've created a query that works the first time I run it but gives me an error saying "Numeric field overflow" if I run it again. The only way I can get the query to run is by making a change to the design view in which case it will run once. You need to post the SQL so we can see what you're dealing with. Bob JonV wrote: >I've created a query that works the first time I run it but gives me an error >saying "Numeric field overflow" if I run it again. The only way I can get >the query to run is by making a change to the design view in which case...

Can we have a TVF call inside a Scalar function ?
I am using the following query select 'level' = case when dbo.function1 = 1 then ( case when ( dbo.function2(dbo.function3, 1) > 0) then 3 end ) end it is showing error "Cannot find either column "dbo" or the user-defined function or aggregate dbo.function3 " dbo.function3 is TVF. so i tried with this select 'level' = case when dbo.function1 = 1 then ( case when ( dbo.function2((select * from dbo.function3), 1) > 0) then 3 end ) end then i have "Only one expression can be specified in the select list w...

Can you display numbers as words in excel (eg. 10 as ten)?
Can you display numbers as words in excel (eg. 10 as ten)? Basically I have standard forms in Excel that require a number both in numerics and in words, like a cheque. Ideally I would like to type in the number and for another cell to = this number but display it in words. Is this possible using Excel 2000? Thanks. Stefan, You could type in a list with numbers in one column and the associated words in the second column, then use VLOOKUP. 1 one 2 two 3 three .... 39 thirty-nine 40 forty .... Eric "Stefan White" wrote: > Can you display numbers as words in exce...