sending CString to CStatic label control from worker thread

I need to send a CString from a thread to a static label on the main 
dialog form.  I think I have the thread working okay, but I am unsure 
how to send the CString to the dialog control.  I have seen information 
on using PostMessage and SendMessage, but I don't really understand how 
to use these functions.

Obviously I can't do like I tried below and I can't get a pointer to the 
control from the thread function, so just how do I say send the word 
"hello" to the SetWindowText() function of the label control on the 
dialog form.  I have looked on the Internet and in several books, but I 
still don't quite understand without an exact example of how to do this. 
It seems like all that PostMessage can do is say repaint the screen and 
other simple tasks, but how do I do something with an individual control.

	Z.K.
--------------------------------------


CWinThread* pThread = 
AfxBeginThread(WorkerThreadProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
	
MessageBox("Thread Started");


UINT CInterfaceKitTestDlg::WorkerThreadProc( LPVOID Param )
{
	CString temp;
	CPhidgetServoHandle Servo = 0;
	double motorPos = 0.0;

	
	CInterfaceKitTestDlg * pTest = (CInterfaceKitTestDlg *)Param;

	pTest->PostMessage(IDC_INPUT,"hello");  //just an example of 							 
//what I would
                                             //like to do, unsure of how.
                                             //this is not meant to be a
                                             //real statement.	

	CPhidgetServo_getMotorPosition(Servo,0,&motorPos);
	temp.Format("Motor Position 0 = %f",motorPos);
	AfxMessageBox(temp);
	//m_input.SetWindowText(temp);

	return TRUE;
}
0
nospam2791 (369)
5/13/2006 11:16:09 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
1270 Views

Similar Articles

[PageSpeed] 57

Z.K. wrote:

> I need to send a CString from a thread to a static label on the main 
> dialog form.  I think I have the thread working okay, but I am unsure 
> how to send the CString to the dialog control.  I have seen information 
> on using PostMessage and SendMessage, but I don't really understand how 
> to use these functions.
> 
> Obviously I can't do like I tried below and I can't get a pointer to the 
> control from the thread function, so just how do I say send the word 
> "hello" to the SetWindowText() function of the label control on the 
> dialog form.  I have looked on the Internet and in several books, but I 
> still don't quite understand without an exact example of how to do this. 
> It seems like all that PostMessage can do is say repaint the screen and 
> other simple tasks, but how do I do something with an individual control.
> 
>     Z.K.
> --------------------------------------
> 
> 
> CWinThread* pThread = 
> AfxBeginThread(WorkerThreadProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
>     
> MessageBox("Thread Started");
> 
> 
> UINT CInterfaceKitTestDlg::WorkerThreadProc( LPVOID Param )
> {
>     CString temp;
>     CPhidgetServoHandle Servo = 0;
>     double motorPos = 0.0;
> 
>     
>     CInterfaceKitTestDlg * pTest = (CInterfaceKitTestDlg *)Param;
> 
>     pTest->PostMessage(IDC_INPUT,"hello");  //just an example 
> of                              //what I would
>                                             //like to do, unsure of how.
>                                             //this is not meant to be a
>                                             //real statement.   
> 
>     CPhidgetServo_getMotorPosition(Servo,0,&motorPos);
>     temp.Format("Motor Position 0 = %f",motorPos);
>     AfxMessageBox(temp);
>     //m_input.SetWindowText(temp);
> 
>     return TRUE;
> }

Z.K.:

If you post or send a custom mesage to the dialog itself, then in the 
handler you can do anything you want, including setting the text of a 
control.

In MyDialog.h:

Define message:

#define UM_MY_MESSAGE WM_APP+1

Prototype:

afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);

In MyDialog.cpp:

Message map entry:

ON_MESSAGE(UM_MY_MESSAGE, OnMyMessage)

Usage:

CMyDialog* pDlg =(CMyDialog*)pParam;
LPCTSTR msg = _T("Hello");
pDlg->PostMessage(UM_MY_MESSAGE, (WPARAM)msg);

Handler:

LRESULT CMyDialog::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
   LPCTSTR msg = (LPCTSTR)wParam;
   GetDlgItem(IDC_INPUT)->SetWindowText(msg);
   return 1;
}

Try it!

David Wilkinson


0
no-reply8010 (1791)
5/13/2006 12:30:33 PM
David Wilkinson wrote:
> Z.K. wrote:
> 
>> I need to send a CString from a thread to a static label on the main 
>> dialog form.  I think I have the thread working okay, but I am unsure 
>> how to send the CString to the dialog control.  I have seen 
>> information on using PostMessage and SendMessage, but I don't really 
>> understand how to use these functions.
>>
>> Obviously I can't do like I tried below and I can't get a pointer to 
>> the control from the thread function, so just how do I say send the 
>> word "hello" to the SetWindowText() function of the label control on 
>> the dialog form.  I have looked on the Internet and in several books, 
>> but I still don't quite understand without an exact example of how to 
>> do this. It seems like all that PostMessage can do is say repaint the 
>> screen and other simple tasks, but how do I do something with an 
>> individual control.
>>
>>     Z.K.
>> --------------------------------------
>>
>>
>> CWinThread* pThread = 
>> AfxBeginThread(WorkerThreadProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
>>     MessageBox("Thread Started");
>>
>>
>> UINT CInterfaceKitTestDlg::WorkerThreadProc( LPVOID Param )
>> {
>>     CString temp;
>>     CPhidgetServoHandle Servo = 0;
>>     double motorPos = 0.0;
>>
>>         CInterfaceKitTestDlg * pTest = (CInterfaceKitTestDlg *)Param;
>>
>>     pTest->PostMessage(IDC_INPUT,"hello");  //just an example 
>> of                              //what I would
>>                                             //like to do, unsure of how.
>>                                             //this is not meant to be a
>>                                             //real statement.  
>>     CPhidgetServo_getMotorPosition(Servo,0,&motorPos);
>>     temp.Format("Motor Position 0 = %f",motorPos);
>>     AfxMessageBox(temp);
>>     //m_input.SetWindowText(temp);
>>
>>     return TRUE;
>> }
> 
> 
> Z.K.:
> 
> If you post or send a custom mesage to the dialog itself, then in the 
> handler you can do anything you want, including setting the text of a 
> control.
> 
> In MyDialog.h:
> 
> Define message:
> 
> #define UM_MY_MESSAGE WM_APP+1
> 
> Prototype:
> 
> afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
> 
> In MyDialog.cpp:
> 
> Message map entry:
> 
> ON_MESSAGE(UM_MY_MESSAGE, OnMyMessage)
> 
> Usage:
> 
> CMyDialog* pDlg =(CMyDialog*)pParam;
> LPCTSTR msg = _T("Hello");
> pDlg->PostMessage(UM_MY_MESSAGE, (WPARAM)msg);
> 
> Handler:
> 
> LRESULT CMyDialog::OnMyMessage(WPARAM wParam, LPARAM lParam)
> {
>   LPCTSTR msg = (LPCTSTR)wParam;
>   GetDlgItem(IDC_INPUT)->SetWindowText(msg);
>   return 1;
> }
> 
> Try it!
> 
> David Wilkinson
> 
> 

Oh okay, that makes it more understandable, thanks.

    Z.K.
0
nospam2791 (369)
5/13/2006 11:09:17 PM
Read my essay on worker threads on my MVP Tips site.
				joe

On Sat, 13 May 2006 04:16:09 -0700, "Z.K." <nospam@nospam.net> wrote:

>I need to send a CString from a thread to a static label on the main 
>dialog form.  I think I have the thread working okay, but I am unsure 
>how to send the CString to the dialog control.  I have seen information 
>on using PostMessage and SendMessage, but I don't really understand how 
>to use these functions.
>
>Obviously I can't do like I tried below and I can't get a pointer to the 
>control from the thread function, so just how do I say send the word 
>"hello" to the SetWindowText() function of the label control on the 
>dialog form.  I have looked on the Internet and in several books, but I 
>still don't quite understand without an exact example of how to do this. 
>It seems like all that PostMessage can do is say repaint the screen and 
>other simple tasks, but how do I do something with an individual control.
>
>	Z.K.
>--------------------------------------
>
>
>CWinThread* pThread = 
>AfxBeginThread(WorkerThreadProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
>	
>MessageBox("Thread Started");
>
>
>UINT CInterfaceKitTestDlg::WorkerThreadProc( LPVOID Param )
>{
>	CString temp;
>	CPhidgetServoHandle Servo = 0;
>	double motorPos = 0.0;
>
>	
>	CInterfaceKitTestDlg * pTest = (CInterfaceKitTestDlg *)Param;
>
>	pTest->PostMessage(IDC_INPUT,"hello");  //just an example of 							 
>//what I would
>                                             //like to do, unsure of how.
>                                             //this is not meant to be a
>                                             //real statement.	
>
>	CPhidgetServo_getMotorPosition(Servo,0,&motorPos);
>	temp.Format("Motor Position 0 = %f",motorPos);
>	AfxMessageBox(temp);
>	//m_input.SetWindowText(temp);
>
>	return TRUE;
>}
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
-- 
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
0
newcomer (15975)
5/14/2006 2:45:31 AM
Reply:

Similar Artilces:

Error message when trying to send an email
Installed outlook 2003 Set up a POP email account the "test account settings" returns no error When trying to send an email, the following message appears: 'the operation failed. an object could not be found' Have tried to repair and re-install office 2003 Still the same problem Outlook express with the same settings on the same machine runs without a problem... What should I do??? HELP!!! Already tried recreating your mail profile in Control Panel-> Mail-> button Show Profiles? -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do th...

using Control to populate combobox
Dear, I have a form where i have to populate diferent comboboxes at diferent stages with data from a seperate database. Im trying to write a Function that would easally repeate the task, the main problem is specifeing what combobox to use. here is a part of my coding Public Sub LoadCB(cbName As Control, SelectionString As String) cbCount = 0 Set rstLoadCB = VMSDatabase.OpenRecordset(SelectionString) With rstLoadCB .MoveLast cbCount = .Counter .MoveFirst If TypeName(CB) = cbName Then End If Next CB End With Set rstLoadCB = Nothing...

how can i add a picture to my return address label
Can I use Word to add pictures to my return address labels? Hi debbie (debbie@discussions.microsoft.com), in the newsgroups you posted: || Can I use Word to add pictures to my return address labels? You can use Word or Publisher to create address labels with pictures. Go to Insert > Picture > From File on the menu and browse to your picture of choice. You could also use the Microsoft Clipart using the same method but go to Insert > Picture > Clipart. -- Brian Kvalheim Microsoft Publisher MVP http://www.publishermvps.com ~pay it forward~ This posting is provided "AS IS&...

Allowing other applicaitons to send e-mail
Hello, I am a novice Microsoft Access programmer and I have some code that sends an e-mail with some attachments. This all works fine however every e-mail is prompted with an Outlook message asking me if I want to allow the e-mail to be sent by another programme. I know there is ClickYesPro freeware to overcome this however I am on a corporate network and the powers that be will not let me install this. Is there a way to change the Outlook settings to allow specific applicaitons to send e-mails without the warning? If I need to code Outlook then I will have a go! Many thanks. Marti...

comdlg32.ocx
I have used an application developed in Access 2003 very well. I bought a new machine with Windows 7 and reloaded Access 2003 (Office 2003). It now does not run a function within the application. I believe comdlg32.ocx is the problem. I unselected Microsoft Common Dialog Control 3.0 (SP3) and it has disappeared as well. Error Run time error 438 - Object does not support this property or object Function Private Function fileName() As String Me.CommandOpenFileDialogue.Filter = "Text|*.txt|All|*.*" Me.CommandOpenFileDialogue.ShowOpen fileName = Me.CommandOpenFil...

CAsyncSocket sends from one computer to the other but not the other way around
I have written a chat server/client combo using delphi. I am rewriting it in MFC. I have the server component almost complete along with a test client, to the point where it is functional. When I test it on my dev machine it works almost flawlessly. However, when I take the server exe and move it to my other machine that I use for a server it doesn't work. What happens is the client sends the data but the server never recieves the data. The client returns the number of characters sent without an error, but the onrecieve event is never triggered on the server. These are two local machi...

Cant outo send mail
have just switched to outlook from Oe 6 and having sorted the blocking of Attachments have found that when I click send and receive Outlook checks all accounts and receives and processes all mail rules but for some reason does not send any mail in the outbox. The mail can be sent by clicking on it and selecting send. When I shut down it says I have outgoing mail but still does not send it. Could some one tell me what setting I have missed please Sorry for the second post I'm using Outlook XP at SP2 Thanks Baron ...

How can a list control respond a tree control message?
I create a list control (CMyList) and a tree control (CMyTree) and want to display different items when the selection changed in the tree control. What I have done is right click my tree control on resource editer and choose 'Add Event Handler...'. I choose TVN_SELCHANGED from Message type and CMyList from Class list. When I run my program and click different item in the tree control, the hangler function in class CMyList does respond it. Could anybody give me some suggestion for coping with the problem? Thanks in advance. Rich I am not sure what you are asking? Do you want a ...

Send to mail recipient
When I right click on a file and go to send to, mail recipient, Windows Installer opens up and then it comes up "Either there is no defaul mail client, or the current mail client cannot fulfill the messaging request. Outlook is my default, I have checked all setting and I have tried reinstalling, etc. Any suggestions? I sure do need this feature. Thanks! Is Outlook open when you try this? Try it with Outlook open. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to ...

Send to non-existant adress and nothing happens
Hi all I have a problem on my network with NDR's.Firstly we send all our mail (via SMTP) through our ISP. We have a exc2003 server and outlook2003 clients (all with updates). I just did a test and send a mail to abc@mydomain.co.za (non-existant adress on my exchange server) and nothing comes back to me. I tried the message tracking and this is what i get : SMTP Store Driver : Message submitted from store SMTP Message submitted to Advanced Queing SMTP Started message submission to Advance Queing SMTP Message submitted to categorizer SMTP Message categorised and qeued for routing SMTP ...

Outlook docket control
How do I mark and event, such as an appointment or task, as being done without having to delete it, so that if I pull up any events or appointments regarding a certain case, that event is still reflected? Anna wrote: > How do I mark and event, such as an appointment or task, as being done > without having to delete it, so that if I pull up any events or > appointments > regarding a certain case, that event is still reflected? You can't mark it complete - appointments are considered "completed" when they have ended. You can assign a Completed category ...

there are no item in inbox, i have click on send/receive tab many
there are no item in inbox, i have click on send/receive tab many time "uttam" <uttam@discussions.microsoft.com> wrote in message news:428FA040-E7B5-47E6-B611-FB1748D71FD2@microsoft.com... > there are no item in inbox, i have click on send/receive tab many time What happens? Do you get any error messages? Did you turn on diagnostic logging to see what's happening during the send/receive? http://support.microsoft.com/kb/300479 -- Brian Tillman [MVP-Outlook] if you switch folders, do the messages show up? -- Diane Poremsky [MVP - Outlook] Outlook Tips: http:/...

"Package" error/label when embedding a BMP in OLE field
I am still getting the 'package' label when I embed a bmp image in an OLE field in my database table. I had been trying to embed jpgs until I learned the OLE server does not support them and returns the 'Package' label; however I converted my images all to bmp and tried to embed them that way, but I still get the same 'Package' label. Any ideas?? Thanks in advance... ...

Continuos sending of Packets
We have an Exchange 2003 Sp1 server. From yesterday it is sending packets to some mail servers like Yahoo & Aol. I chaecked the server. There is no Spyware or Virus. It is patched with the latest released security patches. I found that it has an established smtp connection to the target mail server & when I close the connection it will connect again. There is no email in the queues. Please Help. Payman <Payman@discussions.microsoft.com> wrote: >We have an Exchange 2003 Sp1 server. From yesterday it is sending packets to >some mail servers like Yahoo & Aol. I chae...

Outlook Calendar Labels
Hi, Our secretary is using the colour labels available in Outlook Calendar to highlight different meeting types etc... With Exchange/Outlook 2003 there are ten default calendar labels which she has edited the labels on. Now our secretary wants to know if it is possible to create more, upto 19. Has anyone ever managed this? Cheers, Joe It's not possible.=20 --=20 Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for=20 Administrators, Power Users, and D...

I updated from IE6 to IE7, now can only receive mail not sending
johan knox wrote: <nothing> PLEASE write your question in the body of the post and NOT just the subject Have a look here: http://dts-l.org/goodpost.htm What happens when you try? ...

Radio Buttons, Grouping, and Control Variables
I need to create a control variable for each radio button in a group. However, I am only able to do this for the first one in the group because the others' resource IDs aren't available in the 'Add Variable...' dialog box. Why can't I create a control variable for every radio button in a group? And how do I get around it Related question: How can I change the 'Visible' property during run-time of a control for which I've created a control variable? There should be a method function or flag... "voidxor" <anonymous@discussions.microsoft.com> skr...

Is a Thread appropriate?
Hi, I'm working on a dialog based app that utilizes PC's serial port. Up to now, the app is just capable to send. I'd like to extend it by receive functionality. Actually, port I/O isn't the issue since I'm using a dll that does it for me. The issue I discovered is that I would lock my application for user commands while waiting for some data to be received. Data arrives now and then - might be within a second or might take longer like 5 minites .... I applied a thread to workaround the locking of the application. But I don't know if that is an appropriate...

How do I control a text box via another combo box
I have read through dsome o the other answers and I just can't seem to get it. I have a table called employee information. Within that table are two fields. Retail Title and Retail Incentive. I have a form with a combo box for the the Retail Title. This field looks to a table called Retial titles which is two fields...Title and Incentive What I want to do is have it so when I choose a title in the form it populates the incentive in another text box. The combo box column count = 2 What should by settings be for my text box?(That of course if I should be using a t...

Can not see CString's value when debugging
I'm very sure I'm in the CString's life scope, but I can not see its value but only some "???". Any other type of variables are ok. But some days ago, in the same project, I can see CString's value when debugging. So, what's wrong of CString in debug mode? Now I nearly can't do the debugging job! >So, what's wrong of CString in debug mode? It's a limitation of the debugger. Newer versions of CString have optimisations for the storage of small/long strings that the debugger doesn't cater for :( Dave ...

Outlook 2002 Send/Receive error
I am using Outlook 2002 with Windows XP Professional. All of a sudden, a few hours ago, when I clicked the Send/Receive button to check for messages, the following message appeared: "Operation Failed", and it has continued to appear since. When I open up Outlook, messages are there, but I am not able to check for them myself. I had not made any setting changes myself. I have checked the settings in the Tools/Options menu and can't see anything there. Any ideas about what might have caused this condition to start, suddenly, all by itself, and where I might look for...

Threading in VBA
I know very little about VBA, Alas: I have a VBA app which contains some call backs which repospond to msgs from a server. The call backs basically receive data and notifications and display them on one the sheets. When several of the msgs come together they overwhelm the PC since the display update takes long and thus acknowledging the server may result in a connection time out. (we're talking about hundreds of msec) Is there a way to have these callbacks spawn another thread so that the app acknowdlege the server immediately and have the updates done in due time? Any help will be mos...

How do I take some of my Excel fields and make address labels?
I have Win 2000 and I have a membership in an Excel spreadsheet. Is there a way to convert some of these fields into address labels? Do I need to convert this file into another format (Access, Word, etc)? If so, which is the easiest means? By the way, my membership is over 400 names long, so anything that streamlines this project is welcomed. Thanks. Hi, Carmen. Use Mail merge. http://www.officearticles.com/word/mail_merge_labels_in_microsoft_word.htm ************ Anne Troy www.OfficeArticles.com "Carmen" <Carmen@discussions.microsoft.com> wrote in message news:4F1E91...

Help with following conversation threads
Hope someone can office some advice on this.... I'd like to consolidate several 'feedback' email addresses from our various websites so that one person can respond to each of the emails, but others can look at a single folder (and possible subfolders) and follow the various conversation threads that are in progress. I had been using distribution lists to do this but the problem is that we get so much spam (and yes we do have a spam solution - but we still get lots) that it a big waste of time for multiple individuals to all be wading through enormous amounts of the same spam. B...

Exchange 2003 All of the IT department are able to send emails as other users
Since moving over to Exchange 2003, all of the people in IT support are able to send as any other user using the 'from tab', and I dont know why this is. I looked at the security permissions of the database and there isnt a security group membership which allows 'send as' that includes all the members of IT. In addition, I added the helpdesk group 'firstline' to the database permissions and configured their permissions for 'send as' to deny, but they are still able to send as whoever they want. Am I missing something? Best, KC On 15 Sep 2006 01:27:34 -070...