Hi,
I have figured out how to pass class objects into dialog boxes, and modify values in them.
I haven't figured out how to extract data from them to display in static text, or how to pass arrays and modify data in them.
Can someone help me?
Anyway here is my successful attempt at passing in a class and modifying it:
Passing it in:
Code:
button = DialogBoxParam(globalHInstance, MAKEINTRESOURCE(IDD_2player), hwnd, DialogMulti, (LPARAM)&player);
Modifying values in it:
Code:
BOOL CALLBACK DialogMulti( HWND dwin, UINT message, WPARAM wParam, LPARAM lParam )
{
static Player *pplayer; // pplayer is pointer to a player object
static Player player; //player is a Player object
switch(message)
{
case WM_INITDIALOG:
pplayer = (Player*)lParam; //retrieve contents of lParam
player = *pplayer; //make player hold contents of pplayer
return TRUE;
case WM_COMMAND:
switch LOWORD(wParam)
{
case IDC_EDITP1:
GetDlgItemText(dwin, IDC_EDITP1, player.name1, PLAYER_MAX_NAME);
break;
......
case IDOK:
*pplayer = player;
EndDialog(dwin, IDOK);
break;
Here is an UNSUCCESSFUL attempt to display contents of player in a static text:
passing in the class:
Code:
button = DialogBoxParam( globalHInstance, MAKEINTRESOURCE(IDD_Stats), hwnd, DialogStats, (LPARAM)&player);
Trying to display info:
Code:
BOOL CALLBACK DialogStats( HWND dwin, UINT message, WPARAM wParam, LPARAM lParam )
{
static Player *pplayer; //pplayer is a pointer to a Player object
static Player player; //make a new Player object called player
switch(message)
{
case WM_INITDIALOG:
pplayer = (Player*)lParam;
player = *pplayer;
char temp1 [10];
char temp2 [10];
char temp3 [10];
itoa(player.wins, temp1, 10);
strcat(temp1, " times.");
//SetDlgItemText(dwin, IDC_WINS, temp1);
SetDlgItemText(dwin, 1038, temp1);
An UNSUCCESSFUL attempt to pass in an array and modify its values:
passing it in:
Code:
button = DialogBoxParam(globalHInstance, MAKEINTRESOURCE(IDD_Settings), hwnd, DialogSettings, (LPARAM)&gametype[0]);
Code:
BOOL CALLBACK DialogSettings( HWND dwin, UINT message, WPARAM wParam, LPARAM lParam )
{
static int gametype[5];
static int *pointer;
switch(message)
{
case WM_INITDIALOG:
pointer = (int*)lParam;
gametype[0] = *pointer;
return TRUE;
case WM_COMMAND:
switch LOWORD(wParam)
{
case IDC_2players:
gametype[4] = 2;
break;
The above probably looks pretty stupid but I have tried lots of different things none of which worked.
Any help much appreciated :-)
Thanks!