Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C++
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

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.
 
Share this answer
 
Comments
SajeeshCheviry 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 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.
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
 
Share this answer
 
v2
Comments
SajeeshCheviry 5-Mar-13 0:02am    
Thanks for your support

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900