win 32 Resources and programming

Started by
4 comments, last by uavfun 19 years, 6 months ago
i went and created a new dialog in viscpp6 then i started to add edit box controls to it is there a way to update these 3 edit boxed with random nubers i have tried but i am not sure i am passing all the parameters correctly i keep getting this error //////////////////////////////////////////////// error C2664: 'SetWindowTextA' : cannot convert parameter 1 from 'const int' to 'struct HWND__ *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast ////////////////////////////////////////////////

SetDlgItemInt(IDD_MAIN,IDC_EDIT1,1,true);
	SetWindowText(IDC_EDIT1,"1");
[Edited by - ostamo1 on September 21, 2004 11:38:30 AM]
Advertisement
Use SetDlgItemText() or SetDlgItemInt()

SetDlgItemText(hwndDialog, IDC_EDIT1, "1");
SetDlgItemInt(hwndDialog, IDC_EDIT1, rand(), FALSE);

Also you should be passing an HWND as the 1st param of SetDlgItemInt, it looks like you just have a resource identifier.
thanks man that helped alot

your rating++

/////////////////////////////////////////////////////////

now i need extra help on these edit boxes
my resource file
i only want edit box 1-6 to change but my loop changes them all
even the button caption
have i missed something???


///////////////////////////////////////////////////
#define IDC_EDIT1 1000
#define IDC_EDIT2 1001
#define IDC_EDIT3 1002
#define IDC_EDIT4 1003
#define IDC_EDIT5 1004
#define IDC_EDIT6 1005
///////////////////////////////////////////////////
#define IDC_STRMOD 1007
#define IDC_DEXMOD 1008
#define IDC_CONMOD 1009
#define IDC_INTMOD 1010
#define IDC_WISMOD 1011
#define IDC_CHARMOD 1012
///////////////////////////////////////////////////
#define IDC_ROLL 1006
[/code}


my loop to edit the resources


case IDC_ROLL:
{
// SetDlgItemText(hWndDlg, IDC_EDIT1, "1");
int IDNUM =IDC_EDIT1;
// 1007;
int IDNUMMAX =IDC_EDIT6;
// 1012;

int randnum;
for (int x = 0; x < IDNUMMAX; x++)
{
randnum = 3* (rand()%6 + 1);
SetDlgItemInt(hWndDlg, IDNUM, randnum, FALSE);
++IDNUM;
}
}
break;
[/code}

[Edited by - ostamo1 on September 21, 2004 11:43:03 AM]
You've got too many unnecessary variables there changing all sorts of ways, you've just confused yourself. Try:

for (int x = IDC_EDIT1; x <= IDC_EDIT6; x++){  randnum = 3* (rand()%6 + 1);  SetDlgItemInt(hWndDlg, x, randnum, FALSE);}


Also, don't use ALL CAPS for variable names, that is usually reserved for #defines and sometimes constants/enums.
sorry the caps were just for testing

another question
how do i get the value from the edit box and put it in a static
box
but before i put it in that box if it is higher than 6 i want the box to say 2 else it will say one
and i need this to happen for 6 static boxes
i tried this but it onley return 1 not what was in the edit box

int randnum;
int *rndnum = &randnum
for (int x = IDC_EDIT1; x <= IDC_EDIT6; x++)
{
randnum = 3* (rand()%6 + 1);
SetDlgItemInt(hWndDlg, x, randnum, FALSE);
}


GetDlgItemInt(hWndDlg, IDC_EDIT1, rndnum, FALSE);
// GetDlgItemInt(
SetDlgItemInt(hWndDlg, IDC_STRMOD , *rndnum, FALSE);

[\code]
You don't need to pass a pointer to GetDlgItemInt(), just use NULL. If you do pass one it is just filled in with TRUE or FALSE depending on whether the control had a valid number in it. The return value contains the actual translated number.

MSDN is your best friend.

This topic is closed to new replies.

Advertisement