Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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
SetWindowText()
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 3:21am
Rate this: bad
good
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.
 
Regards,
 
— Manfred
  Permalink  
v2
Comments
SajeeshCheviry at 5-Mar-13 0:02am
   
Thanks for your support
Rate this: bad
good
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.
  Permalink  
Comments
SajeeshCheviry at 4-Mar-13 23:40pm
   
Thanks for your support. I have another doubt. Can i use ModifyStyle to avoid such a problem?
ie,
m_button.ModifyStyle(0, DT_NOPRIFIX);
m_button.SetWindowText(csText);
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: http://msdn.microsoft.com/en-us/library/tf9hd91s%28v=vs.80%29.aspx.

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2014
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