(MFC) How to use messages to communicate between CMDIFrameWnd and CScrollView?

Alright, so I tried to use AfxGetMainWnd() from inside a
CScrollView-derived class to access a function inside of a
CMDIFrameWnd-derived class.  It worked under the "Debug" configuration,
but I'm getting a nasty error under the "Release" configuration:

Coil error LNK2019: unresolved external symbol "public: void __thiscall
CMainFrame::setCurrRef(class ATL::CStringT<char,class
StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >)"
(?setCurrRef@CMainFrame@@QAEXV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z)
referenced in function "protected: void __thiscall
CCoilView::OnEditRefrigerantselection(void)"
(?OnEditRefrigerantselection@CCoilView@@IAEXXZ)

So I've decided to do it using another method: by sending a message to
the application from within the CScrollView-derived class and handling
it from within the CMDIFrameWnd-derived class.  However, I've made my
own custom messages; I've just handled the ones the application
generates for selecting different menu options, etc.  So, how do I
make, send, receive, and act on custom messages?  Thanks.

0
cyde (46)
7/27/2005 8:01:45 PM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
967 Views

Similar Articles

[PageSpeed] 39

Cyde Weys wrote:
> So I've decided to do it using another method: by sending a message to
> the application from within the CScrollView-derived class and handling
> it from within the CMDIFrameWnd-derived class.  However, I've made my
> own custom messages; I've just handled the ones the application
> generates for selecting different menu options, etc.  So, how do I
> make, send, receive, and act on custom messages?  Thanks.
> 

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

-- 
Scott McPhillips [VC++ MVP]

0
Scott
7/28/2005 12:09:10 AM

Scott McPhillips [MVP] wrote:
> Cyde Weys wrote:
> > So I've decided to do it using another method: by sending a message to
> > the application from within the CScrollView-derived class and handling
> > it from within the CMDIFrameWnd-derived class.  However, I've made my
> > own custom messages; I've just handled the ones the application
> > generates for selecting different menu options, etc.  So, how do I
> > make, send, receive, and act on custom messages?  Thanks.
> >
>
> http://www.mvps.org/vcfaq/mfc/12.htm

Alright, I have a question.  First, from the article:

---------------
Your secondary thread will need an hwnd (not a CWnd*) to post to. You
can pass the main hwnd when you create the thread. Then you are ready
to send or post a message from the secondary thread:


    ::PostMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
  or,
    ::SendMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
---------------

How do I set up this whole hwnd business?  I'm working on a rather
large program (most of it not written by me) and it doesn't really have
any hwnd stuff going on.  And I don't see how exactly to pass "the main
hwnd" to the thread.  The only place I can see where a "thread" is
created is the following, and I don't see any way to pass parameters:

---------------
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_COILTYPE,
		RUNTIME_CLASS(CCoilDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CCoilView));
	AddDocTemplate(pDocTemplate);

0
cyde (46)
7/28/2005 1:33:45 PM
This error is a link time error. You should resolve it and see why
setCurrRef is not exported or not found.

You can always access mainframe window (CMDIFrameWnd for MDI) using
AfxGetMainWnd from your view. It does not appear you are dealing with
worker threads here. You can use pMainWnd->PostMessage(WM_YOURMESSAGE,
...). It does not explicitly require a handle but knows to use m_hWnd
that is part of the base class CWnd.

---------
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6842)
7/28/2005 7:35:52 PM

Ajay Kalra wrote:
> This error is a link time error. You should resolve it and see why
> setCurrRef is not exported or not found.

I'm trying to resolve it :-/

> You can always access mainframe window (CMDIFrameWnd for MDI) using
> AfxGetMainWnd from your view. It does not appear you are dealing with
> worker threads here. You can use pMainWnd->PostMessage(WM_YOURMESSAGE,
> ..). It does not explicitly require a handle but knows to use m_hWnd
> that is part of the base class CWnd.

The only place in my program where I see anything called pMainWnd
(actually m_pMainWnd) is here:

	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;
	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

But what is this variable?  It's not defined in my App.h file, yet it
is apparently a member variable?  I guess it's one of the variables
from the class my main App inherits from?  If I use m_pMainWnd inside
of my CScrollView-derived class will it function properly?

0
cyde (46)
7/28/2005 8:38:55 PM
Cyde Weys wrote:
>>http://www.mvps.org/vcfaq/mfc/12.htm
> 
> 
> Alright, I have a question.  First, from the article:
> 
> ---------------
> Your secondary thread will need an hwnd (not a CWnd*) to post to. You
> can pass the main hwnd when you create the thread. Then you are ready
> to send or post a message from the secondary thread:
> 
> 
>     ::PostMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
>   or,
>     ::SendMessage(hwnd, MY_WM_MESSAGE1, (WPARAM)0, (LPARAM)0);
> ---------------
> 
> How do I set up this whole hwnd business?  I'm working on a rather
> large program (most of it not written by me) and it doesn't really have
> any hwnd stuff going on.  And I don't see how exactly to pass "the main
> hwnd" to the thread.  The only place I can see where a "thread" is
> created is the following, and I don't see any way to pass parameters:
> 
> ---------------
> 	CMultiDocTemplate* pDocTemplate;
> 	pDocTemplate = new CMultiDocTemplate(
> 		IDR_COILTYPE,
> 		RUNTIME_CLASS(CCoilDoc),
> 		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
> 		RUNTIME_CLASS(CCoilView));
> 	AddDocTemplate(pDocTemplate);

The above code is not creating a thread.  Not relevant.  By the way, it 
takes years to understand what the above code does.  It is the "big 
bang" of an MFC application: It creates the entire universe.  Ignore it.

As far as I know, your problem does not involve multiple threads.  But 
the referenced article, although it is about interthread messaging, 
shows you how to define and handle a custom message posted to a window, 
no matter where or how the message was generated.  When everything is in 
one thread you can simply use

AfxGetMainWnd()->PostMessage(...)
or
AfxGetMainWnd()->SendMessage(...)

from anywhere in your application and you don't have to mess with HWNDs. 
  Note: AfxGetMainWnd() is a handy built-in function to get the 
m_pMainWnd you asked Ajay about.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
7/28/2005 11:53:29 PM
m_pMainWnd is member of CWinThread, your app's base class. You can use
AfxGetMainWnd to get to it.

---------
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6842)
7/29/2005 1:17:40 PM
ARGHHH!!!!!!  Permission to kill myself?  God dammit ...

So I got the message map thing working in Debug, but not in Release.
So I go back and look to see why in the hell it's not working, and I
look at the code in MainFrm.cpp more carefully and ... guess what block
I've inadvertently inserted both functions setCurrRef and
OnMyCurrRefMessage into?

#ifdef _DEBUG

#endif


AAAAARRRRRRGGGHHHHHHHHHHHHHHHHHH

0
cyde (46)
7/29/2005 1:38:18 PM
Cyde Weys wrote:
> ARGHHH!!!!!!  Permission to kill myself?  God dammit ...
>
> So I got the message map thing working in Debug, but not in Release.
> So I go back and look to see why in the hell it's not working, and I
> look at the code in MainFrm.cpp more carefully and ... guess what block
> I've inadvertently inserted both functions setCurrRef and
> OnMyCurrRefMessage into?
>
> #ifdef _DEBUG
>
> #endif

And by the way, thanks a lot for your help.  I didn't end up using the
messages because once I figured out the real error it runs a bit
smoother just calling ((CMainFrame*)AfxGetMainWnd())->setCurrRef([...])
than using messages, but I did get it to work with messages too, so
I've learned something!

0
cyde (46)
7/29/2005 2:02:23 PM
Reply:

Similar Artilces:

Unread messages in Public Folders
Hi all, I have two problems with public folders: - OWA nor Outlook doesn't display count of unread messages, regardless whether per-user read/unread information is checked or not - I'm unable to setup Outlook to show desktop alert on new messages in any public folder; the dummy rule with display desktop alert option doesn't work - is it even possible? Thanks in advance, Robert On Fri, 24 Feb 2006 16:21:05 +0100, "Robert Goldwein" <robert.goldwein@dtptools.com> wrote: >Hi all, > >I have two problems with public folders: >- OWA nor Outlook doesn&#...

Saving sent messages in secondary mailbox
I have multiple mailboxes, however when I send a message from a secondary mailbox it gets saved in my primary mailbox. Does anyone know a way to save sent messages from a secondary mailbox to the sent folder for that secondary mailbox. Thanks, Anne ...

Outlook security message regarding accessing email addresses
Win XP HE, SP 1, OL 2002 SP3 Follow-up to microsoft.public.outlook Hi, Trying to synch my cell phone with OL, I am getting a message from OL saying--a program is trying to access email addresses. Do you want to allow it? And it gives a time window (1 mn, 5 mn or 10 mn) to choose to allow. This could be interfering with my ability to synch. How do I get rid of this setting? Thanks. S Saturnin02, I am also experienceing the same message and have not found away to correct this. It started showing up about 3 or 4 weeks ago out of the clear blue. Mine only pops up though when I try to rea...

small message box at the right corner
I'd like to enable my MFC application to pop-up a small message box at the right corner of the pc for a few seconds- and then disappear (like a tool tip or the message that Norton Antivirus does). Is that possible and how? thanks Gil You mean like this: http://www.codeproject.com/dialog/statusbarmsgwnd.asp There are better one on CodeProject, but my IE keeps crashing on me. AliR. "Gil" <gil@john.com> wrote in message news:uWDyAaUzGHA.4176@TK2MSFTNGP06.phx.gbl... > I'd like to enable my MFC application to pop-up a small message box at the > right corne...

How to get the startup options within a standard MFC application
Hello, creating a standard mfc with the VC6++ wizzard. How can I get the startup option that were used to start the mfc-executable? Thanks for your help Regards "ZZT" <a@b.c> wrote in message news:cjj1ct$m9e$1@news2.wdf.sap.corp... > Hello, > > creating a standard mfc with the VC6++ wizzard. How can I get the > startup option that were used to start the mfc-executable? > > Thanks for your help > Regards BOOL YourApp::InitInstance() { ... // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; Pars...

deleting row using macro
Hi, I am trying to delete rows in specific columns that have certain words in them. I am a total newbie. The error is: "Runtime Error 1004: AutoFilter method of Range Class Failed" When I debug the line that it doesn't like is: " .Range("A1").AutoFilter Field:=8, Criteria1:="CAD" " Here's my macro.. Sub DeleteBlankRows() 'Assumes the list has a heading. With ActiveSheet If .AutoFilterMode = False Then .Cells(1, 1).AutoFilter .Range("A1").AutoFilter Field:=8, Criteria1:="CAD" ...

Junk Email: Blank Messages
I'm trying to come up with an Outlook 2003 rule for automatically deleting junk emails that come through with no subject, no mailto, and no body (other than an empty HTML page). Any suggestions? We use SpamBayes on our client machines which pick that up. Problem is there's a lot of stupid users out there that can't understand how to filter messages properly. ;-) Also, as a warning, we're using Symantec Mail Security on our Exchange server and had set up a rule to filter out all the messages with blank senders and subjects. Little did we know (and symantec says this ...

Re: Guide to using M2004 Small Business?
Reposting; any thoughts? "Cristof Falk" <cfml@critterdesign.net> wrote in message news:... > Can anyone direct me to a guide or resource or something on handling a small > business with M2004 Small Business? Until now, for many Money versions, I've > simply had a Wages: Self Employment with a report that showed this category, > and then I would handle taxes through TaxAct. But now my sole proprietor > single person consulting firm is getting more active, so I got the Small > Business Edition. But looking at the Business home page and the bCentral > lin...

How can filter messages that are replied by the receiver?
Hi all, In my department an order is send out by mail to a supplier. This mail is replied by the supplier (confirmation) before the order is actually shipped. Now the question is how can I filter out the messages that are replied (confirmed), and of course the messages that are not replied yet? This is done completely manually now ..... All the best, Bert In news:11fedvcggihfu03@corp.supernews.com, plurker <nomail@nomail.com> typed: > Hi all, > > In my department an order is send out by mail to a supplier. This > mail is replied by the supplier (confirmation) befor...

Write Hex to Output File in MFC
Hi All: I need to generate a file using MFC which is Unicoded. In other words, I need to have a file that has '16-bit hex coding' showing in the file when I open it thru notepad Problem: Even though I store the string in 16-bit format, when I write it into the file, it still displays it as ascii. I need to see '16-bit Hex' instead of the ascii. I am using the following code. The output in the file is "hello". Instead, I want to see "0x0048 0x0065 0x006C 0x006C 0x006F". I am using the following code. wchar_t rashid2[] =_T(L"Hello"); HAND...

recurring error message
Hello, I have this irritating error message come up every time Outlook 2003 checks for new emails. My Outlook is set to obtain email from two ISPs. The error message refers to the account that is not the Internet connection I use. I normally don't have a problem retrieving email from this account - just this nagging error message telling me that the account is trying to send a couple of emails. Is there some way I can fix this? "Task 'mail.bigpond.com - Sending' reported error (0x80042109) : 'Outlook is unable to connect to your outgoing (SMTP) e-mail server. If...

Search does not find messages in Outlook 2007
Hello All, I have Outlook 2007 and Windows Desktop search trunning on a Windows XP Professional machine. The indexing has been completed but I noted that the search will not find certain emails, which contain the text that I am searching for in the content. I can find the message by author, subject, etc. but not based on the keyord. This makes me dowbt of the reliability of the search. Any ideas of what might be going on? Kind regards CD ...

Using Forms to Update Worksheet Data
Thanks in advance for the feedback and sorry to those who read it in general questions. I have VBA form that I've created to display data to the screen using the following code (code only shows of few of the columns of data being loaded to form). Public Sub LoadLongInfo3(ByVal selectedProject As String) Dim databaseRow As Long Set reportsSheet = Sheets("Reports") Set resultsSheet = Sheets("Results") Set devdataSheet = Sheets("DevData") 'Find DataRows To Be Loaded Into Form devdataSheet.Activate devdataSheet.Cells.Find(What:=select...

how to use "<10" as text value instead of numeric in COUNT.IF()
Hi, With the function =COUNT.IF(a1:a10;"<10"), i'll get the number of cells with value less than 10. But suppose there are cells which contain the text value "<10" (as a code e.g.). How can i use COUNT.IF() function to count the number of those cells? Thanks Ben How about a different function? In the USA version: =SUMPRODUCT(--(A1:A10="<10")) Ben wrote: > > Hi, > > With the function =COUNT.IF(a1:a10;"<10"), i'll get the number of cells > with value less than 10. > But suppose there are cells which con...

using outlook with juno
I am totally new to outlook. I tried setting up outlook with juno using the wizard and the test page does not go through. What should my Incoming Server(pop3) and my outgoing Server (SMTP) numbers be? Or how do I find them. Thanks You cannot use Outlook since Juno is web mail, not POP mail. Use your browser instead. "Sharon" wrote: > I am totally new to outlook. I tried setting up outlook with juno using the > wizard > and the test page does not go through. What should my Incoming Server(pop3) > and my outgoing Server (SMTP) numbers be? Or how do I find th...

Excel extremely slow opening and using
When using spreadsheets, everything is extremely slow, such as moving from one cell to the next, saving, etc. This is on the hard drive. I also have saved spreadsheets on a ZIP disk and those seem to be trying to open but won't, possibly because it takes so long. The one on disk that I can open, if I try to do anything, such as move a worksheet or copy a worksheet, the computer freezes up and won't do anything. I have to shut it down and start over. I had memory added and that didn't change a thing. I also did the disk fragment and that stuff and that didn't do anything ...

message between objects.
I have designed a class CA and there is a message queue in the class. i.e. Class CA { .... queue q; } Then, i defined two variables: CA a1; CA a2; I am execpting that a1 can send a message into a2's queue. What should I do in the Class CA design?Thank you very much for yoru suggestions -- Best Regards Yan ZHANG http://www.nict.com.sg/zhang/ "Yan ZHANG" wrote: > I have designed a class CA and there is a message queue in the class. i.e. > > Class CA > { > .... > queue q; > > } > > Then, i defined two variables: > > CA ...

What type of trigger should I use
This is a multi-part message in MIME format. ------=_NextPart_000_02DA_01C4B6F5.6DE73C10 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi- What trigger should I use to make sure the custom field in GP alternate = window is saved to my table when people click to move to next record? I did handle the case when user exit the window or click on save button, = but I don't know how to handle the case where user select to move to = next record.=20 Please advice- Thanks- --=20 Roxy ------=_NextPart_000_02DA_01C4B6F5.6DE73C10 Content-Type: t...

Unknown recipient reply message
Where can I find it and change it ? I mean while receive a unknown.user@mydomain.com where to configure the auto reply message ? thx "DT" <daniel.tai@sonopress.com.hk> wrote: >Where can I find it and change it ? > >I mean while receive a unknown.user@mydomain.com > >where to configure the auto reply message ? > >thx > No dice without spending lots of money and engaging Microsoft Consulting. Soon, you will be able to wait for a 3rd party provider to sell a solution: http://blogs.msdn.com/exchange/archive/2004/04/20/117024.aspx Mark Arnold MCSA M...

Tip: How to display picklist values using radio buttons instead of dropdown
I discovered this by chance. I hope it helps someone. I was changing a set of Yes/No radio buttons (bit type) into Yes/No/ Unknown dropdown (picklist only allows dropdown display). I had to remove the fields from the form, publish it, THEN delete the attributes and finally create them again with the new data type, add them to the form, and publish again. Basically, normal. The trick I stumbled into is: When you delete the attributes, DO NOT SAVE YET. Create the new attribute with the same name with the new data type of picklist while the window is still open. Then add to form and publish as ...

Backup job using UNC path
In SQL2008, I can manually backup from the server to different machine using UNC path but if I run it using Backup Maintenance Plan - I don't have any success. What am I missing? Thanks, Cecile On Jul 21, 10:26=A0pm, Cecile <Cec...@discussions.microsoft.com> wrote: > In SQL2008, I can manually backup from the server to different machine us= ing > UNC path but if I run it using Backup Maintenance Plan - I don't have any > success. > > What am I missing? > > Thanks, > Cecile What exact error are you getting ? The backup command ...

hyperlink to message within Outlook?
Is it possible to create a hyperlink in a Microsoft Word document to an email in Outlook without moving the message outside of Outlook? ...

View Hotmail Messages in Outlook 2000
Hi, I've created a new folder and titled it "Hotmail" with it's home page pointing to: http://www.hotmail.com , and it's set to display the home page by default. I can see the page in the folder's window in Outlook, but I can't open any messages as I can only see the sender's details and not the subject (which contains the hyperlink to open the message). I can even access the check boxes, move around the various folders, delete etc but not view the emails- Grrr! I am currently using the "Basic" version of hotmail i.e. "You're using the bas...

Send delayed e-mail message at specific time
Hello I am using Outlook 2000 and there is a place in the options of the e-mail. (After message is saved, right clicl --options) , where you can set a date and time to send the specific e-mail. I have set the parameters and tested it but it doesen't go. What else do I need to do to trigger it to go at a specific time? Thanks Phil Is Outlook open at that particular date/time you've set it for? Do a test for an email later today, at a later time, leave Outlook running and it should still go. I use to use that feature... >-----Original Message----- >Hello > >I am ...

Using COleCurrency with ODBC and Visual C++
Hi, I am writing a database application (using access). I have data fields in the database that are defined as currency. I have defined edit boxes within my applications as COleCurrency. I am having problems for using RFX_... I found not a RFX_Currency(...) for the DoFieldExchange-Function. Can you help me please! Regards, Michael ...