PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How to send a CBN_SELCHANGE message when using CB_SETCURSEL?

 July 12, 2022     c++, combobox, controls, message, winapi     No comments   

Issue

When using the CB_SETCURSEL message, the CBN_SELCHANGE message is not sent.

How to notify a control that the selection was changed ?

P.S.

I found on the Sexchange site, a very ugly hack :

SendMessage( hwnd, 0x014F/*CB_SHOWDROPDOWN*/, 1, 0 );
SendMessage( hwnd, 0x014E/*CB_SETCURSEL*/, ItemIndex, 0 );
SendMessage( hwnd, 0x0201/*WM_LBUTTONDOWN*/, 0, -1 );
SendMessage( hwnd, 0x0202/*WM_LBUTTONUP*/, 0, -1 );

Will do for now... Not really.

P.S.2

For resolving my problem, I'll follow Ken's suggestion in the comments.


Solution

You're not supposed to use CBN_SELCHANGE unless the change in selection was made by the user.

You don't indicate what language you're using; it would make it easier to provide you with a workaround if you did so.

In Delphi, where an OnChange() would be associated with the combobox, you just call the event method directly:

// Send the CB_SETCURSEL message to the combobox
PostMessage(ComboBox1.Handle, CB_SETCURSEL, Whatever, WhateverElse);

// Directly call the OnChange() handler, which is the equivalent to CBN_SELCHANGE
ComboBox1Change(nil);


Answered By - Ken White
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing