Radio Buttons

Started by Peter House, September 14, 2010, 12:13:44 PM

Previous topic - Next topic

Peter House

I am trying to use Radio Button on a Form and am having no luck checking an Option Button from code.

Two option buttons on the form Option1 and Option2 in OptionGroup0

Using FF_Control_SetOption, I am passing hWnd_FORM1, hWnd_FORM1_Option1, hWnd_FORM1_Option2, hWndFORM1_Option1 in order to check the first option button.  No Worky.

I have tried using the values 1, and 2 for the nIDFirstButton and nIDLastbutton, and 1 for nIDCheckButton values with no luck either.

I read the section in Help on "Working with Option Buttons" and it has about as much information as I already know from VB6.

What am I missing?

Peter House

The FF_Control_SetOption Function Returns 1 indicating success according to the CheckRadioButton documentation here:

http://msdn.microsoft.com/en-us/library/bb761877%28VS.85%29.aspx

Here is the exact syntax and parameters I am using:

FF_Control_SetOption( hWnd_FORM1,       _
                         hWnd_FORM1_Option1,  _
                         hWnd_FORM1_Option2,  _
                         hWnd_FORM1_Option1

Peter House

This code works as expected:

SendMessage hWnd_FORM1_Option1, %BM_SETCHECK, %BST_CHECKED, 0

Cho Sing Kum

This works:

FF_Control_SetOption hWnd_FORM1, IDC_FORM1_Option1, IDC_FORM1_Option2, IDC_FORM1_Option1

Peter House

Cho,  Your code works for me also.

What is the difference between hWnd_Form1_Option1 and IDC_Form1_Option1???

hWnd_Form1_Option1 = 984866
IDC_Form1_Option1 = 1001

hWnd_Form1_Text1 = 788250
IDC_Form1_Text1 = 1008

The IDC numbers certainly look familiar from my days using DDT.

I have been using the hWnd number everywhere else (FF_Control_SetText, FF_Control_GetText, and others) and this is the first time I have run into an issue.  It would seem to me like none of this should be working unless I use the IDC constants instead of the hWnd variables.

Does anyone have a simple explanation.  I am an easy guy - I would be happy with a complicated explanation.  OK - I am an engineer - I would probably prefer the complicated explanation!

Thanks,

Peter


Cho Sing Kum

Hi Peter,

The Microsoft link and FF funtion library show that the identifiers of the Radio buttons are required, not their handles. Therefore, IDC instead of hWnd.

David Kenny

Peter,

I don't have the long answer about why controls have ID's in Windows (as well as handles) and why MS didn't go with just handles for everything.  I'm betting they had their reasons.

Anyway, some API calls expect a handle to the parent of the control as well as control ID.  Others just want the handle to the control. It's all in the API documentation. And, each way uniquely identifies the control in Windows.

Handles are assigned by Windows at run-time (when the window/control is created). ID's are assigned by the programmer (in Powerbasic anyway) at design time.  FF takes care of this tedious task of managing ID's for us (in the case of GUI designed controls and forms anyway -you could create a control at design time or run-time using you own specified ID's if you wish). Another thing to note is that ID's can be constants or held in numeric variables (usually defined as DWord or Long).  Typically they would be implemented as constants as you pointed out, but FF makes them available to us in variable form instead.  Again, I am sure Paul had his reasons.

ID's don't have to be unique in Windows. Someone might correct me if I'm wrong, but I think the don't even need to be unique on a given window if the control never needs to be referenced after it is created (most labels for instance).  The combination of the parent-window's handle and the control's ID are sufficient to uniquely reference the control.

Windows gives a unique handle to every control and window in the current session of Windows.  No duplicate handles will exist for any window or control (even resources, like fonts, for instance) at any given time.  It is possible that Windows might reuse one that had been freed earlier however. 

I hope that makes sense,

David

Peter House

David and Cho,

Your answers make sense and are backed up by the documentation and by the code in FF's CODEGEN...DECLARES.inc and other files.

I will now go back and look at the function prototypes for ALL FF_* functions in my code to make sure I use the correct windows handle or identifier.