Solved

MDI application - switch between documents

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

821 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