BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Minimizing and restoring a maximized MDI child window

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Pawel Tatera
Guest





PostPosted: Sun Feb 19, 2006 4:03 pm    Post subject: Minimizing and restoring a maximized MDI child window Reply with quote



Hi.

I'd like to ask what to do to make a maximized MDI child window back to it's
previous position (size), before it was maximized?

I have a main window procedure that part of looks like this:
....
case WM_COMMAND:
HWND mdiActive = (HWND) SendMessage(mdi , WM_MDIGETACTIVE , 0 , 0);
switch (LOWORD(wParam)){
...
/* MDI BOX STUFF */
case IDM_TS_MDI_TILE:
SendMessage(mdi, WM_MDITILE , (WPARAM) (MDITILE_HORIZONTAL |
MDITILE_SKIPDISABLED) , 0);
break;
case IDM_TS_MDI_MAX:
SendMessage(mdi, WM_MDIMAXIMIZE , (WPARAM) mdiActive , 0);
break;
case IDM_TS_MDI_RESTORE:
SendMessage(mdi, WM_MDIRESTORE , (WPARAM) mdiActive , 0);
break;
case IDM_TS_MDI_CASCADE:
SendMessage(mdi, WM_MDICASCADE, 0, 0);
break;
....
IDM_TS_MDI_TILE, IDM_TS_MDI_MAX, IDM_TS_MDI_RESTORE, IDM_TS_MDI_CASCADE are
my custom message triggers defined elswere in the code.

Now when I press any of MDI child box system buttons
(minimize/maximize/close) or select from application menu option that
triggers any of above IDM... messages the MDI CHILD window reacts correctly,
it minimizes/closes itself.

After I maximize w child window, so it's icon moves into the main window
menu and system buttons (minimize/restore/close) show up under main window
system buttons, I can't force that active child window to minimize/restore
to it's previous position using system buttons (my custom IDM... triggers
(from application menu) all work fine; they make the child window to
minimize/restore).

I was trying to put WM_SYSCOMMAND into MDI child box procedure, but catching
SC_RESTORE doesn't seem to work for me. The piece of code from MDI child
proc. looks like this:

.....
case WM_SYSCOMMAND:
switch(wParam){
case SC_RESTORE:
MessageBox(NULL, "OK","Catching SC_RESTORE EVENT", MB_OK);
/*
placed MsgBox here to check if application reacts on mouse clicks on the
system restore button but
without effect; message box doesn't show up.
*/
break;
}
return DefMDIChildProc(hwnd, msg, wParam, lParam);
/* DefMDI... is called after application handles WM_SYSCOMMAND. */

Any idea what message should I catch/pass from main window proc./mdi proc.
to make the child window to minimize?
All help is welcome and appreciated.

Kind regards.
PawelT
Back to top
JD
Guest





PostPosted: Sun Feb 19, 2006 8:03 pm    Post subject: Re: Minimizing and restoring a maximized MDI child window Reply with quote



"Pawel Tatera" <paweltatera (AT) pa80 (DOT) chodziez.sdi.tpnet.pl> wrote:
Quote:


Using the VCL, this works for me:

//-------------------------------------------------------------
void __fastcall TForm1::ToolButton2Click(TObject *Sender)
{
if( (Screen->ActiveForm->WindowState == wsMinimized) || (Screen->ActiveForm->WindowState == wsMaximized) )
{
Screen->ActiveForm->Perform( WM_SYSCOMMAND, SC_RESTORE, NULL );
}
else Screen->ActiveForm->Perform( WM_SYSCOMMAND, SC_MAXIMIZE, NULL );
}
//-------------------------------------------------------------


protected: // User declarations
virtual void __fastcall WndProc( TMessage &Message );
//-------------------------------------------------------------
void __fastcall TForm2::WndProc( TMessage &Message )
{
if( Message.Msg == WM_SYSCOMMAND )
{
switch( Message.WParam )
{
case SC_MINIMIZE: ShowMessage("Minimizing"); break;
case SC_MAXIMIZE: ShowMessage("Maximizing"); break;
case SC_RESTORE : ShowMessage("Restoring"); break;
}
}
TForm::WndProc( Message );
}
//-------------------------------------------------------------

~ JD
Back to top
Pawel Tatera
Guest





PostPosted: Sun Feb 19, 2006 10:03 pm    Post subject: Re: Minimizing and restoring a maximized MDI child window Reply with quote



Well .

I'm not using a VCL; simply freecommandline tools (hardcore version Smile).
I see you used here a function ToolButton2Click(...); Don't know if there is
a replacement
for that in NO VCL version but I'll try to work it out.

Quote:
void __fastcall TForm1::ToolButton2Click(TObject *Sender)

and pass the WM_SYSCOMMAND to the child window.

You pointed me the way.
Thanks.

PawelT
Back to top
Pawel Tatera
Guest





PostPosted: Mon Feb 20, 2006 7:03 pm    Post subject: Re: Minimizing and restoring a maximized MDI child window Reply with quote

Hi again.

I found only one part solution. I have noticed that when I maximize the MDI
child window the WM_SYSCOMMAND's of a child become WM_COMMANDS of the main
window. So I can do something like this inside the main window procedure:

switch (message){
...
case WM_COMMAND:
mdiActive = (HWND) SendMessage(mdi , WM_MDIGETACTIVE , 0 , 0);
switch (LOWORD(wParam)){
case IDM_TS_MDI_RESTORE:
case SC_RESTORE:
SendMessage(mdi, WM_MDIRESTORE , (WPARAM) mdiActive , 0);
break;
....
}
return 0; //when processing WM_COMMAND application must return 0;
....

I have set MDI box procedure to leave WM_SYSCOMMAND for default processing.

The above proc. looks and works very nice. The child window restores itself
from maximized to restored position.
Unfortunately (for me) other commands (SC_MINIMIZE, SC_CLOSE) make the
application to crash.
(it ates all CPU resources and hangs).
It happens when I modify above proc. so it looks like this:

switch (message){
...
case WM_COMMAND:
mdiActive = (HWND) SendMessage(mdi , WM_MDIGETACTIVE , 0 , 0);
switch (LOWORD(wParam)){
case IDM_TS_MDI_RESTORE:
case SC_RESTORE:
SendMessage(mdi, WM_MDIRESTORE , (WPARAM) mdiActive , 0);
break;
case SC_MINIMIZE: //as a WM_COMMAND
SendMessage(mdi, WM_SYSCOMMAND, (WPARAM) SC_MINIMIZE, 0);
break;
....
}
return 0;
....

Does anyone have a solution for that??
Thanks in advance.

PawelT
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.