Click here to Skip to main content
11,806,575 members (67,422 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MFC VisualC++
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 at 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 at 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 at 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
0 ppolymorphe 205
1 OriginalGriff 175
2 Richard Deeming 175
3 Sergey Alexandrovich Kryukov 170
4 Abhinav S 120
0 OriginalGriff 3,380
1 Maciej Los 1,990
2 CPallini 1,915
3 KrunalRohit 1,907
4 ppolymorphe 1,317

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2015
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