Passing a CEdit object to another class..

This is how I've created a thread..

void CvcatTransmit::OnTransmitStart()
{
        thread = (CThread *)AfxBeginThread(RUNTIME_CLASS(CThread),
                                        THREAD_PRIORITY_NORMAL,
                                        0, //stacksize
                                        CREATE_SUSPENDED);
        thread->SetMe = true;
        thread->ResumeThread();
}

CThread is a class that inherits CWinThread.
Now, in my thread I need to be able to update my edit boxes which
reside in the CvcatTransmit class.

this is what I've tried:

inside of Thread.h

CEdit * MyBox;

then inside OnTransmitStart()

thread->MyBox = &vcatBox;

and it fails to work..  any other ideas?

0
9/8/2006 7:42:08 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
537 Views

Similar Articles

[PageSpeed] 19

Dont pass CEdit to the worker thread. Instead let the worker thread
post a message to main gui thread/dialog which will update the edit
box. Only pass window handles(HWND) across threads instead of CWnd*.

---
Ajay

> This is how I've created a thread..
>
> void CvcatTransmit::OnTransmitStart()
> {
>         thread = (CThread *)AfxBeginThread(RUNTIME_CLASS(CThread),
>                                         THREAD_PRIORITY_NORMAL,
>                                         0, //stacksize
>                                         CREATE_SUSPENDED);
>         thread->SetMe = true;
>         thread->ResumeThread();
> }
>
> CThread is a class that inherits CWinThread.
> Now, in my thread I need to be able to update my edit boxes which
> reside in the CvcatTransmit class.
>
> this is what I've tried:
>
> inside of Thread.h
>
> CEdit * MyBox;
>
> then inside OnTransmitStart()
>
> thread->MyBox = &vcatBox;
> 
> and it fails to work..  any other ideas?

0
ajaykalra (6842)
9/8/2006 7:47:39 PM
I apologize, can you give me an example?

Frank B.

Ajay Kalra wrote:
> Dont pass CEdit to the worker thread. Instead let the worker thread
> post a message to main gui thread/dialog which will update the edit
> box. Only pass window handles(HWND) across threads instead of CWnd*.
>
> ---
> Ajay
>
> > This is how I've created a thread..
> >
> > void CvcatTransmit::OnTransmitStart()
> > {
> >         thread = (CThread *)AfxBeginThread(RUNTIME_CLASS(CThread),
> >                                         THREAD_PRIORITY_NORMAL,
> >                                         0, //stacksize
> >                                         CREATE_SUSPENDED);
> >         thread->SetMe = true;
> >         thread->ResumeThread();
> > }
> >
> > CThread is a class that inherits CWinThread.
> > Now, in my thread I need to be able to update my edit boxes which
> > reside in the CvcatTransmit class.
> >
> > this is what I've tried:
> >
> > inside of Thread.h
> >
> > CEdit * MyBox;
> >
> > then inside OnTransmitStart()
> >
> > thread->MyBox = &vcatBox;
> > 
> > and it fails to work..  any other ideas?

0
9/8/2006 7:55:53 PM
Assign a variable in your worker thread (when it is created) something like:

// Created thread;

// I do it this way so I can use any window I want for messages.
//  Assume this sets a variable in the thread object called m_pUIWnd of type 
CWnd *
pThreadObject ->SetUIWnd(this);


From worker thread:

m_pUIWnd->SendMessage(MYMESSAGE,pMyWordData,pMyLongPointer;
// The pMyLongPointer could point to the data you want to have added in the 
control

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/postmessage.asp

Check out Joe's article:

http://www.flounder.com/uithreads.htm

Tom

"Frank B." <kefkastudio@gmail.com> wrote in message 
news:1157745352.967942.86510@d34g2000cwd.googlegroups.com...
>I apologize, can you give me an example?
>
> Frank B.
>
> Ajay Kalra wrote:
>> Dont pass CEdit to the worker thread. Instead let the worker thread
>> post a message to main gui thread/dialog which will update the edit
>> box. Only pass window handles(HWND) across threads instead of CWnd*.
>>
>> ---
>> Ajay
>>
>> > This is how I've created a thread..
>> >
>> > void CvcatTransmit::OnTransmitStart()
>> > {
>> >         thread = (CThread *)AfxBeginThread(RUNTIME_CLASS(CThread),
>> >                                         THREAD_PRIORITY_NORMAL,
>> >                                         0, //stacksize
>> >                                         CREATE_SUSPENDED);
>> >         thread->SetMe = true;
>> >         thread->ResumeThread();
>> > }
>> >
>> > CThread is a class that inherits CWinThread.
>> > Now, in my thread I need to be able to update my edit boxes which
>> > reside in the CvcatTransmit class.
>> >
>> > this is what I've tried:
>> >
>> > inside of Thread.h
>> >
>> > CEdit * MyBox;
>> >
>> > then inside OnTransmitStart()
>> >
>> > thread->MyBox = &vcatBox;
>> >
>> > and it fails to work..  any other ideas?
> 


0
tserface (3861)
9/8/2006 8:06:44 PM
Frank B. wrote:
> I apologize, can you give me an example?
> 
> Frank B.

See FAQ 11 & 12
http://vcfaq.mvps.org/mfc/11.htm

-- 
Scott McPhillips [VC++ MVP]

0
Scott
9/8/2006 8:23:54 PM
NO!!!! Do not touch a control from another thread!  PostMessage to the main thread to do
the updates.  See my essay on worker threads on my MVP Tips site.
					joe

On 8 Sep 2006 12:42:08 -0700, "Frank B." <kefkastudio@gmail.com> wrote:

>This is how I've created a thread..
>
>void CvcatTransmit::OnTransmitStart()
>{
>        thread = (CThread *)AfxBeginThread(RUNTIME_CLASS(CThread),
>                                        THREAD_PRIORITY_NORMAL,
>                                        0, //stacksize
>                                        CREATE_SUSPENDED);
>        thread->SetMe = true;
>        thread->ResumeThread();
>}
>
>CThread is a class that inherits CWinThread.
>Now, in my thread I need to be able to update my edit boxes which
>reside in the CvcatTransmit class.
>
>this is what I've tried:
>
>inside of Thread.h
>
>CEdit * MyBox;
>
>then inside OnTransmitStart()
>
>thread->MyBox = &vcatBox;
>
>and it fails to work..  any other ideas?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/9/2006 12:43:39 AM
SendMessage doesn't solve the problem.  In fact, that is exactly why you can't do
SetWindowText from a thread, because SetWindowText is just a SendMessage(WM_SETTEXT,...)
and will have all the wonderful problems.  PostMessage to the main GUI thread.
				joe

On Fri, 8 Sep 2006 13:06:44 -0700, "Tom Serface" <tserface@msn.com> wrote:

>Assign a variable in your worker thread (when it is created) something like:
>
>// Created thread;
>
>// I do it this way so I can use any window I want for messages.
>//  Assume this sets a variable in the thread object called m_pUIWnd of type 
>CWnd *
>pThreadObject ->SetUIWnd(this);
>
>
>From worker thread:
>
>m_pUIWnd->SendMessage(MYMESSAGE,pMyWordData,pMyLongPointer;
>// The pMyLongPointer could point to the data you want to have added in the 
>control
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/postmessage.asp
>
>Check out Joe's article:
>
>http://www.flounder.com/uithreads.htm
>
>Tom
>
>"Frank B." <kefkastudio@gmail.com> wrote in message 
>news:1157745352.967942.86510@d34g2000cwd.googlegroups.com...
>>I apologize, can you give me an example?
>>
>> Frank B.
>>
>> Ajay Kalra wrote:
>>> Dont pass CEdit to the worker thread. Instead let the worker thread
>>> post a message to main gui thread/dialog which will update the edit
>>> box. Only pass window handles(HWND) across threads instead of CWnd*.
>>>
>>> ---
>>> Ajay
>>>
>>> > This is how I've created a thread..
>>> >
>>> > void CvcatTransmit::OnTransmitStart()
>>> > {
>>> >         thread = (CThread *)AfxBeginThread(RUNTIME_CLASS(CThread),
>>> >                                         THREAD_PRIORITY_NORMAL,
>>> >                                         0, //stacksize
>>> >                                         CREATE_SUSPENDED);
>>> >         thread->SetMe = true;
>>> >         thread->ResumeThread();
>>> > }
>>> >
>>> > CThread is a class that inherits CWinThread.
>>> > Now, in my thread I need to be able to update my edit boxes which
>>> > reside in the CvcatTransmit class.
>>> >
>>> > this is what I've tried:
>>> >
>>> > inside of Thread.h
>>> >
>>> > CEdit * MyBox;
>>> >
>>> > then inside OnTransmitStart()
>>> >
>>> > thread->MyBox = &vcatBox;
>>> >
>>> > and it fails to work..  any other ideas?
>> 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
9/9/2006 12:45:19 AM
Reply:

Similar Artilces:

RUNTIME class corrupted issue in VS2005
Hi, There was a bug in MFC 7.0 as posted in this group:- >Starting with MFC 7.0 Microsoft has introduced a severe bug for extension >DLLs: In the header file AFXDLLX.H that is needed for all extension DLLs >somebody replaced the external variable _pRawDllMain by a wrong one called >_pAtlChainRawDllMain (see line 44 of AFXDLLX.H). Below is the relevant part >of this header file in its original version, the faulty line is marked with >***>: Thanks for the report. This does appear to be a bug in MFC 7.0 and 7.1. We'll be looking to fix it in a future relase. Martyn Lov...

Object appears in in ADSI edit, but I cannot see properties
I've gone and shot myself in the foot by denying "everyone" access to my mailbox store. Poking around the group I've seen several ways to approach the problem, however I am having issues dealing with the Mailbox Store object in ADSI. I can see the object, but when I've tried to check the properties I get an error that states: "An invalid Directory pathname was passed" Additonally, I cannot rename or delete the object. So far I've rebooted 2 of 3 logon servers and restarted the IS service on the exchange box with no success. Any ideas? Most likely a perm...

can i reinstall the software without having to buy another key?
My computer crashed after getting hit with a nasty virus and i lost everything. Can i reinstall my microsoft office home and student 2007 without having to buy a new license? I already used all 3 licenses in the pkg. on my family computers. If you have the installation disk and its currently installed on 2 or less working PC's (The license is for 3 working installations) If as you say its allready running on 3 PC's then you would need to purchase the Office version you require (ie a complete pkge) "snackmonkey" <snackmonkey@discussions.microsoft.com> w...

Conditional formating based on another cell value
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) I've managed to use the solution described below, but I haven't been able to figure out how to use this for formating a cell based on a date entered into another cell. <br><br>Example: When 1/15/10 is entered into AG4, P4 is highlighted green. <br><br>Any help would be appreciated. <br> ----- <br> &quot;On 6/30/08 7:54 PM, in article 59b52d02.-1@webcrossing.caR9absDaxw, <br> &quot;Simon@officeformac.com&quot; wrote:http://www.officeformac.com/macimages/btn_publish.gif &l...

importing reports from another database
I am importing reports from one database to another. After importing, I have to change the report source to the correct query name and the field names to match the correct query--This seems to work fine except-- I have an expression in this report that will not change. When I go into the expression builder, the fields from the new query are not there. It contains the names of the fields from the report from which it was imported. Am I going about this the wrong way? Do I need to create this report from scratch? Or, is there something else I should be changing.-- Ronnie...

Passing data to worker threads
I'm trying to make an application that use CAsynchSocket class (derived to my class CMySocket); i've put a button "Connect" on my formview (CMyView) and when it is clicked, i show to the user a modal dialog form (CWaitDlg): this dialog starts a new worker thread that make the connection in background. The problem is that the CMySocket object is a member of the CMyView so the code i use is: void CMyView::OnBnClickedBconnect() { m_waitDlg.m_sConnectSocket = &m_sConnectSocket; m_waitDlg.m_wParentView = this; m_waitDlg.m_strName = &m_strName; error = m...

Divide number and add remainder in another cell
Can someone help me? I made a work distribution spreadsheet and I can not get it to divide evenly. What I am trying to do is divide the total number of claims by the number of employees and distribute the result to each employee. There are conditions also. For example one employee gets the max number of 50; Here is my formula; =IF(E18=0,0,IF(I19>250,50,(I19/(E8+E9+E10+E16)*E18))) column E =# of hours working for each employee, I19 = total number of claims. If the total number of claims is 1500 and there are 5 people working it returns 50 to the E18 employee and 363 to the rest, but t...

How to export non-virtual method from a class in an Extension DLL ?
I have exported a class in a MFC Extension DLL. The class contains a public non-virtual method. I have a MFC application which explicitly loads the DLL and then calls the non-virtual method. The problem is I get "an unresolved external symbol" when linking the application. I have found 2 ways to prevent the link error: a) change the non-virtual method to virtual b) make the application project dependant on the DLL project First I want to keep the non-virtual method non-virtual. Second when I make the app dependant on the DLL I always get an runtime error about how the DLL is not...

How to print a record in a form by pushing a button in another form ?
Hi ! I'm using MS Access 2003 and Windows XP Professional. I should like to save the extra effort of programming reports. A lot of effort has gone into designing the layout and arrangement of data in the form, and the form displays the data very nicely. So I should like to use it also for printing if I can, even if this method has some drawbacks. I've a form A with a print button on it. Pushing its print button prints the form as it is displaying the current record. Now I 'd like to do the same thing by pushing a print button on another form B. E.g., pushing the button tha...

How do I make values appear in another tab?
I am trying to set up an inspection database I need the values from other pages to appear when they go overdue in a specific cell. Please help!!! Could you give a specific example? If I understand, you'd want 1/1/2005 to show as overdue on sheet 2, but it now resides only on sheet 1? Seems to me you could copy the cell from sheet 1. Go to sheet 2 and Edit-->Paste special-->Paste link. Then, make the font color white. Then, using conditional formatting to show the font as black or red or something when the value is less than today. Type: =today() into a cell. Then, go to yo...

Copy and pasting from one spreadsheet to another
I exported 10 separate files using .csv format. However the vendor wants them all as one file. I attempted to copy and paste from one .csv file into another but I get an error indicating they are not the same size, etc and to click on an individual cell or rectangle. I did this but it still gives me the same error. The data is in the same format (I believe) as all 10 .csv's were created by the same program. How do I copy and paste from one .csv file to another without the error? Thanks. Anthony The simplest way is to import them into excel, copy/paste into new workbook, then...

How can I autocopy text from one textbox to another using VBA in E
As above I have bought 3 books in the hope of finding this answer and aslo searched the www till it has now got me demented! ...

Can't Scroll Text in a Single-line CEdit
Hello all, I have a problem with single-line CEdit controls. I have one where I put text into it, using SetWindowText(). And then I select part of that text, using SetSel(). But I need the caret to end up at the beginning of the selection, not the end. The user needs to see the start of the selection. How do I put the caret at the beginning of the selection and scroll the text back so you can see the caret? I tried something like this (which doesn't work): int iSelStart = GetIndexOfSelectionStart( pMyCEdit ); int iSelEnd = GetIndexOfLastChar( pMyCEdit ); pMyCEdit->SendMessage(EM...

Item Class Filter on Stock Status report
Currently the Historical Stock Status report has a filter for Item Class. The Stock Status report does not have this filter. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid...

Highlight a Cell When Working in Another Cell
If I am working in, say, cell B5, is there a way I can have cell G5 highlighted? When I am inputting numbers into column B, there are instructions in column G that I would like to have highlighted so that the instructions for that particular row are easier to read. I can't think of a good way to do this. I'd appreciate any ideas. Thanks! Private Sub Worksheet_SelectionChange(ByVal Target As Range) Cells.FormatConditions.Delete With Target If .Column = 2 Then .Offset(0, 5).FormatConditions.Add Type:=xlExpression, Formula1:="TRUE" Wi...

Formula for duplicating info from one cell to another
I'd like information that I input into a cell to be automatically output into another cell. So, for example, In one cell I input the following information: HWC65917 P Science / Health & Medical Sciences / Human Anatomy & Physiology / Human Systems / Immune/Lymphatic System / Diseases & Disorders / Other Lymphatic Disorders In the cell next to it I'd like it to automatically output Science / Health & Medical Sciences / Human Anatomy & Physiology / Human Systems / Immune/Lymphatic System / Diseases & Disorders / Other Lymphatic Disorders by excluding the HWC65...

What message is posted when moving mouse over CEdit?
What message is posted when moving mouse over CEdit? I would like to implament a tooltio which is displayed when the mouse is moved over a control derived of CEdit. Therefore I would like to ask you if someone know what message I have to capture in order to call my finction displayinn the tooltip? Can someone help? And perhaps someone knows what should be done to enable tooltips for controls derived of CEdit? I have a dialog and implement the following method: BOOL COptionPricingFooterForm::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult) everything works fine as long as my memebe...

xsd.exe Object reference not set to an instance of an object.
I am trying to generate a class from an xsd and i get this error. Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 1.1.4322.573] Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. Error: Error generating classes for schema 'adf_message'. - Object reference not set to an instance of an object. If you would like more help, please type "xsd /?". The XSD files all validate in VS.Net and in XMLspy. I can't find any documentation to help track down what this means or how to correct this. Could someone point me i...

transparent object does not print out transparent
I have created a circle (with the circle tool) that has varient shading. It's orange in the center and fades out to transparent. I have a second object sitting behind my circle. While I am working on the document, the object appears as I have designed it, but whent I go to print, the object becomes solid and the transparent part becomes white, hiding the second object behind. Can anyone help me figure out how to print it out as a transparent object? Thanks! This is a known bug in Publisher 2002/2003 along with the rest of Office XP/Office 2003. Group the objects together, then ...

offline defrag db on another machine
I need to do an offline defrag of my exchange 2k3 enterprise db. I don't have enough space on the server so I need to copy the db to another server and do the defrag there. Now if the server I copied the db to is called "abc" would the command below work? - where O is the drive mapped to where the files was copied? Also once copied to I delete the existing db and then just copy the defraged version back to the location or do I leave it and just say yes when I copy it back and it asks me if I want to override the file? C:\program files\exchsrvr\bin> eseutil /d O...

Dan Holmes wrote:,> I have to call the following COM interface. Can i just pass a c# arrary ,> of longs and doubles? What about the out parameters? They need to be ,> preallocated.,> ,> ,> [id(11),
I have to call the following COM interface. Can i just pass a c# array of longs and doubles? What about the out parameters? They need to be preallocated. Can i build them of the appropriate size and send them as ref? [id(11), helpstring("Calculate travel time and distance between locations assuming given start or end time ")] HRESULT CalculateTravelCosts( [in] SAFEARRAY(long) *lOriginLocationIds, [in] SAFEARRAY(long) *lOriginEdgeIds, [in] SAFEARRAY(long) *lOriginEdgePercents, [in] SAFEARRAY(double) *dOriginLongit...

is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? #2
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? ...

software problem on another user account
On Karen's account, when Outlook is opened and the message is closed, it's automatically deleted. Why? Minion1@dejazzd.com <Minion1@dejazzd.com> wrote: > On Karen's account, when Outlook is opened and the message > is closed, it's automatically deleted. Why? Are you shure it's deleted? Does it appear in the Deleted Items folder? What View value does Karen have set? WHat version of Outlook does she use? -- Brian Tillman ...

Another '03 vs '07 Add-in Menu Question
Hi, I have successfully written menu code that runs each time an .xla opens along with Excel. It works fine on my machines in both XL 2003 and XL 2007 (as expected under the Add-in menu). However, on other people's machines, and much to my chagrin, the menu does not appear in XL 2007. I know they have properly installed the add-ins, because I can see them selected under the Add-in's menu, and the macros can be called by their defined key-combinations. Nevertheless, no custom menus under Add-ins. Frustration city. Any thoughts on what may be interfering on these other inst...

find first empty cell in range and then copy from another workbook
I am looking for a formula function or a vba code where: - In workbook1 find the first cell that is empty between range A7 - A10, - In workbook2, in Range G10- G13: find the word "Day1". - If the word "Day1" exists in cells G10 or G11 or G12 or G13, copy the particular cell or cells where "Day1" exists to the first found empty cell or cells in range A7-A10 in workbook1. Lets suppose cells A8, A9, A10(workbook1) are empty cells, that means A8 is the first empty cell. And G10,G11,G12, G13 (workbook2) have the word "Day1" Then, Copy cell G10 into ce...