Re: Get window click unless on a control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Mayayana,

Crystal clear now. Thanks so much for taking all the time to respond so
thoroughly! Thanks so much!

"mayayana" wrote:


<Div ID="lbxSourceFiles">
<Select Name=lbxSource...>

Now, I don't want the window click to detect a click on this control, so
how
would my Sub look?


You can do the cancel, as posted above, by ThatsIT.net.au.
That would go something like:
--------
Sub lbxSource_onclick()
window.event.cancelBubble = true
End Sub
--------

That would prevent the click from "bubbling up".
In other words, it stops the event from being "fired"
at document level.

But you said that you wanted to run your script only
if the window is clicked and ignore the click if it was
on any button, listbox, or other control. If you use the
cancelBubble method then you need to name, and write
a sub for, all SELECT and INPUTobjects. By using
the window.event in the document_onclick sub you can
get the same result with just one sub.

Window.event has a property srcElement, which is basically
the "tag object" that was clicked. So if you use
window.event.srcElement then you now have a reference
to the tag associated with the click and you can access
any property of that tag. Since all tags have a name
property in the IE DOM, you can use that if you want to.

window.event.srcElement.tagName returns the HTML
tag that was clicked: DIV, SPAN, TD, INPUT, BODY, etc.

window.event.srcElement.name will return the tag name,
if any.

So if you do the following and click on your listbox...
-------
Sub Document_OnClick
msgbox window.event.srcElement.tagName & "-" &
window.event.srcElement.name
End Sub
-------
....then you should see a msgbox that says "SELECT-lbxSource".


So what I was describing originally was a way to avoid
needing to deal with cancelling each individual object
event, since what you really want is a body_onclick sub.
Since a listbox is a SELECT tag, and a button
is an INPUT tag, you can respond to any click in the
window - but not when it's on the listbox or a button -
by using:

Sub Document_OnClick()
Dim sTagType
sTagType = UCase(window.event.srcElement.tagName)

Select Case sTagType
Case "SELECT", "INPUT" '-- listbox, textbox, button, etc. clicked.
Exit Sub
Case else '-- this could be BODY, TD, SPAN, etc.
msgbox "This is reacting to a click in the window."
End Select
End Sub

You could also filter all buttons but not text fields by
using:

Select Case sTagType
Case "SELECT"
Exit Sub
Case "INPUT"
'-- drop out clicks on buttons but not on input fields:
if window.event.srcElement.type = "button" then Exit Sub
Case else
msgbox "This is reacting to a click in the window."
End Select




.



Relevant Pages

  • Re: Get window click unless on a control
    ... Now, I don't want the window click to detect a click on this control, so ... You can do the cancel, as posted above, by ThatsIT.net.au. ... a sub for, all SELECT and INPUTobjects. ... the "tag object" that was clicked. ...
    (microsoft.public.scripting.vbscript)
  • Re: Where is MAKEWPARAM
    ... The reason why Notepad didn't receive any of the messages with your>> version of the programwas that Notpad has one main top-level window and>> the ... >> Inherits System.Windows.Forms.Form>> Private Declare Function SetActiveWindow Lib "user32" Alias>> "SetActiveWindow" (ByVal hwnd As IntPtr) As IntPtr>> Private Declare Function SetForegroundWindow Lib "USER32" (ByVal hwnd>> As ... >> Public Sub New ...
    (microsoft.public.dotnet.framework.windowsforms)
  • reuse code inquiry
    ... I am a perl beginner and I am suggested to parse HTML by using ... sub parse_html { ... # incomplete tag. ... if ($routine eq "") { ...
    (comp.lang.perl.misc)
  • Re: API to find position of active cell no longer working in 2007.
    ... the EXCELE window remains as does its window coordinates ... Private Sub CommandButton1_Click ... Dim hWndXLDesk As Long ... Dim nRow As Long, nCol As Long ...
    (microsoft.public.excel.programming)
  • Re: Drawing Semi-Transparent Form
    ... > I'm writing an app that creates its own window class and subclassing etc. ... Private Declare Function CreateCompatibleDC& Lib "gdi32" ... Public Sub VBBlend'OpDC2 over OpDC1 with Ratio ...
    (microsoft.public.vb.winapi.graphics)