{"id":225,"date":"2009-11-12T23:12:19","date_gmt":"2009-11-12T17:42:19","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=225"},"modified":"2011-04-12T23:12:39","modified_gmt":"2011-04-12T17:42:39","slug":"how-to-change-the-text-of-a-softkey-menu","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/11\/12\/how-to-change-the-text-of-a-softkey-menu\/","title":{"rendered":"How to change the text of a softkey menu?"},"content":{"rendered":"<div style=\"font-family: Comic Sans MS; text-align: justify;\">To change the text of a softkey menu item, all you have to do is pretend that they are buttons. Well, they are specialized buttons in any case. So in order to change its property (in this case the &#8216;text&#8217;) you will have to use the <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa932118.aspx\">TBBUTTONINFO<\/a><\/span> structure along with <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa929014.aspx\">TB_GETBUTTONINFO<\/a><\/span> and <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa920744.aspx\">TB_SETBUTTONINFO<\/a><\/span> messages. Lets dive into the code:<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">Note: Error checking is omitted for obvious reasons.<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; TCHAR szText[128] = TEXT(&quot;&quot;);<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; TBBUTTONINFO tbi;<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; ZeroMemory(&amp;tbi, sizeof(tbi));<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; tbi.cbSize = sizeof(tbi);<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; tbi.dwMask = TBIF_TEXT | TBIF_COMMAND;<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; tbi.pszText = szText;<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; tbi.cchText = sizeof(szText);<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; tbi.idCommand = IDM_MARK_UNMARK;<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; SendMessage(g_hWndMenuBar, TB_GETBUTTONINFO, (WPARAM)IDM_MARK_UNMARK, (LPARAM)&amp;tbi);<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; if (!wcscmp(szText, L&quot;Mark&quot;))<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; wcscpy(szText, L&quot;Unmark&quot;);<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; else<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; wcscpy(szText, L&quot;Mark&quot;);<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<br style=\"color: rgb(0, 0, 128); font-family: Verdana;\" \/><br \/>\n<span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">&nbsp;&nbsp;&nbsp; SendMessage(g_hWndMenuBar, TB_SETBUTTONINFO, (WPARAM)IDM_MARK_UNMARK, (LPARAM)&amp;tbi);<\/span><\/p>\n<div style=\"font-family: Comic Sans MS; text-align: justify;\">So we fill up the <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa932118.aspx\">TBBUTTONINFO<\/a><\/span> structure and then send <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa929014.aspx\">TB_GETBUTTONINFO<\/a><\/span> message to the menu bar. After this call returns, <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">szText<\/span> will contain the text of the menu item. We switch the contents of <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\">szText<\/span> and then send a <span style=\"color: rgb(0, 0, 128); font-family: Verdana;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa920744.aspx\">TB_SETBUTTONINFO<\/a><\/span> message. And the text on the menu item changes.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"font-family: Comic Sans MS; text-align: justify;\">Couple of seasons back I was working on an application which let the user &quot;Mark&quot; and &quot;Unmark&quot; dates on a calendar control. It was for a smartphone, so I thought this technique is quite handy and just qualifies for a post.<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">Here is a video of it in action,<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To change the text of a softkey menu item, all you have to do is pretend that they are buttons. Well, they are specialized buttons in any case. So in order to change its property (in this case the &#8216;text&#8217;) you will have to use the TBBUTTONINFO structure along with TB_GETBUTTONINFO and TB_SETBUTTONINFO messages. Lets &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/11\/12\/how-to-change-the-text-of-a-softkey-menu\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to change the text of a softkey menu?<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-3D","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/225"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/225\/revisions\/226"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}