Solved

MDI application - switch between documents

Posted on 2004-10-07
3
277 Views
Last Modified: 2006-11-17
In an MDI application, can I know when the user switches between documents? More precisely, can a document know when it becomes active and/or inactive?

The reason I want this is the following: when working with a document, a user can call a modeless dialog which displays some info for him. Since the dialog is modeless, the user can then open another document. However, because it is still a dialog, its "priority" is higher than that any view. I want to write something like this:

OnActiveDocument()
{
  if (Dialog && IsWindow(Dialog->m_hWnd))
     Dialog->ShowWindow(SW_SHOW);
}

OnDeactiveDocument()
{
  if (Dialog && IsWindow(Dialog->m_hWnd))
     Dialog->ShowWindow(SW_HIDE);
}

Is it at all possible?
0
Comment
Question by:Lescha
[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
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 50 total points
ID: 12247429
I believe you'll have to handle the WM_ACTIVATE message in the MDI child window. The window should receive that message whenever the window gets the focus in the application.
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12247500
// This is a delphi routine, so hopefully you can translate it...

Procedure WndProc(var Message: TMessage);
var
  NotActive:boolean;
begin
  if Message.Msg=WM_Activate then begin
     NotActive=(Message.wparamlo=WA_INACTIVE);
    // Do something with NotActive here...
  end;
end;

Value of the low-order word of wParam. Specifies whether the window is being activated or deactivated. This parameter can be one of the following values:

Value      Meaning
WA_ACTIVE      Activated by some method other than a mouse click (for example, by a call to the SetActiveWindow function or by use of the keyboard interface to select the window).
WA_CLICKACTIVE      Activated by a mouse click.
WA_INACTIVE      Deactivated.

// Here's what TMessage should look like...
type
  TMessage = packed record
    Msg: Cardinal;
    case Integer of
      0: (
        WParam: Longint;
        LParam: Longint;
        Result: Longint);
      1: (
        WParamLo: Word;
        WParamHi: Word;
        LParamLo: Word;
        LParamHi: Word;
        ResultLo: Word;
        ResultHi: Word);
  end;
0
 
LVL 1

Author Comment

by:Lescha
ID: 12266832
Correct except for the "click" part. MFC doesn't have this distinction. Never mind, I don't this distinction, anyway.

Thanks!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

738 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