Help on Radio Buttons

Help on Radio Buttons

The help on Radio Buttons says the following -
"Caption - The text that labels the control. To make one of the letters in the caption of a control the mnemonic key, precede it with an ampersand (&)."

I have added the "&" to the captions and they are displayed correctly but how do I get them to work?
It is a WinApi program.



6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You don't have to do anything to get them work. DefDlgProc
handles Alt+key correctly if the control is in a dialog (and the
mnemonic letter is not duplicated).

If the control is not in a dialog, but in a child window, well, I don't
know the way (except the brute-force approach: process
WM_KEYDOWN, use EnumChildWindows and then compare
names of child-controls with the Alt+key pressed)
though I tried hard.


I'm not using a DefDlgProc, and don't know where to call it - so I'm not sure what to do.

I'm calling a DialogBox procedure then a case (WM_COMMAND) then
select case (loword(wparam) then CASE(IDC_RADIOBUTTON1).

Please could you expand on your help.



I meant, you have to do nothing. DefDlgProc exists,
but, as the documentation says, it should almost never be called
from dialog box procedure. Radio-button title designed
in rc editor such as

"&First option"

shoud be expanded to

First option

and when user presses Alt+F, radio button is activated.
(Granted there is no other control with &F as mnemonic).
I tried it in an Win32-handled dialog (with nothing special
in its DlgProc) and it worked.

Btw (regarding your other post), what do you mean
"shimmering" of the color grid? How do you draw on
the dialog -- directly on dialog's hDC on WM_PAINT
or there is another control where you do the painting?
If the latter, you should use "owner-drawn" style on
that control. Can you post some code? (Please enclose
the code in


HTML tags - replace [] with




Here is the code I'm using. Hope the tags are correct. It's OK if I click on the radio button, but not if I press Alt+A etc. Any ideas what I'm doing wrong?

BTW I will answer the shimmerring question in that message.



	integer*4 function EditProc(hwnd, message, wParam, lParam)  
	!MS$ATTRIBUTES STDCALL, ALIAS : '_EditProc@16' :: EditProc 
	use dfwin 
	use grad_inc 
	include 'resource.fd' 
	integer*4	hwnd, message, wParam, lParam 
	integer*4	iCtrl,iret 
	logical*4	lret 
	! Unreferenced variables 
    lparam = lparam 
    select case (message) 
	case (#0053)			! WM_HELP 
		call help 
		if (wParam) then 
        EditProc = 1 
    case (WM_COMMAND)                       ! message: received a command 
		select case (iCtrl) 
		case (IDC_ADD)						! Add 
			lret = EndDialog(hWnd,1) 
		case (IDC_DELETE)					! Delete 
			lret = EndDialog(hWnd,2) 
		case (IDC_EDIT)						! Edit 
			lret = EndDialog(hWnd,3) 
		case (IDC_INSERT)					! Insert 
			lret = EndDialog(hWnd,4) 
		case (IDC_MOVE)						! Move 
			lret = EndDialog(hWnd,5) 
		case (IDC_MENU)						! Menu 
			lret = EndDialog(hWnd,6) 
		case (IDC_WINDOW)					! Window 
			lret = EndDialog(hWnd,7) 
		case (IDCANCEL)		! System menu close command? 
            lret = EndDialog(hWnd,0) 
            EditProc = 1 
		end select 
	case default 
	end select 
	end function EditProc 

Hi David,

I investigated a bit and you were right - I overlooked
(and, frankly, I didn't know) the possibility that no
control initially has focus. In that case, Alt+Letter
for some reason fails. I don't know why -- ask MS, but
the fix is simple:

   case (WM_INITDIALOG) 

As you designed the dialog, setting the focus to
a radio button (IDCANCEL is a push button in my
example) would cause a WM_COMMAND to be generated,
since radio buttons by default set their state to
"on". That would cause the dialog to close immediately
with return value equal to the one corresponding
with the focused radio button. I guess that you choose
radio buttons just because of that feature. But then,
it looks that you have to have at least one non-radio-button
control in the dialog to have focus initially.


Leave a Comment

Please sign in to add a comment. Not a member? Join today