Solved

Windows Messages

Posted on 1998-04-22
9
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Query (QBE) Using VBA Function for Criteria 13 67
What is Runtime?  What is Middleware?  Azure stack 1 534
Windows Installer 4 76
Problem to file 3 92
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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