passing stuff into dialog boxes

This is a discussion on passing stuff into dialog boxes within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have figured out how to pass class objects into dialog boxes, and modify values in them. I haven't ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    6

    passing stuff into dialog boxes

    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!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Code:
    		char temp [MAX_PATH] = {0};//ensure string is null terminated  and has enough space to hold the string and the null terminator
    
    		_snprintf(temp, MAX_PATH-1,"Player %s has won %d times.",pplayer->name1,pplayer->wins);
    
    		SetDlgItemText(dwin, IDC_WINS, temp);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dialog boxes
    By pastitprogram in forum C++ Programming
    Replies: 1
    Last Post: 07-28-2008, 02:13 PM
  2. Dialog Boxes
    By Thantos in forum Windows Programming
    Replies: 7
    Last Post: 08-26-2003, 12:49 PM
  3. passing arguments to dialog boxes?
    By metalhead in forum Windows Programming
    Replies: 3
    Last Post: 11-19-2002, 11:54 AM
  4. Dialog Boxes
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 01-03-2002, 10:13 AM
  5. Windows Dialog Boxes
    By aresashura in forum Windows Programming
    Replies: 1
    Last Post: 12-02-2001, 03:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21