Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Doc/View main window

Posted on 1999-07-07
7
Medium Priority
?
199 Views
Last Modified: 2013-11-20
I am writing a Document/View application. In the Document module, I am trying to send a message to the main window. I am using
   AfxGetMainWnd()->SendMessage(WM_USER, NULL, NULL)
to send the message. But when I use this function, my application crashes. I am wondering what I am doing wrong. Also, I am wondering if there is another way to pass a message to the application, or main window, other than this method.

Thanks.
0
Comment
Question by:Zainal062797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Expert Comment

by:f4817
ID: 1309200
hi,

Would you like to send a message or call a function in your main window?
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1309201
Make sure that the main window pointer you get after call to AfxGetMainWnd is a valid one. Frame window gets created after document.

CWnd *pWnd = AfxGetMainWnd ();
if (NULL != pWnd) {
CFrameWnd *pFrameWnd = static_cast<CFrameWnd *>(pWnd);
pFrameWnd->SendMessage (WM_USER, NULL, NULL);
}

What kind of message u r trying to send to aplication?
0
 

Author Comment

by:Zainal062797
ID: 1309202
I want to do both, send a message and use a function. But I guess it is what naveenkohli   talked about. I am using the call in the document constructor, which menas that the main window is not yet created, and thus I am getting an invalid pointer.
Thank you.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 3

Expert Comment

by:Shay050799
ID: 1309203
do this:
u must create new message WM_USER is a constant declaring user messages  you have to use WM_USER+1000 for your message
using registermessage and than u can send the message like this:
CMyFrame* pFrame=(CMyFrame*)AfxGetMainWnd();
pFrame->SendMessage(WM_MY_MESSAGE,NULL,NULL);

BUT WHAT THE IDEA OF DOING THAT ???
0
 

Author Comment

by:Zainal062797
ID: 1309204
Okay let me give you the big picture. I have functions in the main window which Enable/Disable menu items. I want to invoke these function from within the Document module. The only way of doing it is to send a message to the main window.
Now, back to you Shay, Do I have to register a message or I can simply send a WM_USER + n  and in my message map declare
      ON_MESSAGE ((WM_USER+n), OnEnableMenuItem)
for example?

Thank you.
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 1309205
no !
the way to do it is this:
CMyFrame* pFrame=(CMyFrame*)AfxGetMainWnd();
pFrame->MyFunction()
0
 

Accepted Solution

by:
Phaedan earned 150 total points
ID: 1309206
If you are using the DOc/View model you should write ON_COMMAND_UPDATE handlers for the menu items. In class wizard, if your menu item is IDM_MYMENU

Select Message Maps in the classwizard.  In the list of classes, select the class to handle the event, in this sample CMyDoc. In the the list of resources find IDM_MYMENU.  On the right hand side you will have two options ON_COMMAND, ON_COMMAND_UPDATE.  The ON_COMMAND handler responds when the menu item is clicked.  The ON_COMMAND_UPDATE handler will allow you to set the state of the menu item based on data stored in the document.

For example: if CMyDoc had a boolean member variable m_myMenuChecked, then you could control the menu item with the following

void CMyDoc::OnMyMenuUpdate(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(m_myMenuChecked);
}

CCmdUI also has functions for Enabling/Disabling the menu option.

0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question