Archived

This topic is now archived and is closed to further replies.

Making one field affect another (Win32)

This topic is 5045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve looked all over the place and can''t really find any good info/tutes on this. What I have is two radio buttons and another text field (which is grayed out by default). Once one of the radio buttons is selected, I need the text field to become available to accept input. How would I go about doing that? I''m using MSC++ 6 if that helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I assume you''re just doing plain win32 code? Just intercept the WM_COMMAND message (like you''d do for any button) then check for the button''s ID (as per normal again), then you get the button''s state with IsDlgButtonChecked(), then (IIRC) you can use the WM_ENABLE message to enable/disable the text boxes (can anyone else confirm the use of WM_ENABLE + wParam = true for enabled, false for disabled):

int wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_MY_RADIO_BUTTON: {
bool checked = IsDlgButtonChecked(hWnd, IDC_MY_RADIO_BUTTON) == BST_CHECKED;
SendDlgItemMessage(hWnd, IDC_MY_RADIO_BUTTON, WM_ENABLE, checked, 0);
} break;
// other stuff

}
}

Share this post


Link to post
Share on other sites
I assume I have to replace the IDC_MYRADIOBUTTON handle with my text field handle in the SendDlgItemMessage function? (assuming that was an error in the first place)

Either way, it didn''t work for some reason. I also found out about the EnableWindow() function (supposedly I can just typecast HWND onto my textfield) but that isnt working either.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yep - sorry the sendmessage should have been to the text field - it''s a bit of a pain enabling the windows as far as I remember. I think I''ve had some millage using getting the style bits with lStyleBits = GetWindowLong(hWnd, GWL_STYLE), clearing or setting the WS_DISABLED bit then using SetWindowLong(hWnd, GWL_STYLE, lStyleBits);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
...where obviously hwnd is the handle of the thing to enable/disable

Share this post


Link to post
Share on other sites