473,666 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using api sendmessage in .net

2 New Member
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 2656
tommyk
2 New Member
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
19400
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 = Win32API.SendMessage(hWndYesButton,Win32API.BM_SETSTATE,0,null); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,"11"); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,null); response =...
4
2354
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 is FFFFFFFF. I don't think SendMessage is working correctly to find the text. Can somebody help me out here with the parameters that need to be passed and if I am passing them correctly. How do i specify the pointer to string member in the...
3
17046
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 is a multi-column list view). I am using the PARTIAL flag to try to find an item starting with a certain letter, that i am setting on the LVFINDINFO.psz. I am always being returned -1 (or 0) as the index and am not quite sure what i am
4
5925
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. How do I do this?
3
5329
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 at it and let me know what I need to change. I have tried changing the "hwnd" type into intptr's but there seem to be other problems too, like it won't allow "lParam As Any" to be declared.
4
2128
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 by protecting it in a critical section, or the SendMessage api itself handles this kind of situation where a lot of threads in the same process r calling it. Regards,
2
12524
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
13406
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 Attachmate. It is a mainframe terminal. Here is the issue and strange part of it. It is accepting sendmessage when I use the WM_KEYDOWN/UP commands. However, when I use WM_SETTEXT to send my string it is not imputing the string to the session...
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

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.