• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

CMainFrame MDI ? Size and Title don't seem to work here

I am new to this doc/view architecture and have only really used dialogs with MFC. Also I have just swithed over to .NET.
I have an MDI app and I can't seem to get the OnSize funtion to work, nor can I update the windowText.

I would normally catch the message for the OnSize/WM_SIZE, then lets just say...use this to set the MainFrame window title.
I tried this: (what am I doing wrong?)

void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
      CMDIFrameWnd::OnSize(nType, cx, cy);
      
      CString newTitle;
      newTitle.Format("( %d, %d )", cx, cy);
      SetWindowText(newTitle);
      
}

Just to clarify:
I want to get the onSize from the mainFrame, and set its title.(NOT THE CHILD WINDOWS)
0
cafechris
Asked:
cafechris
  • 6
  • 5
1 Solution
 
mahesh1402Commented:
Check if you are calling DefWndProc rather than DefMDIChildProc in the child window's wndproc. You suppose to call DefMDIChildProc in the child window's wndproc.

MAHESH
0
 
cafechrisAuthor Commented:
I actually don't have any Idea as to how to check that?

here is what I did and it worked:
///////////////////////////////////////////////////////////////////  PREVIOUSLY
.h
...public:
      afx_msg void OnSize(UINT nType, int cx, int cy);
      afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
----------------------------------------------------------------------------------
.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
      ON_WM_CREATE()
END_MESSAGE_MAP()

///////////////////////////////////////////////////////////////////  CHANGED TO
.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
      ON_WM_CREATE()
      ON_WM_SIZE() // added this ?
END_MESSAGE_MAP()

Can someone please explain this to me so I know it for the future... thanks
0
 
cafechrisAuthor Commented:
Is there a function that will update all docking windows while I am moving. Like UpdateWindow() or something.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mahesh1402Commented:
That means you have not added message ON_WM_SIZE for your handler function OnSize(). I suggest you to use ClassWizard to do this. Press Ctrl+W to invoke class wizard. Make sure you have selected appropriate class from list. In Message list box double click on WM_SIZE and click on Edit Code button to add code to handler function. Class wizard automatically adds ON_WM_SIZE() message entry in message map. So you need not to do this manually.

MAHESH
0
 
cafechrisAuthor Commented:
Found RecalcLayout(t/f) thanks.
0
 
mahesh1402Commented:
>>Is there a function that will update all docking windows while I am moving. Like UpdateWindow() or something.

Have a look at function CDocument::UpdateAllViews().

MAHESH
0
 
cafechrisAuthor Commented:
mahesh,
I am using .NET. I don't believe that it has Class Wizard. That is what is making this a little uncomfortable for me. I assumed that if I select the class and tell it to create a new messageFunction that it would set it up correctly. I guess not. I really like VC++ 6 (what I am used to) , but this .NET seems really nice to work in (as I get the hang of it). Are you taling about ChildWindows, or MainFrame? I need to update all my docking windows. I will look at UpdateAllViews, but it sounds like it is for the child window views.

what is happening if I only have the afx_msg and no WM_SIZE MessageMap? I still don't totally understand
0
 
mahesh1402Commented:
>>what is happening if I only have the afx_msg and no WM_SIZE MessageMap? I still don't totally understand

BEGIN_MESSAGE_MAP.... END_MESSAGE_MAP macros are to put messages you need to handle in your message map. Any message in this case WM_SIZE you need to handle you suppose to add message map entry in between this macros. Here you want to add handler for WM_SIZE so you suppose to add ON_WM_SIZE() in MFC. So that OnSize() member function is called by the framework to allow your application to handle a WM_SIZE Windows message.

Its just like similar to handling case WM_SIZE in your WindowProc of your window.

MAHESH
0
 
mahesh1402Commented:
if you dont hput ON_WM_SIZE() in your message map then your OnSize() will never get called as it will not understand on which event it suppose to call OnSize as OnSize is mapped to WM_SIZE.

MAHESH
0
 
mahesh1402Commented:
>>I am using .NET. I don't believe that it has Class Wizard. That is what is making this a little uncomfortable for me

Here its how to do in .NET :

In your project Select From menu View->Class View. Right Click on class name and select properties. In Right pane you will see Properties of class. Click on Messages button which is located at position 5th Button from left. Now you will see All messages. Click on list box in next to WM_SIZE where you will be able to select <Add>OnSize

Now it will let you add code for handle function OnSize.

MAHESH
0
 
cafechrisAuthor Commented:
Hmmm,
Thats exactly what I did. Usually it seems to do it, I am using .NET for the first time and don't really know exactly how it does everything. Seems like it messed up then, it put the afx_msg code in, but not the ON_WM message Map. Thanks.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now