Solved

MDI application - switch between documents

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

16 Experts available now in Live!

Get 1:1 Help Now