Home All Groups Group Topic Archive Search About

Locate MessageBox over Window

Author
27 Mar 2005 1:35 AM
Ed Bitzer
One option of the messagebox object indicates it can be placed over a
selected window rather than just appearing centered on the desktop.  The
function is "Overloads Public Shared Function Show(IWin32Window, String) As
DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToString()
rtn = MessageBox.Show(winhandle, "My message")
\\\

Unfortunately the winhandle becomes the content with the My message as the
title and the box in the center of the desktop, not over form1.
Appreciate some help.

Ed

Author
27 Mar 2005 1:46 AM
Herfried K. Wagner [MVP]
"Ed Bitzer" <edbit***@yahoo.com> schrieb:
> One option of the messagebox object indicates it can be placed over a
> selected window rather than just appearing centered on the desktop.

You can position a messagebox window by using a hook.  A VB6 sample which
can be converted to VB.NET can be found here:

<URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Mar 2005 2:07 AM
Ed Bitzer
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:eBFcC6mMFHA.2704@TK2MSFTNGP15.phx.gbl...

> You can position a messagebox window by using a hook.  A VB6 sample which
> can be converted to VB.NET can be found here:
>
> <URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>

Herfried,
I do thank you but converting that code is over my head.  The vb.net
messagebox object appears to have the capability and simply executed but I
do not understand the window identification syntax.

Ed
Author
27 Mar 2005 9:55 AM
Herfried K. Wagner [MVP]
Ed,

"Ed Bitzer" <edbit***@yahoo.com> schrieb:
>> You can position a messagebox window by using a hook.  A VB6 sample which
>> can be converted to VB.NET can be found here:
>>
>> <URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>
>
> I do thank you but converting that code is over my head.  The vb.net
> messagebox object appears to have the capability and simply executed but I
> do not understand the window identification syntax.

The .NET messagebox doesn't have this capability out of the box (although
you can specify an owner window).  I doubt that it's worth the effort to
center a messagebox.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Mar 2005 6:09 PM
Ed Bitzer
Herfried ,
    Stephany caught my misunderstanding and I do thank you for trying to
help.  Have got to lean how to convert old API's so will study the code you
offered.

Ed
Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:%23hWzQLrMFHA.1392@TK2MSFTNGP10.phx.gbl...
> Ed,
>
> "Ed Bitzer" <edbit***@yahoo.com> schrieb:
>>> You can position a messagebox window by using a hook.  A VB6 sample
>>> which can be converted to VB.NET can be found here:
>>>
>>> <URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>
>>
>> I do thank you but converting that code is over my head.  The vb.net
>> messagebox object appears to have the capability and simply executed but
>> I do not understand the window identification syntax.
>
> The .NET messagebox doesn't have this capability out of the box (although
> you can specify an owner window).  I doubt that it's worth the effort to
> center a messagebox.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
27 Mar 2005 4:01 AM
Stephany Young
The 'owner' parameter to the MessageBox.Show() method is of type
IWin32Window. It does not represent a window handle, rather it represents a
window. so in your case it should be: rtn = MessageBox.Show(Me, "My
message").

The bigger point to understand when you read the documentation is that "You
can use the owner parameter to specify a particular object, which implements
the IWin32Window interface, to place the message box in front of.". Note the
use of the phrase 'in front of'. This means the position of the dialog in
the z-order, not the location of the dialog on the screen.

I have never understood how this parameter is useful. Because the dialog is
modal to the application, I can't see any point in displaying the dialog in
front of a window that might be behind the current window. One would have to
move the current window to see it but the dialog is modal so you can't.


Show quoteHide quote
"Ed Bitzer" <edbit***@yahoo.com> wrote in message
news:%23GsG10mMFHA.1884@TK2MSFTNGP15.phx.gbl...
>
> One option of the messagebox object indicates it can be placed over a
> selected window rather than just appearing centered on the desktop.  The
> function is "Overloads Public Shared Function Show(IWin32Window, String)
> As DialogResult"
>
> I have unsuccessfully tried:
> ///
> Dim winhandle as string
> Dim rtn as DialogResult
> winHandle = Me.Handle.ToString()
> rtn = MessageBox.Show(winhandle, "My message")
> \\\
>
> Unfortunately the winhandle becomes the content with the My message as the
> title and the box in the center of the desktop, not over form1.
> Appreciate some help.
>
> Ed
>
>
Author
27 Mar 2005 6:07 PM
Ed Bitzer
Stephany,

I certainly misunderstood - as you suspected I was not thinking about the
z-order but the placement of the messagebox relative to my form.  My program
has a relatively small window and I found the message box voicing a
confirmation could be "far away."  When I saw this option I jumped, but then
stumbled with my lack of knowledge of IWin32Window interface. So the
alternate solution (besides leaning a bit more, and at 72 I am getting a bit
old for that) is to create my own form and control its position relative to
the form opening it.

Ed


Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:%23zQIZGoMFHA.436@TK2MSFTNGP09.phx.gbl...
> The 'owner' parameter to the MessageBox.Show() method is of type
> IWin32Window. It does not represent a window handle, rather it represents
> a window. so in your case it should be: rtn = MessageBox.Show(Me, "My
> message").
>
> The bigger point to understand when you read the documentation is that
> "You can use the owner parameter to specify a particular object, which
> implements the IWin32Window interface, to place the message box in front
> of.". Note the use of the phrase 'in front of'. This means the position of
> the dialog in the z-order, not the location of the dialog on the screen.
>
> I have never understood how this parameter is useful. Because the dialog
> is modal to the application, I can't see any point in displaying the
> dialog in front of a window that might be behind the current window. One
> would have to move the current window to see it but the dialog is modal so
> you can't.
>
>
> "Ed Bitzer" <edbit***@yahoo.com> wrote in message
> news:%23GsG10mMFHA.1884@TK2MSFTNGP15.phx.gbl...
>>
>> One option of the messagebox object indicates it can be placed over a
>> selected window rather than just appearing centered on the desktop.  The
>> function is "Overloads Public Shared Function Show(IWin32Window, String)
>> As DialogResult"
>>
>> I have unsuccessfully tried:
>> ///
>> Dim winhandle as string
>> Dim rtn as DialogResult
>> winHandle = Me.Handle.ToString()
>> rtn = MessageBox.Show(winhandle, "My message")
>> \\\
>>
>> Unfortunately the winhandle becomes the content with the My message as
>> the title and the box in the center of the desktop, not over form1.
>> Appreciate some help.
>>
>> Ed
>>
>>
>
>
Author
28 Mar 2005 6:24 AM
Stephany Young
That's cool Ed. But remember that 72 is only a spring chicken these days. Go
for it!!!!!!!!

Once you've got your head around it and developed your 'super-duper' dialog
box, I'm sure that we'd all appreciate hearing about it. It's one of those
things that is on everyone's todo list but no-one ever has the time to do
actually do it.

One of the nice things that comes with 'rolling your own' is that you get to
add all that functionality that you wish was in MessageBox, like relative
and absolute positioning, time-out and other goodies.


Show quoteHide quote
"Ed Bitzer" <edbit***@yahoo.com> wrote in message
news:u3otkfvMFHA.3788@tk2msftngp13.phx.gbl...
> Stephany,
>
> I certainly misunderstood - as you suspected I was not thinking about the
> z-order but the placement of the messagebox relative to my form.  My
> program has a relatively small window and I found the message box voicing
> a confirmation could be "far away."  When I saw this option I jumped, but
> then stumbled with my lack of knowledge of IWin32Window interface. So the
> alternate solution (besides leaning a bit more, and at 72 I am getting a
> bit old for that) is to create my own form and control its position
> relative to the form opening it.
>
> Ed
>
>
> "Stephany Young" <noone@localhost> wrote in message
> news:%23zQIZGoMFHA.436@TK2MSFTNGP09.phx.gbl...
>> The 'owner' parameter to the MessageBox.Show() method is of type
>> IWin32Window. It does not represent a window handle, rather it represents
>> a window. so in your case it should be: rtn = MessageBox.Show(Me, "My
>> message").
>>
>> The bigger point to understand when you read the documentation is that
>> "You can use the owner parameter to specify a particular object, which
>> implements the IWin32Window interface, to place the message box in front
>> of.". Note the use of the phrase 'in front of'. This means the position
>> of the dialog in the z-order, not the location of the dialog on the
>> screen.
>>
>> I have never understood how this parameter is useful. Because the dialog
>> is modal to the application, I can't see any point in displaying the
>> dialog in front of a window that might be behind the current window. One
>> would have to move the current window to see it but the dialog is modal
>> so you can't.
>>
>>
>> "Ed Bitzer" <edbit***@yahoo.com> wrote in message
>> news:%23GsG10mMFHA.1884@TK2MSFTNGP15.phx.gbl...
>>>
>>> One option of the messagebox object indicates it can be placed over a
>>> selected window rather than just appearing centered on the desktop.  The
>>> function is "Overloads Public Shared Function Show(IWin32Window, String)
>>> As DialogResult"
>>>
>>> I have unsuccessfully tried:
>>> ///
>>> Dim winhandle as string
>>> Dim rtn as DialogResult
>>> winHandle = Me.Handle.ToString()
>>> rtn = MessageBox.Show(winhandle, "My message")
>>> \\\
>>>
>>> Unfortunately the winhandle becomes the content with the My message as
>>> the title and the box in the center of the desktop, not over form1.
>>> Appreciate some help.
>>>
>>> Ed
>>>
>>>
>>
>>
>
>
Author
28 Mar 2005 10:03 PM
Ed Bitzer
Stephany,

It's not cool being 72 - it's old, ya, unfortunately that bit about you are
only as old as you feel is true and I do hurt after an hour or two of tennis
or even ping pong - but admittedly I can still play.

Don't have the ambition to create a truly flexible message box but have
already added to my "dialer" a window without min and max buttons that
positions itself relative to the calling form where I wanted it.  I also
remember all the  form locations if moved but used an "ini" file rather than
the registry - I still like ini files better.


Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:uWA2J71MFHA.3512@TK2MSFTNGP15.phx.gbl...
> That's cool Ed. But remember that 72 is only a spring chicken these days.
> Go for it!!!!!!!!
>
> Once you've got your head around it and developed your 'super-duper'
> dialog box, I'm sure that we'd all appreciate hearing about it. It's one
> of those things that is on everyone's todo list but no-one ever has the
> time to do actually do it.
>
> One of the nice things that comes with 'rolling your own' is that you get
> to add all that functionality that you wish was in MessageBox, like
> relative and absolute positioning, time-out and other goodies.
>
>
> "Ed Bitzer" <edbit***@yahoo.com> wrote in message
> news:u3otkfvMFHA.3788@tk2msftngp13.phx.gbl...
>> Stephany,
>>
>> I certainly misunderstood - as you suspected I was not thinking about the
>> z-order but the placement of the messagebox relative to my form.  My
>> program has a relatively small window and I found the message box voicing
>> a confirmation could be "far away."  When I saw this option I jumped, but
>> then stumbled with my lack of knowledge of IWin32Window interface. So the
>> alternate solution (besides leaning a bit more, and at 72 I am getting a
>> bit old for that) is to create my own form and control its position
>> relative to the form opening it.
>>
>> Ed
>>
>>
>> "Stephany Young" <noone@localhost> wrote in message
>> news:%23zQIZGoMFHA.436@TK2MSFTNGP09.phx.gbl...
>>> The 'owner' parameter to the MessageBox.Show() method is of type
>>> IWin32Window. It does not represent a window handle, rather it
>>> represents a window. so in your case it should be: rtn =
>>> MessageBox.Show(Me, "My message").
>>>
>>> The bigger point to understand when you read the documentation is that
>>> "You can use the owner parameter to specify a particular object, which
>>> implements the IWin32Window interface, to place the message box in front
>>> of.". Note the use of the phrase 'in front of'. This means the position
>>> of the dialog in the z-order, not the location of the dialog on the
>>> screen.
>>>
>>> I have never understood how this parameter is useful. Because the dialog
>>> is modal to the application, I can't see any point in displaying the
>>> dialog in front of a window that might be behind the current window. One
>>> would have to move the current window to see it but the dialog is modal
>>> so you can't.
>>>
>>>
>>> "Ed Bitzer" <edbit***@yahoo.com> wrote in message
>>> news:%23GsG10mMFHA.1884@TK2MSFTNGP15.phx.gbl...
>>>>
>>>> One option of the messagebox object indicates it can be placed over a
>>>> selected window rather than just appearing centered on the desktop.
>>>> The function is "Overloads Public Shared Function Show(IWin32Window,
>>>> String) As DialogResult"
>>>>
>>>> I have unsuccessfully tried:
>>>> ///
>>>> Dim winhandle as string
>>>> Dim rtn as DialogResult
>>>> winHandle = Me.Handle.ToString()
>>>> rtn = MessageBox.Show(winhandle, "My message")
>>>> \\\
>>>>
>>>> Unfortunately the winhandle becomes the content with the My message as
>>>> the title and the box in the center of the desktop, not over form1.
>>>> Appreciate some help.
>>>>
>>>> Ed
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
29 Mar 2005 10:13 AM
Cor Ligthert
Ed,

> I still like ini files better.
>
Be cautious, this kind of behaviour can show that your age stops you to
check newer solutions. Did you try the registry with VBNet. It is so easy to
use.

Cor
Author
30 Mar 2005 2:00 AM
Ed Bitzer
Cor,

Of course there might actually be some reason to stop checking newer
solutions at my age - times running out<g>.  However I admit I have not even
looked how VB.Net handles and will do so.  The INI file has always made it
so easy to examine and modify content with any ASCII editor.  Not having to
search through the Registry to detect my errors did seem simpler.

Ed

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23%23dSyfENFHA.2576@TK2MSFTNGP10.phx.gbl...
> Ed,
>
>> I still like ini files better.
>>
> Be cautious, this kind of behaviour can show that your age stops you to
> check newer solutions. Did you try the registry with VBNet. It is so easy
> to use.
>
> Cor
>
Author
30 Mar 2005 6:59 AM
Cor Ligthert
Ed,

A piece of code to save your Form settings

\\\
Imports Microsoft.Win32
Public Class RegistryEd
    Private Shared pFormWidth As Integer
    Private Shared pFormHeight As Integer
    Private Shared pFormX As Integer
    Private Shared pFormY As Integer
    Private Shared pWindowState As Integer
    Private Shared Reg As RegistryKey = Registry.CurrentUser
    Public Shared Property FormWidth() As Integer
        Get
            Return pFormWidth
        End Get
        Set(ByVal Value As Integer)
            pFormWidth = Value
        End Set
    End Property
    Public Shared Property FormHeight() As Integer
        Get
            Return pFormHeight
        End Get
        Set(ByVal Value As Integer)
            pFormHeight = Value
        End Set
    End Property
    Public Shared Property FormX() As Integer
        Get
            Return pFormX
        End Get
        Set(ByVal Value As Integer)
            pFormX = Value
        End Set
    End Property
    Public Shared Property FormY() As Integer
        Get
            Return pFormY
        End Get
        Set(ByVal Value As Integer)
            pFormY = Value
        End Set
    End Property
    Public Shared Property WindowState() As Integer
        Get
            Return pWindowState
        End Get
        Set(ByVal Value As Integer)
            pWindowState = Value
        End Set
    End Property
    Public Shared Sub Load()
        Reg = Registry.CurrentUser.CreateSubKey("Software\Cor\EdSample")
        pFormWidth = CInt(Reg.GetValue("Width", 700))
        pFormHeight = CInt(Reg.GetValue("Height", 400))
        pFormX = CInt(Reg.GetValue("X", 100))
        pFormY = CInt(Reg.GetValue("Y", 100))
        pWindowState = CInt(Reg.GetValue("WindowState", 0))
End Sub
Public Shared Sub Save()
        Dim Reg As RegistryKey
        Reg = Registry.CurrentUser.CreateSubKey("Software\Cors\EdSample")
        Reg.SetValue("Width", pFormWidth)
        Reg.SetValue("Height", pFormHeight)
        Reg.SetValue("X", pFormX)
        Reg.SetValue("Y", pFormY)
       End Sub
End Class
///

I hope this gives a QuickStart

Cor
Author
30 Mar 2005 7:08 AM
Cor Ligthert
Ed,

I changed some words and deleted as well some parts, where is Cors it should
be Cor or visa versa. Maybe there are more errors because of that change.

:-)

Cor
Author
30 Mar 2005 10:09 PM
Ed Bitzer
Cor,

I do thank you -- you took all the work out of this project.  Have an
example working already.

Ed
Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23IgEVdPNFHA.1392@TK2MSFTNGP10.phx.gbl...
> Ed,
>
> I changed some words and deleted as well some parts, where is Cors it
> should be Cor or visa versa. Maybe there are more errors because of that
> change.
>
> :-)
>
> Cor
>