Simple Thread

I have created a thread in my MFC Dialog based application, in the thread
function i want to have access to a user interface control that is attached
to the main dialog.
How can I do it?

Regards,
Mystique


0
misic (56)
12/17/2005 4:58:29 PM
vc.mfc 33608 articles. 0 followers. Follow

12 Replies
1030 Views

Similar Articles

[PageSpeed] 49

Mystique wrote:
> I have created a thread in my MFC Dialog based application, in the thread
> function i want to have access to a user interface control that is attached
> to the main dialog.
> How can I do it?
> 
> Regards,
> Mystique
> 
> 

Indirectly, by posting a message to the main thread asking it to update 
the control. http://www.mvps.org/vcfaq/mfc/12.htm

-- 
Scott McPhillips [VC++ MVP]

0
Scott
12/17/2005 5:39:54 PM
You can't.  Instead, you have to use PostMessage to post a user-defined message to the
main GUI thread to request whatever update you are doing.  Take a look at my essay on
worker threads on my MVP Tips site.
					joe

On Sat, 17 Dec 2005 17:58:29 +0100, "Mystique" <misic@softhome.net> wrote:

>I have created a thread in my MFC Dialog based application, in the thread
>function i want to have access to a user interface control that is attached
>to the main dialog.
>How can I do it?
>
>Regards,
>Mystique
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
12/18/2005 3:29:25 AM
Thanks Scott
I'm to get this to compile cause i'm getting an error when:

::PostMessage(Param, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);

the error is: 'PostMessageA' : cannot convert parameter 1 from 'void *' to
'struct HWND__ *'

can i cast this somehow?

Best Regards,
Mystique

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:ehoZyDzAGHA.3340@tk2msftngp13.phx.gbl...
> Mystique wrote:
> > I have created a thread in my MFC Dialog based application, in the
thread
> > function i want to have access to a user interface control that is
attached
> > to the main dialog.
> > How can I do it?
> >
> > Regards,
> > Mystique
> >
> >
>
> Indirectly, by posting a message to the main thread asking it to update
> the control. http://www.mvps.org/vcfaq/mfc/12.htm
>
> --
> Scott McPhillips [VC++ MVP]
>


0
misic (56)
12/19/2005 9:20:10 AM
Mystique wrote:
> Thanks Scott
> I'm to get this to compile cause i'm getting an error when:
> 
> ::PostMessage(Param, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
> 
> the error is: 'PostMessageA' : cannot convert parameter 1 from 'void *' to
> 'struct HWND__ *'
> 
> can i cast this somehow?
> 
> Best Regards,
> Mystique

Yes.  If Param contains the HWND then use (HWND)Param

-- 
Scott McPhillips [VC++ MVP]

0
Scott
12/19/2005 12:33:38 PM
Ye it's ok now with the cast, but the Message funtion does not get called.

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:OQNE$hJBGHA.2664@TK2MSFTNGP15.phx.gbl...
> Mystique wrote:
> > Thanks Scott
> > I'm to get this to compile cause i'm getting an error when:
> >
> > ::PostMessage(Param, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
> >
> > the error is: 'PostMessageA' : cannot convert parameter 1 from 'void *'
to
> > 'struct HWND__ *'
> >
> > can i cast this somehow?
> >
> > Best Regards,
> > Mystique
>
> Yes.  If Param contains the HWND then use (HWND)Param
>
> --
> Scott McPhillips [VC++ MVP]
>


0
misic (56)
12/19/2005 1:59:06 PM
Mystique wrote:

> Ye it's ok now with the cast, but the Message funtion does not get called.
> 
[snip]

So how are you setting up the message handler? Look up ON_MESSAGE in the 
help.

David Wilkinson
0
no-reply8010 (1791)
12/19/2005 2:55:00 PM
the way it's defined here:
http://www.mvps.org/vcfaq/mfc/12.htm

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:#02MqwKBGHA.2568@TK2MSFTNGP10.phx.gbl...
> Mystique wrote:
>
> > Ye it's ok now with the cast, but the Message funtion does not get
called.
> >
> [snip]
>
> So how are you setting up the message handler? Look up ON_MESSAGE in the
> help.
>
> David Wilkinson


0
misic (56)
12/19/2005 5:06:45 PM
Mystique wrote:

> the way it's defined here:
> http://www.mvps.org/vcfaq/mfc/12.htm
> 

Then either you did something wrong, or the HWND is not that of the CWnd 
where you have defined your message map entry (in which case you also 
did something wrong). Bottom line, you did something wrong.

What I do in a worker thread is pass the "this" pointer of the 
originating CWnd as the LPVOID, and do:

CWnd* pWnd=static_cast<CWnd*>(pParam);
::PostMessage(pWnd->m_hWnd, ....);

This is partly because I am more comfortable casting an LPVOID to a 
pointer than to a handle (though I'm sure this is OK also).

Actually, it is also possible to do

pWnd->PostMessage(....);

because the MFC wrapping of ::PostMessage() does not use the handle map,
just the m_hWnd member.

David Wilkinson
0
no-reply8010 (1791)
12/19/2005 10:25:24 PM
thanks David
it worked by passing the this pointer :-)

Best Regards,
Mystique

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:#UWTVsOBGHA.628@TK2MSFTNGP14.phx.gbl...
> Mystique wrote:
>
> > the way it's defined here:
> > http://www.mvps.org/vcfaq/mfc/12.htm
> >
>
> Then either you did something wrong, or the HWND is not that of the CWnd
> where you have defined your message map entry (in which case you also
> did something wrong). Bottom line, you did something wrong.
>
> What I do in a worker thread is pass the "this" pointer of the
> originating CWnd as the LPVOID, and do:
>
> CWnd* pWnd=static_cast<CWnd*>(pParam);
> ::PostMessage(pWnd->m_hWnd, ....);
>
> This is partly because I am more comfortable casting an LPVOID to a
> pointer than to a handle (though I'm sure this is OK also).
>
> Actually, it is also possible to do
>
> pWnd->PostMessage(....);
>
> because the MFC wrapping of ::PostMessage() does not use the handle map,
> just the m_hWnd member.
>
> David Wilkinson


0
misic (56)
12/20/2005 8:26:33 AM
But is there anything special i should know about threads, cause now it
seems like it's going into recursion and the application is eating memory by
the second.

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:#UWTVsOBGHA.628@TK2MSFTNGP14.phx.gbl...
> Mystique wrote:
>
> > the way it's defined here:
> > http://www.mvps.org/vcfaq/mfc/12.htm
> >
>
> Then either you did something wrong, or the HWND is not that of the CWnd
> where you have defined your message map entry (in which case you also
> did something wrong). Bottom line, you did something wrong.
>
> What I do in a worker thread is pass the "this" pointer of the
> originating CWnd as the LPVOID, and do:
>
> CWnd* pWnd=static_cast<CWnd*>(pParam);
> ::PostMessage(pWnd->m_hWnd, ....);
>
> This is partly because I am more comfortable casting an LPVOID to a
> pointer than to a handle (though I'm sure this is OK also).
>
> Actually, it is also possible to do
>
> pWnd->PostMessage(....);
>
> because the MFC wrapping of ::PostMessage() does not use the handle map,
> just the m_hWnd member.
>
> David Wilkinson


0
misic (56)
12/20/2005 8:58:51 AM
Mystique wrote:

> But is there anything special i should know about threads, cause now it
> seems like it's going into recursion and the application is eating memory by
> the second.
> 
[snip]

There are many special things about multi-threaded applications, but 
they mostly have to do with communication between the threads, stopping 
a thread from another thread, and stuff like that

There is no particular reason why a multi-threaded application should 
leak memory; as in any other program you need to make sure that every 
"new" has a "delete".

David Wilkinson
0
no-reply8010 (1791)
12/20/2005 11:15:02 AM
Ye I traced the problem with the AxWebBrowser component, when it prints
something is happening, but i can't debug cause then the situation is even
worse.

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:#CK$YaVBGHA.2644@TK2MSFTNGP09.phx.gbl...
> Mystique wrote:
>
> > But is there anything special i should know about threads, cause now it
> > seems like it's going into recursion and the application is eating
memory by
> > the second.
> >
> [snip]
>
> There are many special things about multi-threaded applications, but
> they mostly have to do with communication between the threads, stopping
> a thread from another thread, and stuff like that
>
> There is no particular reason why a multi-threaded application should
> leak memory; as in any other program you need to make sure that every
> "new" has a "delete".
>
> David Wilkinson


0
misic (56)
12/20/2005 11:42:00 AM
Reply:

Similar Artilces:

Simple graph
I have a chart with zip codes and a population rate. ZIP RATE 80001 2.34 80002 1.23 80003 1.23 I want to make a chart that has the rate on the x axis and the number of times that rate occurs on the y axis. | | | * | | * |_________________________________ | | 1.23 2.34 Thank you. I will assume the ZIP and RATE stuff is in A1:B200 (labels in row 1) Label in G1 to read RATE (but leave it empty for now), label in H2 to read COUNT Make a list of rates in G2:G20 (say) In H2 =COUNTIF($B$2:$B$200,G2) Copy down the row Select H1:G20 and make a...

Simple help with implementing Outlook-like GUI
Hi All. I am an experienced unix programmer who sometimes has to do something in the windows world, and always has newbie-questions. Basically I want to write an application program that looks like outlook in that it has nice icons down the left hand side that choose the content of the main area in the right hand side. So I started the MFC App wizard, and got me a SDI program with a CLeftFrame (CTreeView) and a CMainFrame (CFrameWnd). Then I prepared the following snippet of code to draw the buttons: // Create a pushbutton CBitmapButton* pmyButton; pmyButton = new CB...

Simple Simple Simple
Just started Excel (again) and need to make an easy speadsheet fo calculating square inches. Column A: Height Column B: Legnth Column C: Total Tags per 16 x 24 Column D: Cost per tag Figures I know: each sheet cost me $9.98. each sheet is 16 x 24 inches What I want to do is enter the Height, enter the Length and have th total (sum) be entered into columns C and D. I can't believe I forgot how to enter formulas. Any help will b appreciated. Thank you, Crai -- Message posted from http://www.ExcelForum.com Hi Craig, One Way, might be better ways but this'll work: List the colou...

Simple hack to get $500 to your home. 06-05-10
Simple hack to get $500 to your home at http://uknews.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. ...

Simple Query Wizard hangs
I am using Access 2003 When I initiate the "Simple Query Wizard", I am presented with the first screen - "What fields do you want in your query" When I click on the pulldown list to select a table, I get the following message: "The expression On Get Focus you entered as the event property setting produced the following error: the text you entered isn't an item in the list * the expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]. * There may have been an error evaluating the function, event, or macro&q...

I Need a Simple Sales Software
Hello, I am looking for software to keep track of my prospects, customers, and the notes of the sales process. I spend about one hour a day on sales and marketing, so I prefer a simple and inexpensive software. Maximizer, Outlook, Act, and Goldmine seem made for the full-time professional salesperson. Please let me know if what I am looking for exists. Best Regards, T.I. ...

Make it more simple or intuitive to do simple things
I appreciate the fact that applications are becoming more versatile and able to do things that we hardly thought possible in the past but I feel that in this added complexity you are losing sight of the need to do simple things easily without resorting to trial and error or consulting "help" which often anyhow doesn't lead one straight to the solution! An example is how to produce a chart with a series of months i.e Jan Feb Mar etc appearing on the X axis. This is no doubt something that resulted naturally in the first versions of Excel charts or in a competitor's ea...

MAD Monitoring thread starting sporadically
Hi, My server is delivering mail fine, but I am getting repeated instances of Event IDs 9095 and 9096 (see below). The explanation from MS says: Explanation This occurs when Exchange System Attendant service is started and whenever configuration changes are made that could affect the monitoring work of Exchange System Attendant. User Action No user action is required. If this event occurs frequently, contact Microsoft Product Support Services. My question is, how often is "frequently"? I am seeing this at least a couple times a day when I am not manually stopping and start...

Simple public folder permission problem
I have a public task list folder. However even though I have given everyone "Author" priviledges and full control of the directory, users cannot update the tasks (although they can create new ones). The changes to tasks get reset to their original values. Where should I look to fix this problem? Brian How did you grant Author Access, via Outlook or ESM? What do you meanyou gave them full control of the directory? "Brian Taylor" <taylorb@newsgroups.nospam> wrote in message news:e2hwumGrEHA.1160@tk2msftngp13.phx.gbl... > I have a public task list folder. Ho...

What is simple text?
When creating a custom list that includes a column of accounting formated data, I get an error message that 'fields without simple text will be ignored'. The result is all other data except the accounting formatted data. Help!!!! I suppose it means without the currency symbol and thousands delimiters. On Fri, 8 Apr 2005 11:01:04 -0700, TexMas <TexMas@discussions.microsoft.com> wrote: >When creating a custom list that includes a column of accounting formated >data, I get an error message that 'fields without simple text will be >ignored'. The result is ...

Synchronize the read/write operation between threads
In main thread, I capture video stream from webcam with VFW. When the video frame is captured by the driver, the OnCaptureStream is invoked. In this callback function, I copy the frame into a global frame buffer and return. The code is following: ================================================== LRESULT CALLBACK OnCaptureStream(HWND mwnd,LPVIDEOHDR lphdr) { CCaptureDlg *pCapDlg = (CCaptureDlg *)capGetUserData(mwnd); if(pCapDlg != NULL) { EnterCriticalSection(&g_CriticalSection); memcpy(g_FrameBuffer, lphdr->lpData, lphdr->dwBytesUsed); LeaveCriti...

simple question
Okay, I have a very simple question. Where do the old posts go after they run off the last page of this newsgroup? Sometimes I would like to refer to a post that I remember seeing in October, but is no longer on the current section. The search function seems to only search current posts as well. If anyone has some input please email me at joep@siboneylg.com Thanks kindly. have you tried google groups, they keep archived old posts: http://groups.google.co.uk/groups?q=microsoft.public.greatplains&hl=en "Joe Proehl" <joep@siboneylg.com> wrote in message news:099701c5...

Simple Macro is not so simple
Hi all, I am trying to record a macro which will automatically perform the insert > comment function to a selected cell. Should be easy right? Alas no Danny There's sample code on my web site, for inserting comments: http://www.contextures.com/xlcomments03.html Aardvark wrote: > Hi all, > > I am trying to record a macro which will automatically perform the insert > > comment function to a selected cell. Should be easy right? Alas no -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html Wow! Nice one :-) Thank you M...

(Error 1004) Object Defined Error ...simple code
I have the following simple simple code: Dim s as String s = WeekdayName(1) ' Causes Error 1004 Why would the above call to "WeekdayName(1)" suddenly cause an Object Defined Error?? My program has been working nicely for awhile, but now all of a sudden it halts at the above line??? What the heck is going on??? Robert Crandal Hi Robert, It works fine for me. However, checking out Help, the first day of week parameter is supposed to default to Sunday (or 1) as the first day of the week but it appears to default to zero. Tested in xl2002 and x...

vb--simple simple
hi, anyone know how to copy a combobox selection to a specific cell b using vb code in a command box -- Message posted from http://www.ExcelForum.com i cant see this in the userform. i know you can do this with a normal combo box which is not in a for but lost when in a userform -- Message posted from http://www.ExcelForum.com What's a "command box"? Can you give an clear example of what you want to do? -- Jim Rech Excel MVP "stevieh >" <<stevieh.16v8yw@excelforum-nospam.com> wrote in message news:stevieh.16v8yw@excelforum-nospam.com... | hi, | |...

Formula question -simple for those who know
Hello I'm trying to add a number that was calculated by means of a formula in one column to the sum of a different column. Example: Column A (running balance) Column B (sum) =+e5+c6-d6 =sum(h1:h8) Col A's number is running balance. I copied the formula down so that the next row changes the formula to =+e6=c7-d7 I want that running balance to add to a sum in another column. I can add the first cell to it, but it doesn't change if the running balance changes. I know that is because it's pointing to that single...

Pretty simple question
Hello I use Excel 97 in work. I have a frustrating problem. If I have two Excel workbooks open then, in order to switch between them, I have to go to the menu bar and select <Window> and then the appropriate workbook. I am used to Excel 2000 where I can just click the workboook 'icons / tabs' along the bottom of my screen. This is far better. How can I change Excel 97 to allow the open workbooks to display as icons/tabs along the bottom of the screen (as is standard these days). Please help lower my blood pressure... Regards Alex Alex, I don't think that was an ...

Simple Formula Question
hi, I have the following simple formula: =A61*E61 I need to know how I can highlight a block of cells - Let's say row 62-86 and have that formula update itself to reflect each row number (A column & E column remain throughout only the numbers of the row change) Hope that made sense. I know it's a simple proceedure I just can' remember how to do it. Your help would be greatly appreciated as I' really up against a deadline. Thanks!! : -- Message posted from http://www.ExcelForum.com just copy the formula for all rows. Excel will change the formula accordingly Frank ...

A simple question requiring a simple answer
When typing in a cell how do I get the text to drop down a line yet stay in the same cell? ie. In word you hit enter and the cursor drops to the next line. In excel you hit enter and the next cell is selected. -- Pedros ------------------------------------------------------------------------ Pedros's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28202 View this thread: http://www.excelforum.com/showthread.php?threadid=562306 Pedros, use Alt+enter to get a new line in the same cell -- Paul B Always backup your data before trying something new Please post...

Help with a 'simple' (prob!!) formular
I have date figures in A col and sales amounts in B - i want to identify trends. I want to formulate this; if a sales was between 1st and last day of month x and between �3001 and �4000 count 1 ie i want to be able to see how many sales between two figures and two dates there were i am really stuck on this one! - paulrobertmee@ukonline.co.uk ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ I sent you a file that should accomplish what you are trying to do. "me...

Simple Questions
Hello 1- How do I make my spreadsheet have its grids non-visible? 2- How do I make (at the same time) a certain cell write protected as well as if someone clicks on it then its border does not get focus (meaning: you know when you click on a cell, then its border lines weight get larger as to tell you that this is the cell that you have chosen, but I don't want this focus feature, I want it to look like as if it is a webpage, and you know when you glick on any work on a webpage it doesn't get any focus)? -- cgi_pro -----------------------------------------------------------------...

Simple Formula for simple person. :)
Hi, I'm typing up a basketball boxscore template and need the formula to work out shots made over shot attempts. I know this is a simple percentage but I'm not sure what form this would take in the function window. Any help would be appreciated. Thanks The Excel Noob. Okay, I learnt to read. *blush* ...

simple sheet ?
Hi Would it be possible to have a Simple Spread Sheet that would recognise the input of the SAME number if it were entered three times and then highlight that number in a different place and the number could be anything between 1 and 2000 -- Keith You could have a helper column in b. if all the numebrs are in col a. have an equation in b1:- =countif(a:a=a1) and in c1 if(b1=>3,("This number has appeared three times "&b1),"") copy this formula down. this the kinda thing ure after -- Message posted from http://www.ExcelForum.com Hi Keith I would say Con...

quick and simple question
I have a user that wants to send out an same exact e-mail every Thursday of the month to the same exact recipients, is there a way to create and store an e-mail that can automatically do this? using outlook 2000, or 2002, or 2003 You can use an add-in for this; http://www.sperrysoftware.com/Outlook/Schedule-Recurring-Email.asp?Source=RS If you decide to order use "BH93RF24" to get a discount. or; http://www.mapilab.com/outlook/email_scheduler/ If you decide to order use "4PM76A8" to get a discount. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the...

preventing a workbook being changed? (not as simple as it sounds!)
i am trying to prevent anyone being able to make changes to a workboo and something strange is happening. Ive put a password on the workbook by going to tools/options/securit and adding a "password to modify". now in theory this should prevent anyone ever being able to change m workbook without knowing that password. however ive had the workbook put onto the intranet, clicking the lin to it opens it in IE. if i make some changes in the workbook and the click the back button in IE, i get prompted to save the workbook due t changes. I can then click save and save the workbook to m...