Gather information from a dialog box

Can someone point me to a tutorial that explains, or show me, how to get the contents of an edit box I've created inside of a dialog box which is defined in a resource file? I'd also like to change the text of a static made the same way.

I know how to get it if I hard code the edit box in the window, but resource editors offer so may advantages over code I was hoping I could use them similarily.
I had been googling about, and I'm sure its out there, I just couldn't figure out the keywords to find relevant information. I'll keep searching about, though.
I think Zaita wanted to tell you that the question wasn't well frased.

How is your GUI made, are you using the Windows API?
Fair enough.
I am using Windows API.
My GUI is created simply with DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MM), hWnd, MenuProc);
I've used a resource file to make my window.
Thing is I have an IP Address box in it and I'm trying to get the user's input from that IP box when they click a certain button. I know how to tell when they've clicked, just not how to get the data. I've looked up CIPAddressCtrl in my travels and I have put together this code now (this is after I asked or I would have included it):

CIPAddressCtrl *IPConnect;
IPConnect = reinterpret_cast<CIPAddressCtrl *>(GetDlgItem(IDC_IPA_IP));
IPConnect->SetAddress("127,0,0,1");

unfortunately to use this I need to #include <afxcmn.h> but dev-c++ is throwing an error that the file doesn't exist...
I think you should google for that library
If you using native win32 API. Then if memory serves me right, you'd use a SendMessage() API call to the dialogbox passing a pointer to a buffer to be filled. :)
I know how to do that if the GUI components are hard coded because I have their window handles, but how would I get a window handle of a control I created in a resource file?
Doesn't the DialogBox call return a handle to it?
If you change the DialogBox function with the CreateDialog one, that will return the handle used
I believe it returns the intresource to whatever was clicked on the dialog box, but I want to gather information from something that was never clicked, and I don't know how to get a handle from an intresource...

if I try to use
HWND test = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MM), hWnd, MenuProc);
I get the message:
invalid conversion from `int' to `HWND__*'
MSDN is useful for Win API functions:
DialogBox documentation: http://msdn.microsoft.com/en-us/library/ms645452(VS.85).aspx
CreateDialog documentation: http://msdn.microsoft.com/en-us/library/ms645434(VS.85).aspx
Working with CreateDialog, and now reading the link you've posted, its returning the handle to the dialog box, that doesn't let me get or change data in the IP edit box inside that dialog box...
I think its time to show the whole cpp file here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <RakNetworkFactory.h>
#include <RakClientInterface.h>
#include <bitstream.h>
#include <windows.h>
#include <commctrl.h>

#include "resource.h" 

RakClientInterface *client;
Packet * packet = NULL;
const unsigned char PACKET_ID_LOGIN = 100;
const unsigned char PACKET_ID_LOGINRESPONSE = 101;
const unsigned char PACKET_ID_LOGOUT = 102;
HWND hWnd;
bool loggedin = false;
bool connected = false;
bool lastconnected = false;
DWORD lasttime = 0;

void HandlePacket(RakClientInterface * client, Packet * p)
{
    unsigned char packetID;
    
    BitStream dataStream((const char*)p->data, p->length, false);
    
    dataStream.Read(packetID);
    
    switch(packetID) {
    case PACKET_ID_LOGINRESPONSE:
        dataStream.Read(loggedin);
        if(!loggedin)
           MessageBox(hWnd, "Incorrect Username/Password combination.", "Login Error", 0);
    break;
    }
}

BOOL CALLBACK MenuProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch(Message)
	{
		case WM_INITDIALOG:
	       break;
		return TRUE;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
               case IDC_BTN_CONNECT:
 		       {
                  /*char IP[15] = {0};
                  client->Connect(IP, 2500, 0, 0, 0);
                  if(!client->IsConnected())
                   ;*/
                break;
				}
 		       case IDC_BTN_QUIT:
 		          PostQuitMessage(0);
			}
		break;
		case WM_DESTROY:
             PostQuitMessage(0);
		break;
	    case WM_CLOSE:
             PostQuitMessage(0);
		break;
		default:
			return FALSE;
	}
	return TRUE;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
 	MSG messages; 
 	WPARAM wParam;
    InitCommonControls();
    
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MM), hWnd, MenuProc);
    return messages.wParam;
    
}


on case WM_INITDIALOG: I'd like to set the default value of IDC_IPA_IP.
on case IDC_BTN_CONNECT: I'd like to get the current value of IDC_IPA_IP.

Maybe there is a way I can get the handle of the control using the resource number?
Okay I've discovered the functions I needed are GetDlgItemText and SetDlgItemText. I'm pretty new to this WinAPI stuff so that was probably a simpler answer than you were expecting.

Thanks for the help guys, you certainly pointed me in the right directions!
SendMessage would've worked also :)
I believe it would, because I have used it when I created the windows with C++ instead of the resource file, I just don't know how to get their handles when I didn't create them in C++. I'm sure there is a way to do that, too, though.
Last edited on
Topic archived. No new replies allowed.