Solved

Windows Messages

Posted on 1998-04-22
9
390 Views
Last Modified: 2013-12-03
I'm having nothing but bad luck from Windows Messages.  Specifically, I am trying to add items to a combo box.  Here is the line I am using to add the item:

long err = SendMessage(hWnd, CB_ADDSTRING, MAKEWPARAM(0, IDC_COMBO), (LPARAM)Item);

I immediatly call GetLastError after this line, and get a value of 0x58d (Control ID not found.)  I have specified the Control ID in the Hiword of the wParam, so I don't understand why I get this error.  And yes, I did specify the same control ID when creating the window.  I have also tried the line like this:

long err = SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)Item);

and get the same result.
0
Comment
Question by:dirtdart
  • 4
  • 4
9 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 1334375
You need hWnd to be the HWND of the combo control itself

Note that the CB_ADDSTRING docco says

CB_ADDSTRING
wParam = 0;                         // not used; must be zero
lParam = (LPARAM) (LPCTSTR) lpsz;    // address of string to add
 
Also, I would use ComboBox_AddString or ComboBox_AddItemData instead (it is a little nice to code that way)

0
 
LVL 11

Expert Comment

by:alexo
ID: 1334376
#include <windowsx.h> to do what Roger suggested.
0
 
LVL 5

Author Comment

by:dirtdart
ID: 1334377
I'm going to go ahead and grade your answer because you put forth the effort to answer.  However, that wasn't the problem.  hWnd is the hWnd of the control.  I realized the problem right after I left work.  I had created the control with the wrong control class specified (that's what happens sometimes when you cut and paste code).  If I change it to the correct class, I believe it will work as it should.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1334378
Well, at least you've got it fixed.  And you know that you don't need to include the control id in the message.  And you know that you can use ComboBox_AddItemData or AddString instead to make your code look neater (it worries about the SendMessage syntax for you).

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Author Comment

by:dirtdart
ID: 1334379
Actually, I'm creating an AddString method for my combobox.  I'm trying to stay completly away from MFC, because i hate using it.  But it only makes sense to wrap objects you are going to use more than once (combobox, textbox, etc).  I had figured that the control ID didn't need to be included in the SendMessage, but since it had said Control ID not found, I thought I'd give it a shot like that.  It wouldn't be the first time an API was obscure.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1334380
ComboBox_AddString is NOTHING to do with MFC .. it is part of the API - its is implemented as a Macro in <windowsx.h>.

Most standard SendMessage calls have API macro wrappers that make them easier to call.  That way you don't need to remember what lparam and wparam etc to use .. the macro builds them approriately for each message.

If there is such a macro for a particular message, then it is ALWAYS best to use the macro instead of the direct SendMessage because:
* you are less likely to make mistakes
* your code will still work even if the way a particular message is send is altered in a later version of Win32
* it is much easier to read.


0
 
LVL 5

Author Comment

by:dirtdart
ID: 1334381
Ok.  I'll buy that.  Any chance you can tell me what the macro is to change the height of the stupid thing?  According to my error messages, everything worked beautifully, but I wouldn't know, because when I drop it down, it's only about one pixel high. AAARRRRGGGGGGGG!!!!!
0
 
LVL 5

Author Comment

by:dirtdart
ID: 1334382
Never mind.  Just found it.  Duh!

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1334383
Are you using the dialog resource editor in VC?

If so, click on the drop down arrow of the combo box from within the editor. That will show you the size of the dropdown part.  Drag it to the deried size.

You can change the size (I think) with message, but getting it right in the dialog template is better.

Is this another question?  If so, then you might be better off posting another question (with whatever points you feel is suitable) so that other experts can get a look in, people looking at the PAQ can find this answer, and (coincidentally) I can get a couple more points :-)


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Winform not working on 64 bit machine 31 97
SAPE.heur.AE935 Visual Studio 3 36
What .NET website keeps me current? 9 56
Please explain "Multi-Tenant Services" 5 62
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now