setting up controls in a dialog.

M

maddog

Sorry, bit of a noob question.

But if I bind a var to a radio control, then set that var just before
calling DoModal the control does not reflect the vars value. So I put a
UpdateData(0) in the OnInitDialog func, no joy. So I added.........

HWND hWndCtrl;
GetDlgItem(IDC_RADIO1, &hWndCtrl);
::SendMessage(hWndCtrl, BM_SETCHECK, (WPARAM)test_var, 0L);

and this works!

As far as I can see, that is what UpdateData(0) is doing, via DoDataExchange
and
DDX_Check(pDX,IDC_RADIO1,test_var)

Odd and i'm confused.


I've come up against this many times and in the past ended up adding MFX
contol object to do it, but i've decieded to once and for all find a way to
do it with out adding loads of CButton radio_button.... vars just to init
the control. If UpdateData(0) worked as I had expected I would have been a
happy chappy. :)
 
M

maddog

Sorry, ignore that question. Just found a very very very silly bug/typo on
my part. Doh!. Works fine now. :)
 
G

Guest

I do not use MFC but I understand your problem. DoModul is a macro for

DialogBox(Instance,MAKEINTRESOURCE(IDD_RESOURCE),hwnd, DialogProc)

DialogBox() creates the dialog box and then calls CALLBACK DialogProc() whic
is a kind of do{}while until the dialog box loses focus or is close

BOOL CALLBACK DialogProc (HWND, UINT message, WPARAM wParam, LPARAM lParam

HWND hwnd

switch (message


case WM_INITDIALOG: //here is where and when variables are initialize
//eg. Title the dialog box and check a butto
/
SendMessage(hdlg,WM_SETTEXT,0,(LPARAM) "Dialog Box")
hwnd = GetDlgItem(hdlg,IDC_BUTTON)
SendMessage(hwnd,BM_SETCHECK,BST_CHECKED,0)

break

case WM_COMMAND://here is when and where variables and data exchange
/
switch (wParam

case IDOK: //and here is the en
/
case IDCANCEL: EndDialog()
return(TRUE)


return(FALSE)


//DoModul displays your resource as you made it. Changes you wan
//to make to variables etc. in the Dialog Box are done after DoModul(
//in the CALLBACK procedure. Simply put, DoModul()does all the stati
//graphics and CALLBACK procedure does all the work with variables
//It is in the WM_INITDIALOG where you check buttons and things t
//get started
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top