Creating a popup window to get user input.

closed account (2NywAqkS)
I've got an opengl window, that uses winsock, but at the start I'd like a popup window to get the IP from the user. How would I go about doing this?

Thanks,
Rowan.
Use a modal dialog and use standard ip address control.
closed account (2NywAqkS)
I'm finding it hard to find any decent tutorials on modal dialog boxes.
Is it simple? could you please give an example
http://www.codeproject.com/Articles/1651/Tutorial-Modeless-Dialogs-with-MFC
The title is modeless but there's alot of info and comparisons to modal dialogs that I found helpful...
It's not hard, but it takes a lot of jumping around the code at first until u see how it's all connected. Maybe create a side project just to experiment with this ?
Last edited on
That's MFC, if you want clean WINAPI, get ResEdit and create your Dialog with a IP Address Control, and a OK button, then change your Window Message Handler for the appropriate use.
closed account (2NywAqkS)
Thanks, I also found this tool quite helpful; http://www.resedit.net/
That's ResEdit, as I said. ;)
closed account (2NywAqkS)
Sorry to reopen the topic but I'm finding it difficult to get the IP as a char * from the ip address control. I know I have to use IPM_GETADDRESS, but I'm not sure how to use it.
1
2
3
4
5
6
7
8
9
10
11
12
BYTE IP[4] = {0};
DWORD IP_Ext = 0;
SendMessage((IP Control Window Handle),IPM_GETADDRESS,0,(LPARAM)(&IP_Ext));
IP[0] = FIRST_IPADDRESS(IP_Ext);
IP[1] = SECOND_IPADDRESS(IP_Ext);
IP[2] = THIRD_IPADDRESS(IP_Ext);
IP[3] = FOURTH_IPADDRESS(IP_Ext);
// In a 255.128.64.32 input from the window:
// IP[0] = 255
// IP[1] = 128
// IP[2] = 64
// IP[3] = 32 

From: http://msdn.microsoft.com/en-us/library/windows/desktop/bb761378(v=vs.85).aspx
Last edited on
closed account (2NywAqkS)
hmm either I'm not coverting it to a char * correctly or somthing else becuase this just says it's equal to 0 (and I'm not entering 0)

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
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_INITDIALOG:
		return TRUE;

	case WM_COMMAND:
		switch(wParam)
		{
		case IDOK:
			{
				BYTE IP[4] = {0};
				DWORD IP_Ext = 0;
				SendMessage(hWndDlg,IPM_GETADDRESS,0,(LPARAM)(&IP_Ext));
				IP[0] = FIRST_IPADDRESS(IP_Ext);
				IP[1] = SECOND_IPADDRESS(IP_Ext);
				IP[2] = THIRD_IPADDRESS(IP_Ext);
				IP[3] = FOURTH_IPADDRESS(IP_Ext);
				char buf[100];
				sprintf(buf, "%d", IP_Ext);
				MessageBox(hWnd,buf,"IP", MB_OK);
				EndDialog(hWndDlg, 0);
			return TRUE;
		}
		break;
		}
	}

	return FALSE;
}
Last edited on
Ho, you should use it like:
sprintf(buf, "%d.%d.%d.%d",(int)IP[0],(int)IP[1],(int)IP[2],(int)IP[3]);
And for safety reasons, use snprintf like:
snprintf(buf,100,......)

And if it says it's 0... IDK, are you sure you're entering all parameters? Also try checking if SendMessage returns 4.
Last edited on
If have trouble using the ip control, then you could use a regular edit control, but you need to do the validation yourself in that case.
closed account (2NywAqkS)
I decided to go with your plan modoran. Using
SendMessage(hWndDlg,WM_GETTEXT,sizeof(buffer)/sizeof(buffer[0]),reinterpret_cast<LPARAM>(buffer));
apparantly returns "enter server ip" which is the caption on the dialog box. How to I specify to get the text from the edit control?
Oh, you're doing everything wrong!
1
2
3
4
5
6
// With the IP Control:
HWND IP_Control = GetDlgItem(hWndDlg, (ID of your IP Control like IDC_IPCTRL1) );
SendMessage(IP_Control,...);
// With the EditBox Control:
HWND Edit_Control = GetDlgItem(hWndDlg, (ID of your EditBox Control like IDC_EDIT1) );
SendMessage(Edit_Control,...);

You see, you're trying to get the IP address from your Main Window, and not from the IP Control!
Last edited on
Topic archived. No new replies allowed.