473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using api sendmessage in .net

2
Hi

I am using the following code to search for a given string in either a listbox or a combo box, but the function always returns the index as "-1". The function fires from the change event of a textbox.

This is a program that I am converting from vb6.0, so I think that there may have been a problem in translation. There were two upgrade warnings, which I have left in in code, as they may be the root of the problem!

SendMessage Declaration:
Expand|Select|Wrap|Line Numbers
  1.     Public Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As String) As Integer
  2.     Public Const CB_FINDSTRING As Short = &H14Cs
  3.     Public Const CB_FINDSTRINGEXACT As Short = &H158s
  4.     Public Const LB_FINDSTRING As Short = &H18Fs
  5.     Public Const LB_FINDSTRINGEXACT As Short = &H1A2s
Function Call:
Expand|Select|Wrap|Line Numbers
  1. Index = FindFirstMatch(lstProductCode, txtProductCode.Text, -1, False)
Function:
Expand|Select|Wrap|Line Numbers
  1. Public Function FindFirstMatch(ByVal ctlSearch As System.Windows.Forms.Control, ByVal SearchString As String, ByVal FirstRow As Short, ByVal Exact As Boolean) As Short
  2.  
  3.         Dim Index As Integer
  4.  
  5.         'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
  6.         If TypeOf ctlSearch Is System.Windows.Forms.ComboBox Then
  7.             If Exact Then
  8.                 Index = SendMessage(ctlSearch.Handle.ToInt32, CB_FINDSTRINGEXACT, FirstRow, SearchString)
  9.             Else
  10.                 Index = SendMessage(ctlSearch.Handle.ToInt32, CB_FINDSTRING, FirstRow, SearchString)
  11.             End If
  12.             'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
  13.         ElseIf TypeOf ctlSearch Is System.Windows.Forms.ListBox Then
  14.             If Exact Then
  15.                 Index = SendMessage(ctlSearch.Handle.ToInt32, LB_FINDSTRINGEXACT, FirstRow, SearchString)
  16.             Else
  17.                 Index = SendMessage(ctlSearch.Handle.ToInt32, LB_FINDSTRING, FirstRow, SearchString)
  18.             End If
  19.         End If
  20.  
  21.         FindFirstMatch = Index
  22.  
  23.         If Index <> -1 Then
  24.             Call frmMain.Populate_Screen(VB6.GetItemString(frmMain.lstProductCode, Index))
  25.         End If
  26.  
  27.     End Function
Any help will be greatly appriciated!

Many Thanks

Tom
Mar 28 '07 #1
1 2625
tommyk
2
Sorry, I just realised I havent actually asked a question.

Basicly, I would like to know how to fix this code - as it is obviously not working correctly! i need it to return the index number of the closest match in the list box to the search string.

I really need any help you can give me, as I have a deadline to meet!

Many Thanks

Tom
Mar 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
4
by: jbhan | last post by:
Hi, I am trying to find text in a window. I can get the handle to the window but when I try using SendMessage the return value is very large number. When I use Spy++ to see the return value it...
3
by: Dave Rich | last post by:
Hi I am trying to access the listview items from a SysListView32 control in C#. I am using LVM.FINDITEM and LVFINDINFO through SendMessage to try to get the text from each column in the item (it...
4
by: Brian | last post by:
I used SendMessage to get the line count of a multiline textbox, since it recognizes word wrap as a new line (and not only crlf). But with EM_GETLINE it needs a pointer to a buffer for the lparam....
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
4
by: Abubakar | last post by:
Hi, My application has a lot of threads which at some point call SendMessage api passing it the handle of the gui window. The calls r a lot. My question is that should I call the SendMessage api...
2
by: Mayur | last post by:
I tried followinf but working fine fo int but how to do it for string using user custome message in c# public static extern int FindWindow(string strClassName,string strWindowName);
1
by: Necromis | last post by:
Ok, I have gotten my head around things better regarding SendMessage and FindWindow functions. However, I am running into an issue with my code still. The program I am working with is EXTRA! by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.