From: Tom Serface on
I typically send messages to my mainframe since it *is* a window. You can
call functions in the main app code by using AfxGetApp().

Tom

"FHDB" <FHDB(a)discussions.microsoft.com> wrote in message
news:9E8C74B2-01BE-4658-9C06-609A9608C50C(a)microsoft.com...
>I have placed thread control logic for worker threads in theApp, declared
>as
> CdualApp : public CWinApp. But my additions to the message map result in
> the
> error: error C2440: 'static_cast' : cannot convert from 'LRESULT (__cdecl
> *)(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
> if declared globally, or similarly if made part of class CdualApp.
>
> The problem appears to be that the message map wants message handlers that
> are part of a CWnd derived class. Is there a workaround for this, or do I
> need to move all the thread control logic into such a class?

From: Scott McPhillips [MVP] on
"Ajay Kalra" <ajaykalra(a)yahoo.com> wrote in message
news:2b629084-1edb-4151-844d-014b14b7ec40(a)p36g2000vbn.googlegroups.com...
On Nov 4, 8:35 am, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> Note, however, that if the CWinApp is the CWinApp for a GUI-based app
>> that has windows,
>> you cannot PostThreadMessage to it!
>>
>
>Thats very odd. We did it for a GUI without any issue and it has been
>in the product for a very long time.


It will fail to process the message if the app is displaying a messge box. I
think it will also fail if the app is displaying a menu. I.e. a modal loop
within Windows does not forward the message, as documented in
PostThreadMessage.

--
Scott McPhillips [VC++ MVP]

From: Joseph M. Newcomer on
(a) Read the description of PostThreadMessage which explains that it does not work
(b) PostThreadMessage messages will be lost if, at the point of receipt
The GUI thread has a MessageBox up
The GUI thread has a menu up
A window in the main thread is being dragged
A window in the main thread is being resized
...(and probably other situations)

So if it worked "without any issue" it means that you have simply been lucky. The reality
is that it does not work correctly under common scenarios of the main GUI thread.
joe

On Wed, 4 Nov 2009 06:38:12 -0800 (PST), Ajay Kalra <ajaykalra(a)yahoo.com> wrote:

>On Nov 4, 8:35�am, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> Note, however, that if the CWinApp is the CWinApp for a GUI-based app that has windows,
>> you cannot PostThreadMessage to it! �
>>
>
>Thats very odd. We did it for a GUI without any issue and it has been
>in the product for a very long time.
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
I find that the main window is convenient but only under certain restricted scenarios. I
have also discovered that many people post messages to the main window in inappropriate
situations and end up spending a lot of effort figuring out what to do next, and often
this involves having the main window call methods of a document or view, which is really
bad structure. So it is necessary to be careful about how the messaging is structured.
joe

On Wed, 4 Nov 2009 07:56:21 -0800, "Tom Serface" <tom(a)camaswood.com> wrote:

>I typically send messages to my mainframe since it *is* a window. You can
>call functions in the main app code by using AfxGetApp().
>
>Tom
>
>"FHDB" <FHDB(a)discussions.microsoft.com> wrote in message
>news:9E8C74B2-01BE-4658-9C06-609A9608C50C(a)microsoft.com...
>>I have placed thread control logic for worker threads in theApp, declared
>>as
>> CdualApp : public CWinApp. But my additions to the message map result in
>> the
>> error: error C2440: 'static_cast' : cannot convert from 'LRESULT (__cdecl
>> *)(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
>> if declared globally, or similarly if made part of class CdualApp.
>>
>> The problem appears to be that the message map wants message handlers that
>> are part of a CWnd derived class. Is there a workaround for this, or do I
>> need to move all the thread control logic into such a class?
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Ajay Kalra on
On Nov 4, 11:47 am, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
> (a) Read the description of PostThreadMessage which explains that it does not work
> (b) PostThreadMessage messages will be lost if, at the point of receipt
>         The GUI thread has a MessageBox up
>         The GUI thread has a menu up
>         A window in the main thread  is being dragged
>         A window in the main thread is being resized
>         ...(and probably other situations)
>
> So if it worked "without any issue" it means that you have simply been lucky.  The reality
> is that it does not work correctly under common scenarios of the main GUI thread.

Thanks. That explains why. It just happens to be used before the
window is shown.

To elaborate, I didnt implement this; I just found that it was used
this way and was curious(It was also memorable as I still remember it
10 years later). Its also the only use that I have seen this being
used in CWinApp.

--
Ajay