|
|
1.1 ! root 1: ! 2: //----------------------------------------------------------------------------- ! 3: // This is a part of the Microsoft Source Code Samples. ! 4: // Copyright (C) 1993 Microsoft Corporation. ! 5: // All rights reserved. ! 6: // ! 7: // This source code is only intended as a supplement to ! 8: // Microsoft Development Tools and/or WinHelp documentation. ! 9: // See these sources for detailed information regarding the ! 10: // Microsoft samples programs. ! 11: //----------------------------------------------------------------------------- ! 12: ! 13: /****************************************************************************\ ! 14: * dialogs.c -- sample program demonstrating Windows Sockets APIs. ! 15: * ! 16: * Handles the dialog boxes for the WSOCK sample. ! 17: * ! 18: ****************************************************************************/ ! 19: ! 20: #include <stdio.h> ! 21: #include <stdlib.h> /* atoi */ ! 22: #include <windows.h> ! 23: #include <winsock.h> ! 24: #include "wsock.h" ! 25: ! 26: extern u_short portno; /* Which tcp port are we going to use? */ ! 27: extern char szBuff[80]; ! 28: ! 29: /**************************************************************************** ! 30: * ! 31: * FUNCTION: GetTcpPort(HWND, UINT, UINT, LONG) ! 32: * ! 33: * PURPOSE: dialog callback procedure. Allows the user to enter the ! 34: * tcp port number, or a service name. ! 35: * ! 36: *\***************************************************************************/ ! 37: ! 38: LRESULT APIENTRY GetTcpPort( ! 39: HWND hDlg, /* window handle of the dialog box */ ! 40: UINT message, /* type of message */ ! 41: UINT wParam, /* message-specific information */ ! 42: LONG lParam) ! 43: { ! 44: ! 45: switch (message) { ! 46: case WM_INITDIALOG: /* message: initialize dialog box */ ! 47: SetFocus( GetDlgItem( hDlg, IDD_EDIT)); ! 48: return (TRUE); ! 49: ! 50: case WM_COMMAND: { /* message: received a command */ ! 51: switch(LOWORD(wParam)) { ! 52: case IDOK: /* "OK" box selected? */ ! 53: { ! 54: GetDlgItemText( hDlg, IDD_EDIT, szBuff, 80); ! 55: if ((portno = atoi(szBuff)) == 0) ! 56: EndDialog( hDlg, 2 ); ! 57: else ! 58: EndDialog( hDlg, 1 ); ! 59: } ! 60: break; ! 61: ! 62: case IDCANCEL: /* System menu close command? */ ! 63: EndDialog(hDlg, 0); /* Exits the dialog box */ ! 64: break; ! 65: ! 66: default: ! 67: return FALSE; ! 68: } ! 69: return (TRUE); ! 70: } ! 71: } /* switch message */ ! 72: ! 73: return (FALSE); /* Didn't process a message */ ! 74: UNREFERENCED_PARAMETER(lParam); ! 75: } ! 76: ! 77: /**************************************************************************** ! 78: * ! 79: * FUNCTION: GetHostName(HWND, UINT, UINT, LONG) ! 80: * ! 81: * PURPOSE: dialog callback procedure. Allows the user to enter the ! 82: * the host name. Used for menu item "Check Host Name" and ! 83: * also for menu item "Connect". ! 84: * ! 85: *\***************************************************************************/ ! 86: ! 87: LRESULT APIENTRY GetHostName( ! 88: HWND hDlg, /* window handle of the dialog box */ ! 89: UINT message, /* type of message */ ! 90: UINT wParam, /* message-specific information */ ! 91: LONG lParam) ! 92: { ! 93: ! 94: switch (message) { ! 95: case WM_INITDIALOG: /* message: initialize dialog box */ ! 96: SetFocus( GetDlgItem( hDlg, IDD_EDIT)); ! 97: return (TRUE); ! 98: case WM_COMMAND: { /* message: received a command */ ! 99: switch(LOWORD(wParam)) { ! 100: case IDOK: /* "OK" box selected? */ ! 101: { ! 102: GetDlgItemText( hDlg, IDD_EDIT, szBuff, 80); ! 103: EndDialog(hDlg, TRUE); /* Exits the dialog box */ ! 104: } ! 105: break; ! 106: case IDCANCEL: /* System menu close command? */ ! 107: EndDialog(hDlg, FALSE); /* Exits the dialog box */ ! 108: break; ! 109: default: ! 110: return FALSE; ! 111: } ! 112: return (TRUE); ! 113: } ! 114: } /* switch message */ ! 115: ! 116: return (FALSE); /* Didn't process a message */ ! 117: UNREFERENCED_PARAMETER(lParam); ! 118: } ! 119: /**************************************************************************** ! 120: * ! 121: * FUNCTION: About(HWND, UINT, UINT, LONG) ! 122: * ! 123: * PURPOSE: dialog callback procedure for "about" box. ! 124: * ! 125: *\***************************************************************************/ ! 126: ! 127: LRESULT APIENTRY About( ! 128: HWND hDlg, /* window handle of the dialog box */ ! 129: UINT message, /* type of message */ ! 130: UINT wParam, /* message-specific information */ ! 131: LONG lParam) ! 132: { ! 133: switch (message) { ! 134: case WM_COMMAND: /* message: received a command */ ! 135: if (LOWORD(wParam) == IDOK /* "OK" box selected? */ ! 136: || LOWORD(wParam) == IDCANCEL) { /* System menu close command? */ ! 137: EndDialog(hDlg, TRUE); /* Exits the dialog box */ ! 138: return (TRUE); /* WM_COMMAND */ ! 139: } ! 140: break; ! 141: } /* End switch message */ ! 142: return (FALSE); /* Didn't process a message */ ! 143: UNREFERENCED_PARAMETER(lParam); ! 144: } ! 145: ! 146: /**************************************************************************** ! 147: * ! 148: * FUNCTION: DisplayHostEnt(HWND, UINT, UINT, LONG) ! 149: * ! 150: * PURPOSE: dialog callback procedure. Displays the information ! 151: * returned by gethostbyname() (HOSTENT structure). ! 152: * ! 153: *\***************************************************************************/ ! 154: ! 155: LRESULT APIENTRY DisplayHostEnt( ! 156: HWND hDlg, /* window handle of the dialog box */ ! 157: UINT message, /* type of message */ ! 158: UINT wParam, /* message-specific information */ ! 159: LONG lParam) ! 160: { ! 161: ! 162: DWORD ret; ! 163: switch (message) { ! 164: /* ! 165: * Initialize dialog box ! 166: */ ! 167: case WM_INITDIALOG: ! 168: { ! 169: int count = 0; ! 170: ! 171: SetWindowText( GetDlgItem( hDlg, IDD_HOSTNAME), (LPCTSTR)phe->h_name); ! 172: ! 173: while (phe->h_aliases[count] != NULL) { ! 174: SendDlgItemMessage(hDlg, IDD_LBALIAS, LB_ADDSTRING, 0, (LPARAM)(phe->h_aliases[count])); ! 175: count++; ! 176: } ! 177: ! 178: count = 0; ! 179: ! 180: /* ! 181: * Enumerate all the hosts IP addresses. ! 182: */ ! 183: while (phe->h_addr_list[count] != NULL) { ! 184: sprintf( szBuff, "%u.%u.%u.%u", ! 185: (unsigned char) phe->h_addr_list[count][0], ! 186: (unsigned char) phe->h_addr_list[count][1], ! 187: (unsigned char) phe->h_addr_list[count][2], ! 188: (unsigned char) phe->h_addr_list[count][3]); ! 189: ! 190: count++; ! 191: ! 192: /* ! 193: * Fill the dialog box.. ! 194: */ ! 195: if ((ret = SendDlgItemMessage(hDlg, IDD_LBADDR, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)szBuff)) == LB_ERR) ! 196: MessageBox(hDlg, szBuff, "Couldn't add address..", MB_OK); ! 197: } ! 198: ! 199: } /* while( more IP addresses ) */ ! 200: return (TRUE); /* WM_INITDIALOG */ ! 201: ! 202: /* ! 203: * Received a command message ! 204: */ ! 205: case WM_COMMAND: ! 206: if (LOWORD(wParam) == IDOK) { ! 207: EndDialog(hDlg, TRUE); /* Exits the dialog box */ ! 208: return TRUE; ! 209: } ! 210: return FALSE; /* WM_COMMAND */ ! 211: } /* switch message */ ! 212: ! 213: return (FALSE); /* Didn't process a message */ ! 214: UNREFERENCED_PARAMETER(lParam); ! 215: } /* DisplayHostEnt */ ! 216: ! 217: /**************************************************************************** ! 218: * ! 219: * FUNCTION: GetSendString(HWND, UINT, UINT, LONG) ! 220: * ! 221: * PURPOSE: dialog callback procedure. Allows the user to enter a ! 222: * string to be sent to the connected remote host. ! 223: * ! 224: *\***************************************************************************/ ! 225: ! 226: LRESULT APIENTRY GetSendString( ! 227: HWND hDlg, /* window handle of the dialog box */ ! 228: UINT message, /* type of message */ ! 229: UINT wParam, /* message-specific information */ ! 230: LONG lParam) ! 231: { ! 232: ! 233: switch (message) { ! 234: case WM_INITDIALOG: /* message: initialize dialog box */ ! 235: SetFocus( GetDlgItem( hDlg, IDD_EDIT)); ! 236: return (TRUE); ! 237: case WM_COMMAND: { /* message: received a command */ ! 238: switch(LOWORD(wParam)) { ! 239: case IDOK: /* "OK" box selected? */ ! 240: { ! 241: ! 242: /* ! 243: * Store string in szBuff (global buffer) ! 244: */ ! 245: GetDlgItemText( hDlg, IDD_EDIT, szBuff, 80); ! 246: EndDialog(hDlg, TRUE); /* Exits the dialog box */ ! 247: } ! 248: break; ! 249: case IDCANCEL: /* System menu close command? */ ! 250: EndDialog(hDlg, FALSE); /* Exits the dialog box */ ! 251: break; ! 252: default: ! 253: return FALSE; ! 254: } ! 255: return (TRUE); ! 256: } ! 257: } /* switch message */ ! 258: ! 259: return (FALSE); /* Didn't process a message */ ! 260: UNREFERENCED_PARAMETER(lParam); ! 261: } /* GetString */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.