P/Invoke Problem selected index changing


J

jr

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 SendMessageByString Lib "user32.dll" Alias
"SendMessageA" _
(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
"SendMessageA" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As String) As Integer

''set focus -
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SendNotifyMessage(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(Parent_hWnd, CB_FINDSTRING, -1, "United
States")

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

SendMessageByString(ipCountry, CB_SETCURSEL, iCountryCbo, 0)

SendNotifyMessage(ipZip, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero)

I tried moving the setfocus calls around with no luck-
 
Ad

Advertisements

M

Mattias Sjögren

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

SendMessageByString(ipCountry, CB_SETCURSEL, iCountryCbo, 0)

SendNotifyMessage(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top