Solved

MDI application - switch between documents

Posted on 2004-10-07
3
251 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will show, step by step, how to integrate R code into a R Sweave document
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now