Software Archive
Read-only legacy content
17061 Discussions

Help on Radio Buttons

davidgraham
Beginner
580 Views
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.

Thanks,

David
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
580 Views
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.

Jugoslav
0 Kudos
davidgraham
Beginner
580 Views
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.

Thanks,

David
0 Kudos
Jugoslav_Dujic
Valued Contributor II
580 Views
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
 and 
HTML tags - replace [] with
<>).

Regards

Jugoslav
0 Kudos
davidgraham
Beginner
580 Views
Jugoslav,

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.

Thanks,

David

 
	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 
 
	case (WM_SHOWWINDOW) 
		if (wParam) then 
			iret=ShowCursor(.TRUE.) 
		endif 
        EditProc = 1 
        return 
		 
    case (WM_COMMAND)                       ! message: received a command 
		iCtrl=LoWord(wParam) 
		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 
		EditProc=0 
	end select 
     
	return 
 
	end function EditProc 
0 Kudos
Jugoslav_Dujic
Valued Contributor II
580 Views
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) 
      iret=SetFocus(GetDlgItem(hWnd,IDCANCEL)) 
      EditProc=1 


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.

Regards
Jugoslav
0 Kudos
Reply