variables won't change !
On running debug I found out that some variables weren't changing when explicitly asked to, i.e. int a = 5. They are inside a dialog box function.
gametype is a global variable (since I never figured out how to pass an array into a dialog box - if any one knows how to do that I'd be glad to hear it!) and dummy is a local one. Neither dummy = something nor gametype = dummy work. gametype stays as what it was before and dummy stays as a random huge negative number.
So what's happening?
On a related note, some child window buttons work fine until this dialog is called, then they won't work anymore (they look enabled, but can't be clicked). Does anyone know why that might happen?
Anyway, here is the code for the dialog box function:
If anyone has an idea of why the buttons might not work I will post the code of WM_COMMAND where the buttons are processed and the dialog is called.
BOOL CALLBACK DialogSettings( HWND dwin, UINT message, WPARAM wParam, LPARAM lParam )
//make dummy variable(for if user changes their mind about settings)
int a, b, c, d, e;
//set initial checks
if(gametype == TAKELASTLOSE) radioID = IDC_TAKELASTLOSE;
if(gametype == TAKELASTWIN) radioID = IDC_TAKELASTWIN;
CheckRadioButton(dwin, IDC_TAKELASTLOSE, IDC_TAKELASTWIN, radioID);
if(gametype == TAKE2) radioID = IDC_Take2;
if(gametype == TAKE3) radioID = IDC_Take3;
if(gametype == TAKE4) radioID = IDC_Take4;
if(gametype == TAKE5) radioID = IDC_Take5;
CheckRadioButton(dwin, IDC_Take2, IDC_Take5, radioID);
if(gametype == YOU) radioID = IDC_Pfirst;
if(gametype == COMP) radioID = IDC_Compfirst;
if(gametype == RAND) radioID = IDC_Comprand;
CheckRadioButton(dwin, IDC_Pfirst, IDC_Comprand, radioID);
if(gametype == P1) radioID = IDC_P1first;
if(gametype == P2) radioID = IDC_P2first;
if(gametype == P3) radioID = IDC_P3first;
if(gametype == P4) radioID = IDC_P4first;
if(gametype == P5) radioID = IDC_P5first;
if(gametype == RAND) radioID = IDC_Multirand;
CheckRadioButton(dwin, IDC_P1first, IDC_Multirand, radioID);
if(gametype == 2) radioID = IDC_2players;
if(gametype == 3) radioID = IDC_3players;
if(gametype == 4) radioID = IDC_4players;
if(gametype == 5) radioID = IDC_5players;
CheckRadioButton(dwin, IDC_2players, IDC_5players, radioID);
//dummy = 2;
e = 2;
//dummy = 3;
e = 3;
//dummy = 4;
e = 4;
//dummy = 5;
e = 4;
//dummy = TAKELASTWIN;
a = TAKELASTWIN;
//dummy = TAKELASTLOSE;
a = TAKELASTLOSE;
//dummy = YOU;
c = YOU;
//dummy = COMP;
c = COMP;
//dummy = RAND;
c = RAND;
//dummy = P1;
d = P1;
//dummy = P2;
d = P2;
//dummy = P3;
d = P3;
//dummy = P4;
d = P4;
//dummy = P5;
d = P5;
//dummy = RAND;
d = RAND;
//dummy = TAKE2;
b = TAKE2;
//dummy = TAKE3;
b = TAKE3;
//dummy = TAKE4;
b = TAKE4;
//dummy = TAKE5;
b = TAKE5;
gametype = a;
gametype = b;
gametype = c;
gametype = d;
gametype = e;
Thanks heaps in advance, it is puzzling me incredibly!!
On the matter of passing an array into a dialog box... use DialogBoxParam and set the LPARAM value to point at your struct or array. You will need to typecast it as (LPARAM) &ARRAY to get it in there, then inside the dialog in WM_INITDIALOG convert it back to a pointer and store it as a page-global variable... PARRAY = (ARRAY*) LPARAM
Your issue is 'scope' of your variables (how long and which sections of code they exist in).
Callbacks process all the msgs, each as a seperate event. Each msg creates a 'new' copy of the callback function (and cleans it up when it finishes).
When the callback gets a WM_INIT msg the variables get a value random value (because you did not initialise them).
You use the variable and assign a new value.
When the WM_INIT msg finishes the variables (and any new value) go out of scope (are freed/deleted).
When the callback gets a WM_COMMAND msg the variables again get a random value.
Your comparison fails as the old value has been lost.
The solution is to use 'static' variables for any that you want to retain their value for the life of the app (rather than the life of the msg).