P/Invoke Problem selected index changing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jr

    P/Invoke Problem selected index changing

    I'm writing a .net application that will update several textboxes and
    comboboxes on a 2nd app (3rd party-no source). I have the part that is
    updating the textboxes and comboboxes working pretty well.

    The problem is that it looks like they have the some events tied to one
    of the comboxes selected_index_ changed events so that it changes one of
    the textboxes to a combobox or vice-versa. When I enter something in a
    the combo manually and tab out the 2nd control changes, but this does
    _not_ happen when I use my api calls. I've tried setting the focus
    through api calls, but this doesn't do anything either. Is there
    someway to fire the app's combo event. I'm a little stuck here, and
    would appreciate any suggestions.

    Some code:

    Private Const WM_SETTEXT As Int32 = &HC
    Private Const CB_SETCURSEL As Long = &H14E
    Private Const CB_FINDSTRING as long = &H14C
    Public Const WM_SETFOCUS As Long = &H7
    Private Const WM_PASTE As Long = &H302


    Private Declare Function SendMessageBySt ring Lib "user32.dll " Alias
    "SendMessag eA" _
    (ByVal hwnd As IntPtr, _
    ByVal uMsg As Int32, _
    ByVal wParam As IntPtr, _
    ByVal lParam As String) As Integer


    Public Declare Ansi Function SendMessage Lib "user32.dll " Alias
    "SendMessag eA" _
    (ByVal hwnd As IntPtr, _
    ByVal wMsg As Int32, _
    ByVal wParam As Int32, _
    ByVal lParam As String) As Integer

    ''set focus -
    <DllImport("use r32.dll", CharSet:=CharSe t.Auto, SetLastError:=T rue)_
    Public Shared Function SendNotifyMessa ge(ByVal hWnd As IntPtr,
    ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr)
    As IntPtr
    End Function


    ....
    ''this is how I select the combobox
    iCountryCbo = SendMessage(Par ent_hWnd, CB_FINDSTRING, -1, "United
    States")

    ''try to set focus
    SendNotifyMessa ge(ipCountry, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero)

    SendMessageBySt ring(ipCountry, CB_SETCURSEL, iCountryCbo, 0)

    SendNotifyMessa ge(ipZip, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero)

    I tried moving the setfocus calls around with no luck-
  • Mattias Sjögren

    #2
    Re: P/Invoke Problem selected index changing

    >''try to set focus
    >SendNotifyMess age(ipCountry, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero)
    >
    >SendMessageByS tring(ipCountry , CB_SETCURSEL, iCountryCbo, 0)
    >
    >SendNotifyMess age(ipZip, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero)
    >
    >I tried moving the setfocus calls around with no luck-

    Have you also tried sending WM_KILLFOCUS to the window that you "tab
    out from"?


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...