Click here to Skip to main content
12,996,261 members (66,536 online)
Rate this:
Please Sign up or sign in to vote.
See more:
In my VC++ project i got an issue like this. ie, there is an edit box which accepts string input from user. while pressing another button, this string will be set on a Button. to set this text on this button iam using
API. But the issue was when user enter the input like this
"&abcd" then "&" will not be set on button. It will make "a" as hot key. ie,
now the text will be displayed on button like this "abcd". How can i avoid default hot key conversion of windows API? Is this possible? If yes give me a reply.
Posted 4-Mar-13 2:21am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have two options to avoid having the ampersand generate a hot key:
1. Remove all ampersands from the string: &button -> button
2. Make sure that single ampersand instances inside the string are doubled: &button -> &&button
   The first ampersand escapes the second one and only one ampersand is displayed.


— Manfred
SajeeshCheviry 5-Mar-13 0:02am
Thanks for your support
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Besides the options mentioned by Manfred in solution 1, there is a third one:
When using owner draw buttons (see the MSDN example at CButton::DrawItem()[^]), the DrawText() format flag DT_NOPREFIX will disable processing of prefix characters and show the text as it is.
SajeeshCheviry 4-Mar-13 23:40pm
Thanks for your support. I have another doubt. Can i use ModifyStyle to avoid such a problem?
m_button.ModifyStyle(0, DT_NOPRIFIX);
Jochen Arndt 5-Mar-13 2:57am
No. DT_NOPREFIX is a format flag for DrawText() and not a button style. The value is 0x800. When setting this for a button style, the text will be drawn at the bottom of the button (style BS_BOTTOM). See button styles in the MSDN:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170609.2 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100