Home All Groups Group Topic Archive Search About
Author
23 May 2006 7:45 PM
knikkix@yahoo.com
Hi,

I created a form in VB.Net with only one button. This is the code in
button click event

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        AppGlobals.SetHandles(Me.Handle.ToInt64())
        Call OpenModel()
End Sub

appglobals.sethandles set the handle to window to be used by
postmessage function

Private Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal lpString As String) As IntPtr
    Private Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As IntPtr

    'Private m_xlWindowHandle As IntPtr
    Private m_xlWindowHandle As Long
    Private m_xlMessageID_SC As IntPtr
    Private m_xlMessageID_C As IntPtr

    Public Const c_RegistryKey As String =
"Software\Pzena\StockAnalyzer.NET\Client"
    Public Const r_RegistryKey As String =
"Software\Pzena\StockAnalyzer.NET\Report"

    Public Sub SetHandles(Optional ByVal WndHandle As Long = 0)
        If WndHandle <> 0 Then
            xlWindowHandle = WndHandle
        Else
            'Modified by nikki
            'xlWindowHandle = oParentForm.ActiveMainForm.Handle.ToInt64
        End If
        'xlWindowHandle = oParentForm.ActiveMainForm.Handle
        xlMessageID_SC = RegisterWindowMessage("WM_EXCEL_SAVE_CLOSE")
        xlMessageID_C = RegisterWindowMessage("WM_EXCEL_CLOSE")
    End Sub

    Public Property xlWindowHandle()
        Get
            Return m_xlWindowHandle
        End Get
        Set(ByVal Value)
            m_xlWindowHandle = Value
        End Set
    End Property

    Public Property xlMessageID_SC()
        Get
            Return m_xlMessageID_SC.ToInt64
        End Get
        Set(ByVal Value)
            m_xlMessageID_SC = Value
        End Set
    End Property

    Public Property xlMessageID_C()
        Get
            Return m_xlMessageID_C.ToInt64
        End Get
        Set(ByVal Value)
            m_xlMessageID_C = Value
        End Set
    End Property

    Public ReadOnly Property xlMessageID32_SC()
        Get
            Return m_xlMessageID_SC.ToInt32
        End Get
    End Property

    Public ReadOnly Property xlMessageID32_C()
        Get
            Return m_xlMessageID_C.ToInt32
        End Get
    End Property

OpenModel function calls VBA routine in EXCEl like. This Open Model
function is defined in another class as Class1. There is one more
function call SaveModel defined in same Class1
xlApp.Run("OpenModel", "In Excel", CType(xlWindowHandle, Integer),
CType(xlMessageID_SC, Integer), CType(xlMessageID_C, Integer))

I added one menu in excel at runtime called Menu1 and has one submenu
submenu1
When I click on submenu1 then I am calling this routine
PostMessage(hwnd,wmsave,0,0).

The point is when this Postmessage is executed then it should execute
SaveModel in Class1 in VB.Net but somehow the control is not returned
to it. I don;t know what exactly is the problem.  If somebody please
let me know then I will really appreciate them.

Thanks
Nikki

Author
24 May 2006 2:01 PM
Claes Bergefall
Remove all the ToInt64 stuff. A window handle should be treated as an
IntPtr, not as long
Also rewrite your declare like this:

Private Declare Auto Function RegisterWindowMessage Lib "user32" (ByVal
lpString As String) As Integer
Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As
String, ByVal lpWindowName As String) As IntPtr

Let the runtime figure out if it should call the ansi or unicode version.
Also note that RegisterWindowMessage returns an integer, not IntPtr


   /claes

<knik***@yahoo.com> wrote in message
Show quoteHide quote
news:1148413551.919263.13850@g10g2000cwb.googlegroups.com...
> Hi,
>
> I created a form in VB.Net with only one button. This is the code in
> button click event
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>        AppGlobals.SetHandles(Me.Handle.ToInt64())
>        Call OpenModel()
> End Sub
>
> appglobals.sethandles set the handle to window to be used by
> postmessage function
>
> Private Declare Function RegisterWindowMessage Lib "user32" Alias
> "RegisterWindowMessageA" (ByVal lpString As String) As IntPtr
>    Private Declare Function FindWindow Lib "user32" Alias
> "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
> String) As IntPtr
>
>    'Private m_xlWindowHandle As IntPtr
>    Private m_xlWindowHandle As Long
>    Private m_xlMessageID_SC As IntPtr
>    Private m_xlMessageID_C As IntPtr
>
>    Public Const c_RegistryKey As String =
> "Software\Pzena\StockAnalyzer.NET\Client"
>    Public Const r_RegistryKey As String =
> "Software\Pzena\StockAnalyzer.NET\Report"
>
>    Public Sub SetHandles(Optional ByVal WndHandle As Long = 0)
>        If WndHandle <> 0 Then
>            xlWindowHandle = WndHandle
>        Else
>            'Modified by nikki
>            'xlWindowHandle = oParentForm.ActiveMainForm.Handle.ToInt64
>        End If
>        'xlWindowHandle = oParentForm.ActiveMainForm.Handle
>        xlMessageID_SC = RegisterWindowMessage("WM_EXCEL_SAVE_CLOSE")
>        xlMessageID_C = RegisterWindowMessage("WM_EXCEL_CLOSE")
>    End Sub
>
>    Public Property xlWindowHandle()
>        Get
>            Return m_xlWindowHandle
>        End Get
>        Set(ByVal Value)
>            m_xlWindowHandle = Value
>        End Set
>    End Property
>
>    Public Property xlMessageID_SC()
>        Get
>            Return m_xlMessageID_SC.ToInt64
>        End Get
>        Set(ByVal Value)
>            m_xlMessageID_SC = Value
>        End Set
>    End Property
>
>    Public Property xlMessageID_C()
>        Get
>            Return m_xlMessageID_C.ToInt64
>        End Get
>        Set(ByVal Value)
>            m_xlMessageID_C = Value
>        End Set
>    End Property
>
>    Public ReadOnly Property xlMessageID32_SC()
>        Get
>            Return m_xlMessageID_SC.ToInt32
>        End Get
>    End Property
>
>    Public ReadOnly Property xlMessageID32_C()
>        Get
>            Return m_xlMessageID_C.ToInt32
>        End Get
>    End Property
>
> OpenModel function calls VBA routine in EXCEl like. This Open Model
> function is defined in another class as Class1. There is one more
> function call SaveModel defined in same Class1
> xlApp.Run("OpenModel", "In Excel", CType(xlWindowHandle, Integer),
> CType(xlMessageID_SC, Integer), CType(xlMessageID_C, Integer))
>
> I added one menu in excel at runtime called Menu1 and has one submenu
> submenu1
> When I click on submenu1 then I am calling this routine
> PostMessage(hwnd,wmsave,0,0).
>
> The point is when this Postmessage is executed then it should execute
> SaveModel in Class1 in VB.Net but somehow the control is not returned
> to it. I don;t know what exactly is the problem.  If somebody please
> let me know then I will really appreciate them.
>
> Thanks
> Nikki
>
Author
24 May 2006 2:25 PM
José_Manuel_Agüero
Hello knikkix,

Also review the PostMessage declaration. It should be something like:
declare function PostMessage lib "user32.dll" (byval hWnd as intptr, byval Msg as uint32, byval lParam as int32, byval wParam as int32) as int32

Regards.


Show quoteHide quote
<knik***@yahoo.com> escribió en el mensaje news:1148413551.919263.13850@g10g2000cwb.googlegroups.com...
| Hi,
|
| I created a form in VB.Net with only one button. This is the code in
| button click event
|
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles Button1.Click
|        AppGlobals.SetHandles(Me.Handle.ToInt64())
|        Call OpenModel()
| End Sub
|
| appglobals.sethandles set the handle to window to be used by
| postmessage function
|
| Private Declare Function RegisterWindowMessage Lib "user32" Alias
| "RegisterWindowMessageA" (ByVal lpString As String) As IntPtr
|    Private Declare Function FindWindow Lib "user32" Alias
| "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
| String) As IntPtr
|
|    'Private m_xlWindowHandle As IntPtr
|    Private m_xlWindowHandle As Long
|    Private m_xlMessageID_SC As IntPtr
|    Private m_xlMessageID_C As IntPtr
|
|    Public Const c_RegistryKey As String =
| "Software\Pzena\StockAnalyzer.NET\Client"
|    Public Const r_RegistryKey As String =
| "Software\Pzena\StockAnalyzer.NET\Report"
|
|    Public Sub SetHandles(Optional ByVal WndHandle As Long = 0)
|        If WndHandle <> 0 Then
|            xlWindowHandle = WndHandle
|        Else
|            'Modified by nikki
|            'xlWindowHandle = oParentForm.ActiveMainForm.Handle.ToInt64
|        End If
|        'xlWindowHandle = oParentForm.ActiveMainForm.Handle
|        xlMessageID_SC = RegisterWindowMessage("WM_EXCEL_SAVE_CLOSE")
|        xlMessageID_C = RegisterWindowMessage("WM_EXCEL_CLOSE")
|    End Sub
|
|    Public Property xlWindowHandle()
|        Get
|            Return m_xlWindowHandle
|        End Get
|        Set(ByVal Value)
|            m_xlWindowHandle = Value
|        End Set
|    End Property
|
|    Public Property xlMessageID_SC()
|        Get
|            Return m_xlMessageID_SC.ToInt64
|        End Get
|        Set(ByVal Value)
|            m_xlMessageID_SC = Value
|        End Set
|    End Property
|
|    Public Property xlMessageID_C()
|        Get
|            Return m_xlMessageID_C.ToInt64
|        End Get
|        Set(ByVal Value)
|            m_xlMessageID_C = Value
|        End Set
|    End Property
|
|    Public ReadOnly Property xlMessageID32_SC()
|        Get
|            Return m_xlMessageID_SC.ToInt32
|        End Get
|    End Property
|
|    Public ReadOnly Property xlMessageID32_C()
|        Get
|            Return m_xlMessageID_C.ToInt32
|        End Get
|    End Property
|
| OpenModel function calls VBA routine in EXCEl like. This Open Model
| function is defined in another class as Class1. There is one more
| function call SaveModel defined in same Class1
| xlApp.Run("OpenModel", "In Excel", CType(xlWindowHandle, Integer),
| CType(xlMessageID_SC, Integer), CType(xlMessageID_C, Integer))
|
| I added one menu in excel at runtime called Menu1 and has one submenu
| submenu1
| When I click on submenu1 then I am calling this routine
| PostMessage(hwnd,wmsave,0,0).
|
| The point is when this Postmessage is executed then it should execute
| SaveModel in Class1 in VB.Net but somehow the control is not returned
| to it. I don;t know what exactly is the problem.  If somebody please
| let me know then I will really appreciate them.
|
| Thanks
| Nikki
|
Author
25 May 2006 2:02 PM
Claes Bergefall
You can also overload PostMessage if you need other types for lParam and/or
wParam. The marshaler will handle the conversion for you (within limits)

    /claes

"José Manuel Agüero" <chema012_hotmail.com> wrote in message
news:OhDsj3zfGHA.1320@TK2MSFTNGP04.phx.gbl...
Hello knikkix,

Also review the PostMessage declaration. It should be something like:
declare function PostMessage lib "user32.dll" (byval hWnd as intptr, byval
Msg as uint32, byval lParam as int32, byval wParam as int32) as int32

Regards.


<knik***@yahoo.com> escribió en el mensaje
Show quoteHide quote
news:1148413551.919263.13850@g10g2000cwb.googlegroups.com...
| Hi,
|
| I created a form in VB.Net with only one button. This is the code in
| button click event
|
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles Button1.Click
|        AppGlobals.SetHandles(Me.Handle.ToInt64())
|        Call OpenModel()
| End Sub
|
| appglobals.sethandles set the handle to window to be used by
| postmessage function
|
| Private Declare Function RegisterWindowMessage Lib "user32" Alias
| "RegisterWindowMessageA" (ByVal lpString As String) As IntPtr
|    Private Declare Function FindWindow Lib "user32" Alias
| "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
| String) As IntPtr
|
|    'Private m_xlWindowHandle As IntPtr
|    Private m_xlWindowHandle As Long
|    Private m_xlMessageID_SC As IntPtr
|    Private m_xlMessageID_C As IntPtr
|
|    Public Const c_RegistryKey As String =
| "Software\Pzena\StockAnalyzer.NET\Client"
|    Public Const r_RegistryKey As String =
| "Software\Pzena\StockAnalyzer.NET\Report"
|
|    Public Sub SetHandles(Optional ByVal WndHandle As Long = 0)
|        If WndHandle <> 0 Then
|            xlWindowHandle = WndHandle
|        Else
|            'Modified by nikki
|            'xlWindowHandle = oParentForm.ActiveMainForm.Handle.ToInt64
|        End If
|        'xlWindowHandle = oParentForm.ActiveMainForm.Handle
|        xlMessageID_SC = RegisterWindowMessage("WM_EXCEL_SAVE_CLOSE")
|        xlMessageID_C = RegisterWindowMessage("WM_EXCEL_CLOSE")
|    End Sub
|
|    Public Property xlWindowHandle()
|        Get
|            Return m_xlWindowHandle
|        End Get
|        Set(ByVal Value)
|            m_xlWindowHandle = Value
|        End Set
|    End Property
|
|    Public Property xlMessageID_SC()
|        Get
|            Return m_xlMessageID_SC.ToInt64
|        End Get
|        Set(ByVal Value)
|            m_xlMessageID_SC = Value
|        End Set
|    End Property
|
|    Public Property xlMessageID_C()
|        Get
|            Return m_xlMessageID_C.ToInt64
|        End Get
|        Set(ByVal Value)
|            m_xlMessageID_C = Value
|        End Set
|    End Property
|
|    Public ReadOnly Property xlMessageID32_SC()
|        Get
|            Return m_xlMessageID_SC.ToInt32
|        End Get
|    End Property
|
|    Public ReadOnly Property xlMessageID32_C()
|        Get
|            Return m_xlMessageID_C.ToInt32
|        End Get
|    End Property
|
| OpenModel function calls VBA routine in EXCEl like. This Open Model
| function is defined in another class as Class1. There is one more
| function call SaveModel defined in same Class1
| xlApp.Run("OpenModel", "In Excel", CType(xlWindowHandle, Integer),
| CType(xlMessageID_SC, Integer), CType(xlMessageID_C, Integer))
|
| I added one menu in excel at runtime called Menu1 and has one submenu
| submenu1
| When I click on submenu1 then I am calling this routine
| PostMessage(hwnd,wmsave,0,0).
|
| The point is when this Postmessage is executed then it should execute
| SaveModel in Class1 in VB.Net but somehow the control is not returned
| to it. I don;t know what exactly is the problem.  If somebody please
| let me know then I will really appreciate them.
|
| Thanks
| Nikki
|