473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Modal Window Mouse Capture Outside of Bounds?


If Form1 opens Form2 modally, how do I capture clicks on Form1 when
Form2 is open? I want to click on Form1 and read the mouse co-ordinates
into Form2. Since Form2 is open modally, Form1 mouse-events do not
fire. What events on Form2 fire?
I could open Form2 modelessly, then process from within Form1 mouse
events. Is there any other way?
May 7 '07 #1
10 4806
On Sun, 06 May 2007 20:42:05 -0700, bern11 <be****@yahoo.comwrote:
If Form1 opens Form2 modally, how do I capture clicks on Form1 when
Form2 is open?
You can't. That's the definition of modal...user input to other windows
is disabled.
[...]
I could open Form2 modelessly, then process from within Form1 mouse
events. Is there any other way?
No. If you want Form1 to get user input while Form2 is open, Form2 cannot
be modal.

Pete
May 7 '07 #2
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 06 May 2007 20:42:05 -0700, bern11 <be****@yahoo.comwrote:
>If Form1 opens Form2 modally, how do I capture clicks on Form1 when
Form2 is open?

You can't. That's the definition of modal...user input to other windows
is disabled.
>[...]
I could open Form2 modelessly, then process from within Form1 mouse
events. Is there any other way?

No. If you want Form1 to get user input while Form2 is open, Form2 cannot
be modal.
It depends on what you're doing. The modal form might be a dropdown that you
want to have disappear when the use clicks outside. For this I just override
WndProc and trap the non client mouse clicks. I think they start with WM_NC.
>
Pete

May 7 '07 #3
On Sun, 06 May 2007 21:36:13 -0700, Michael C <no****@nospam.comwrote:
>No. If you want Form1 to get user input while Form2 is open, Form2
cannot be modal.

It depends on what you're doing. The modal form might be a dropdown that
you want to have disappear when the use clicks outside. For this I just
override WndProc and trap the non client mouse clicks. I think they start
with WM_NC.
Well, it's programming. There is always a way to do anything you want.
But it is frequently not worth the trouble, and this is especially true
when one is essentially wanting to violate the standard UI behavior.

But beyond any of that, .NET doesn't provide a way to do this. You have
to go into the guts of things to fake it.

I'll also point out that your example is a lot simpler than what the OP
wants, since in your case it's still your "modal form" that is getting the
mouse clicks. To address the OP's goal, you'd have to get those clicks,
translate them for the underlying form, and post them to that form's
message queue.

Pete
May 7 '07 #4
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
Well, it's programming. There is always a way to do anything you want.
But it is frequently not worth the trouble, and this is especially true
when one is essentially wanting to violate the standard UI behavior.
It really depends on the specific situation. We don't know if the OP is
violating anything.
But beyond any of that, .NET doesn't provide a way to do this. You have
to go into the guts of things to fake it.
Really it does, you just override WndProc. This is all managed code.
I'll also point out that your example is a lot simpler than what the OP
wants, since in your case it's still your "modal form" that is getting the
mouse clicks. To address the OP's goal, you'd have to get those clicks,
translate them for the underlying form, and post them to that form's
message queue.
The way I read it he wants to clicks sent to the modal form. This doesn't
seem that big a deal, in fact MS provide specifically for this with their
non-client mouse messages. Those messages are there for a reason.

Michael
May 8 '07 #5
On Mon, 07 May 2007 17:10:42 -0700, Michael C <no****@nospam.comwrote:
[...]
>But beyond any of that, .NET doesn't provide a way to do this. You have
to go into the guts of things to fake it.

Really it does, you just override WndProc. This is all managed code.
I guess that's in the eye of the beholder. I don't consider any solution
that involves overriding WndProc to be "managed" per se. Yes, it doesn't
require the use of "unsafe", but it's definitely getting into the
underlying native Windows API, rather than relying on the .NET Framework.
And, of course, there still remains the question as to whether overriding
WndProc would be sufficient for the OP's needs.
The way I read it he wants to clicks sent to the modal form. This doesn't
seem that big a deal, in fact MS provide specifically for this with their
non-client mouse messages. Those messages are there for a reason.
I agree, unless he clarifies, we don't really know what he wants to do.
To me, though, it sounds as though he wants the user to interact with his
first form, but have results from that show up in his second (modal)
form. It's not sufficient to just get mouse input from outside the client
area; he needs to, at a minimum, translate that input relative to the
first form (if not actually handle the click in the first form...it's not
really clear).

And I also agree that we don't know for sure that he's violating any UI
standard. But what he's doing sure *sounds* a lot like why we have the
concept of modeless dialogs in the first place. I haven't seen anything
that would suggest there's any good reason to make the second dialog modal.

Pete
May 8 '07 #6
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
I guess that's in the eye of the beholder. I don't consider any solution
that involves overriding WndProc to be "managed" per se. Yes, it doesn't
require the use of "unsafe", but it's definitely getting into the
underlying native Windows API, rather than relying on the .NET Framework.
And, of course, there still remains the question as to whether overriding
WndProc would be sufficient for the OP's needs.
That's true, although it is technically managed it does require greater
knowledge. It not terribly difficult though.
I agree, unless he clarifies, we don't really know what he wants to do.
To me, though, it sounds as though he wants the user to interact with his
first form, but have results from that show up in his second (modal)
form. It's not sufficient to just get mouse input from outside the client
area; he needs to, at a minimum, translate that input relative to the
first form (if not actually handle the click in the first form...it's not
really clear).

And I also agree that we don't know for sure that he's violating any UI
standard. But what he's doing sure *sounds* a lot like why we have the
concept of modeless dialogs in the first place. I haven't seen anything
that would suggest there's any good reason to make the second dialog
modal.
It is possible he wants to violate windows standards but my point was it is
quite possible he doesn't. Quite often I read what seems like outrageous
ideas on here but when explained further they make sense. For example when
customising a toolbar in excel the customise box is modal but you can drag
toolbar buttons off toolbars. I think the OP needs to explain, although we
haven't heard from him in a while.

Michael
May 8 '07 #7
On Mon, 07 May 2007 18:24:06 -0700, Michael C <no****@nospam.comwrote:
[...]
It is possible he wants to violate windows standards but my point was it
is quite possible he doesn't. Quite often I read what seems like
outrageous
ideas on here but when explained further they make sense. For example
when customising a toolbar in excel the customise box is modal but you
can
drag toolbar buttons off toolbars.
Funny you should bring that up. :) I suppose that UI is so entrenched
that it's the de facto standard now. But it's always bugged me, because
of the "sort of modal, sort of modeless" nature of it. You are correct
that it's modal. You can't do anything except what the toolbar customize
UI allows you to do, until you close the dialog box. On the other hand,
I've always felt there is insufficient feedback to the user with respect
to the modal nature. In a lot of ways, it *looks* modeless, even though
it's modal.

If I had my way, I would have designed the UI so that rather than it being
completely modal but looking non-modal, it would actually be modeless,
while making it clear that when the customize dialog box is active, you
are editing your UI rather than the document. The document itself would
be greyed out, dimmed, or otherwise displayed as inactive, but you would
still be able to do things like adjust the program's window size, or even
exit the application.

I realize a lot of this is subjective, and plenty of people probably
disagree (for sure, the program manglers over in the Office group do, I'm
sure :) ). But hopefully the above provides some insight into how I feel
about modeless versus modal.
I think the OP needs to explain, although
we haven't heard from him in a while.
Yup. Seems like a common problem when answering questions around here. :)

Pete
May 8 '07 #8
Peter Duniho wrote:
On Mon, 07 May 2007 17:10:42 -0700, Michael C <no****@nospam.comwrote:
>[...]
>>But beyond any of that, .NET doesn't provide a way to do this. You have
to go into the guts of things to fake it.


Really it does, you just override WndProc. This is all managed code.


I guess that's in the eye of the beholder. I don't consider any
solution that involves overriding WndProc to be "managed" per se. Yes,
it doesn't require the use of "unsafe", but it's definitely getting
into the underlying native Windows API, rather than relying on the .NET
Framework. And, of course, there still remains the question as to
whether overriding WndProc would be sufficient for the OP's needs.
>The way I read it he wants to clicks sent to the modal form. This doesn't
seem that big a deal, in fact MS provide specifically for this with their
non-client mouse messages. Those messages are there for a reason.


I agree, unless he clarifies, we don't really know what he wants to
do. To me, though, it sounds as though he wants the user to interact
with his first form, but have results from that show up in his second
(modal) form. It's not sufficient to just get mouse input from outside
the client area; he needs to, at a minimum, translate that input
relative to the first form (if not actually handle the click in the
first form...it's not really clear).

And I also agree that we don't know for sure that he's violating any UI
standard. But what he's doing sure *sounds* a lot like why we have the
concept of modeless dialogs in the first place. I haven't seen
anything that would suggest there's any good reason to make the second
dialog modal.

Pete
I want the clicks sent to the modal form. If I can capture them, I can
get the mouse screen position from the Cursor.Position property. I'm
actually after the screen pixel color that the mouse clicks on. I have
it working modelessly through an event handler in Form1. It would be
nice to keep it all in Form2 though.
May 9 '07 #9
bern11 wrote:
Peter Duniho wrote:
>On Mon, 07 May 2007 17:10:42 -0700, Michael C <no****@nospam.comwrote:
>>[...]

But beyond any of that, .NET doesn't provide a way to do this. You
have
to go into the guts of things to fake it.

Really it does, you just override WndProc. This is all managed code.

I guess that's in the eye of the beholder. I don't consider any
solution that involves overriding WndProc to be "managed" per se.
Yes, it doesn't require the use of "unsafe", but it's definitely
getting into the underlying native Windows API, rather than relying
on the .NET Framework. And, of course, there still remains the
question as to whether overriding WndProc would be sufficient for the
OP's needs.
>>The way I read it he wants to clicks sent to the modal form. This
doesn't
seem that big a deal, in fact MS provide specifically for this with
their
non-client mouse messages. Those messages are there for a reason.

I agree, unless he clarifies, we don't really know what he wants to
do. To me, though, it sounds as though he wants the user to interact
with his first form, but have results from that show up in his second
(modal) form. It's not sufficient to just get mouse input from
outside the client area; he needs to, at a minimum, translate that
input relative to the first form (if not actually handle the click in
the first form...it's not really clear).

And I also agree that we don't know for sure that he's violating any
UI standard. But what he's doing sure *sounds* a lot like why we
have the concept of modeless dialogs in the first place. I haven't
seen anything that would suggest there's any good reason to make the
second dialog modal.

Pete


I want the clicks sent to the modal form. If I can capture them, I can
get the mouse screen position from the Cursor.Position property. I'm
actually after the screen pixel color that the mouse clicks on. I have
it working modelessly through an event handler in Form1. It would be
nice to keep it all in Form2 though.
PS. I want to keep it modal because the second form is an editor on the
first form. I'm masking out the pixel(s) in an image displayed in the
first form when they are clicked on. It works pretty cool. When it is
modeless, I cannot prevent other editing windows from opening and all my
'mode' flags become useless.
May 9 '07 #10
"bern11" <be****@yahoo.comwrote in message
news:R5******************************@comcast.com. ..
PS. I want to keep it modal because the second form is an editor on the
first form. I'm masking out the pixel(s) in an image displayed in the
first form when they are clicked on. It works pretty cool. When it is
modeless, I cannot prevent other editing windows from opening and all my
'mode' flags become useless.
If it's working the way you're doing it then I'd leave it like that. Better
to use managed code if possible.
May 9 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lee | last post by:
I am using a modal window and an iFrame to try and pull a return value back. I am doing this across domains. I have the value returned from the modal window to the iFrame window but I can not...
3
by: Sharon | last post by:
Hi y'all, I'm trying to figure out how to tackle this problem: I have an XML table with a cool grid in which users can select a table row. When they right-click on a cell, they get a modal dialog...
1
by: gopal srinivasan | last post by:
I need to know how to close a parent modal window when child modal window opens, also i need to know the syntax for writing document on the modal window on the fly, like what we do in case of...
1
by: stellabein | last post by:
Hi friends, I am very very new to programing. i have a one main window from that window i am opening one modal window using showmodaldialog(m.jp...). in that modal window i have a form. when i...
4
by: atn2002 | last post by:
How can I track the mouse coordinates outside the active window? No one can tell me its not possible because Google Spreadsheets and EditGrid both do it. When you drag down to select cells these...
0
by: homsar | last post by:
I've seen many posts discussing the options we have when using modal windows within a web based application. Often times it seems the greatest hurdle is simply getting the modal window to post back...
0
by: Laurahn | last post by:
Hi: i'm using modal window (showmodelessdialog) on asp. when the object is created i used session variables. After the object is closed the data is remaining on the modal window when is open...
1
by: Laurahn | last post by:
Hi: i'm using modal window (showmodelessdialog) on asp. when the object is created i used session variables. After the object is closed the data is remaining on the modal window when is open...
2
by: vindesh | last post by:
Applet hides Modal Window Hi All, I am facing one problem for which i am getting any help. I am calling javascript function on ClickEvent. This javascript function creates Modal window. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.