hi, i'm in need of some assistance getting some dialog boxes to bloody work properly. I've never done dialog boxes before, and i now know why i avoided them :\ . When my main window is first created, I want a dialog box to pop asking for some information from the user. Then, when they press the "Connect" button on the dialog box, i wish for it to close, and for my program to go about it's business. So i have this in my WM_CREATE: of my main windowproc:
int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), hwnd, DlgProc);
which works fine, the dialog opens when i start the program, and lets the person fill in the two fields, an ip control for a server ip, and an edit control for a screenname. This is the dialogwindowproc, which i'm sure is where everything goes fubar:
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
return TRUE;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
{
DWORD ipAddress = 0;
char * TempIp;
struct in_addr addr;
SendDlgItemMessage(hwnd, IDC_IPADDRESS1, IPM_GETADDRESS, 0, (lParam) &ipAddress);
addr.s_addr = (long)ipAddress;
TempIp = inet_ntoa(addr);
strcpy_s(ServerIp, TempIp);
GetDlgItemText(hwnd, IDC_EDIT1, username, 100);
SendMessage(mainWindow, WM_START_WINSOCK, 0, 0);
EndDialog(hwnd, IDOK);
return true;
}
}
break;
}
default:
return FALSE;
}
return TRUE;
}
So what i thought i was doing was, when the button with the dialog ID IDC_BUTTON1 was pressed, it would first grab the ip address in the form of DWORD via the IPM_GETADDRESS message, which i then convert to a char string and then store in a global variable 'ServerIp'. I then grab the entered username via the GetDlgItemText function and store it in the global TCHAR string, 'username'. I then send a user-defined message, which is handled by my main WinProc, but i'm not worried about that cause it doesn't get any farther. I thought the end dialog function was supposed to close the dialog box entirely, but it just stays open, and the rest of my main window pops up behind it, which i can't click on because the dialog box is still up. Then, when i try and click the Connect button again to close it, i get an "Unhandeled exception" / "Access Violation" error from MSVC++ express and my program crashes. so yeh, I'm doing this wrong. Can someone help me out?