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 

How to lock the current child form in a MDI application?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Ma Xiaoguang
Guest





PostPosted: Sun Jul 09, 2006 6:32 am    Post subject: How to lock the current child form in a MDI application? Reply with quote



Dear ladies and gentlemen,

I have wrote a MDI application. In this application, you could open
several child forms. I want to lock up a specific child form when I opened a
custom dialog. Because of I need to pick up colors from the image in the
specific child form for the dialog, so I opened the dialog with Show method,
not the ShowModal method. The question is that if I opened the dialog with
Show method, I could activate other child forms, but this is not what I
want. What I want is that only the child form which is activated before the
dialog has opened could accepts the operations. So I need to lock up a child
form, when the dialog is opened, other child forms couldn't be activated.

The effect is like the Levels tool in the Photoshop. After you opened
several images in PS, and then open the Levels dialog, you could pick up
colors from a activated form, but you couldn't activate other forms.

How can I achieve this? Help me, please. Thank you very much.

Best regards.

Xiaoguang
Back to top
Peter Below (TeamB)
Guest





PostPosted: Sun Jul 09, 2006 2:39 pm    Post subject: Re: How to lock the current child form in a MDI application? Reply with quote



Ma Xiaoguang wrote:

Quote:
I have wrote a MDI application. In this application, you could open
several child forms. I want to lock up a specific child form when I
opened a custom dialog. Because of I need to pick up colors from the
image in the specific child form for the dialog, so I opened the
dialog with Show method, not the ShowModal method. The question is
that if I opened the dialog with Show method, I could activate other
child forms, but this is not what I want. What I want is that only
the child form which is activated before the dialog has opened could
accepts the operations. So I need to lock up a child form, when the
dialog is opened, other child forms couldn't be activated.

This is not easy to achieve with MDI. Basically you would have to
disable all other MDI child forms *and* the main windows menu entries
(at least those that allow switching between children or creating new
ones).

Depending on what kind of operation you need the user to do with the
active MDI child you may actually be able to do this with a standard
modal dialog. If all you need is for the user to click on a spot in the
active child: there are ways to detect a click outside the active
window.

<quote>
Usually one solves this problem by grabbing the mouse capture, so even
mouse events outside the form are "seen" by the form. But there are many
controls that will grab the capture when the user clicks on them, so one
cannot rely on this method unless the form does not contain controls
that grab capture when clicked on. Which basically leaves us with a not
quite perfect kludge: a timer that checks moouse position and button
state in short intervals:

The timer in the example has an interval of 100 msecs and is enabled at
design-time:

procedure TForm2.Timer1Timer(Sender: TObject);
begin
If Showing and (GetAsyncKeyState( VK_LBUTTON ) < 0) Then
If not PtInRect( BoundsRect, Mouse.CursorPos )
Then
..use Mouse.CursorPos to figure out where the mouse is
end;

It is not totally perfect, a very fast click can escape its notice. One
could reduce the interval to minimize that but at the cost of increasing
CPU load a bit.
</quote>

To pick up the color of the pixel under the mouse you don't even need
to figure out where the mouse is exactly, the Windows.GetPixel function
will happily pick up a color from the screen anywhere you like if you
hand it a device context handle for the screen:

function GlobalGetPixel(const Pt: TPoint): TColor;
var
DC: HDC;
begin
DC:= GetDC(0);
try
Result := Windows.GetPixel(DC, Pt.X, Pt.Y) and $FFFFFF;
finally
ReleaseDC(0, DC);
end;
end;


--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Ma Xiaoguang
Guest





PostPosted: Mon Jul 10, 2006 7:10 am    Post subject: Re: How to lock the current child form in a MDI application? Reply with quote



Hello Peter,

Thanks for your help. I deeply appreciate it.

Best regards

Xiaoguang

"Peter Below (TeamB)" <none>
??????:xn0eoin2b28a15000 (AT) newsgroups (DOT) borland.com...
Quote:
Ma Xiaoguang wrote:

I have wrote a MDI application. In this application, you could open
several child forms. I want to lock up a specific child form when I
opened a custom dialog. Because of I need to pick up colors from the
image in the specific child form for the dialog, so I opened the
dialog with Show method, not the ShowModal method. The question is
that if I opened the dialog with Show method, I could activate other
child forms, but this is not what I want. What I want is that only
the child form which is activated before the dialog has opened could
accepts the operations. So I need to lock up a child form, when the
dialog is opened, other child forms couldn't be activated.

This is not easy to achieve with MDI. Basically you would have to
disable all other MDI child forms *and* the main windows menu entries
(at least those that allow switching between children or creating new
ones).

Depending on what kind of operation you need the user to do with the
active MDI child you may actually be able to do this with a standard
modal dialog. If all you need is for the user to click on a spot in the
active child: there are ways to detect a click outside the active
window.

quote
Usually one solves this problem by grabbing the mouse capture, so even
mouse events outside the form are "seen" by the form. But there are many
controls that will grab the capture when the user clicks on them, so one
cannot rely on this method unless the form does not contain controls
that grab capture when clicked on. Which basically leaves us with a not
quite perfect kludge: a timer that checks moouse position and button
state in short intervals:

The timer in the example has an interval of 100 msecs and is enabled at
design-time:

procedure TForm2.Timer1Timer(Sender: TObject);
begin
If Showing and (GetAsyncKeyState( VK_LBUTTON ) < 0) Then
If not PtInRect( BoundsRect, Mouse.CursorPos )
Then
..use Mouse.CursorPos to figure out where the mouse is
end;

It is not totally perfect, a very fast click can escape its notice. One
could reduce the interval to minimize that but at the cost of increasing
CPU load a bit.
/quote

To pick up the color of the pixel under the mouse you don't even need
to figure out where the mouse is exactly, the Windows.GetPixel function
will happily pick up a color from the screen anywhere you like if you
hand it a device context handle for the screen:

function GlobalGetPixel(const Pt: TPoint): TColor;
var
DC: HDC;
begin
DC:= GetDC(0);
try
Result := Windows.GetPixel(DC, Pt.X, Pt.Y) and $FFFFFF;
finally
ReleaseDC(0, DC);
end;
end;


--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Mon Jul 10, 2006 7:19 am    Post subject: Re: How to lock the current child form in a MDI application? Reply with quote

At 04:10:37, 10.07.2006, Ma Xiaoguang wrote:

Quote:
Hello Peter,

Thanks for your help. I deeply appreciate it.

Best regards

Xiaoguang

While I'm sure Peter will appreciate your gratitude, I doubt he'll
appreciate the fact that your message contained 86 lines, of which only
the one above were new content.

Please, next time, do not overquote.

http://blogs.teamb.com/rudyvelthuis/articles/7509.aspx

--
Rudy Velthuis [TeamB] http://rvelthuis.de/

"No Sane man will dance."
- Cicero (106-43 B.C.)
Back to top
Ma Xiaoguang
Guest





PostPosted: Mon Jul 10, 2006 2:01 pm    Post subject: Re: How to lock the current child form in a MDI application? Reply with quote

Hello Rudy,

Thanks for you advice.

Best regards.

Xiaoguang
Back to top
Ma Xiaoguang
Guest





PostPosted: Tue Jul 11, 2006 5:46 am    Post subject: Re: How to lock the current child form in a MDI application? Reply with quote

Hello Peter,

I think that I could using the following code to disable all the MDI
Childs except the current activated one:

for I := MDIChildCount-1 downto 0 do
begin
if MDIChildren[I] <> The Activated
then MDIChildren[I].Enable := False;
end;

Best regards.

Xiaoguang
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics 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.