home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / ras / rasberry / authdlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  6.4 KB  |  220 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1997  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   authdlg.c
  9. //
  10. //  PURPOSE:   Displays the "AuthDlg" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    AuthDlg           - Processes messages for "AuthDlg" dialog box.
  14. //    MsgAuthDlgInit    - To initialize the authdlg box with version info
  15. //                      from resources.
  16. //    MsgAuthDlgCommand - Process WM_COMMAND message sent to the authdlg box.
  17. //    CmdAuthDlgOK      - Free the authdlg box and signal continue with dial.
  18. //    CmdAuthDlgCancel  - Free the authdlg box.
  19. //
  20. //  COMMENTS:
  21. //    Dialog Box to get authentication information
  22. //
  23. //
  24.  
  25. #include <windows.h>            // required for all Windows applications
  26. #include <windowsx.h>
  27. #ifdef WIN16
  28. #include "win16ext.h"           // required only for win16 applications
  29. #endif
  30. #include "globals.h"            // prototypes specific to this application
  31. #include <ras.h>
  32. #include <raserror.h>
  33. #include "authdlg.h"
  34.  
  35. LRESULT MsgAuthDlgInit(HWND, UINT, WPARAM, LPARAM);
  36. LRESULT MsgAuthDlgCommand(HWND, UINT, WPARAM, LPARAM);
  37. LRESULT CmdAuthDlgOK(HWND, WORD, WORD, HWND);
  38. LRESULT CmdAuthDlgCancel(HWND, WORD, WORD, HWND);
  39.  
  40.  
  41. // AuthDlg dialog message table definition.
  42. MSD rgmsdAuthDlg[] =
  43. {
  44.     {WM_COMMAND,      MsgAuthDlgCommand},
  45.     {WM_INITDIALOG,   MsgAuthDlgInit}
  46. };
  47.  
  48. MSDI msdiAuthDlg =
  49. {
  50.     sizeof(rgmsdAuthDlg) / sizeof(MSD),
  51.     rgmsdAuthDlg,
  52.     edwpNone
  53. };
  54.  
  55. // AuthDlg dialog command table definition.
  56. CMD rgcmdAuthDlg[] =
  57. {
  58.     {IDOK,     CmdAuthDlgOK},
  59.     {IDCANCEL, CmdAuthDlgCancel}
  60. };
  61.  
  62. CMDI cmdiAuthDlg =
  63. {
  64.     sizeof(rgcmdAuthDlg) / sizeof(CMD),
  65.     rgcmdAuthDlg,
  66.     edwpNone
  67. };
  68.  
  69. // Module specific "globals"  Used when a variable needs to be
  70. // accessed in more than on handler function.
  71.  
  72. //
  73. //  FUNCTION: AuthDlg(HWND, UINT, WPARAM, LPARAM)
  74. //
  75. //  PURPOSE:  Processes messages for "AuthDlg" dialog box.
  76. //
  77. //  PARAMETERS:
  78. //    hdlg - window handle of the dialog box
  79. //    wMessage - type of message
  80. //    wparam - message-specific information
  81. //    lparam - message-specific information
  82. //
  83. //  RETURN VALUE:
  84. //    TRUE - message handled
  85. //    FALSE - message not handled
  86. //
  87. //  COMMENTS:
  88. //    Dispatches message to appropriate handler
  89. //
  90.  
  91. LRESULT CALLBACK AuthDlg(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  92. {
  93.     return DispMessage(&msdiAuthDlg, hdlg, uMessage, wparam, lparam);
  94. }
  95.  
  96.  
  97. //
  98. //  FUNCTION: MsgAuthDlgInit(HWND, UINT, WPARAM, LPARAM)
  99. //
  100. //  PURPOSE: To initialize the authdlg box
  101. //
  102. //  PARAMETERS:
  103. //    hwnd - The window handing the message.
  104. //    uMessage - The message number. WM_INITDIALOG.
  105. //    wparam - Message specific data (unused).
  106. //    lparam - Message specific data (unused).
  107. //
  108. //  RETURN VALUE:
  109. //    Always returns TRUE - message handled.
  110. //
  111. //  COMMENTS:
  112. //    Registers window message for RAS event.
  113. //    Makes call to RasDial with appropriate params.
  114. //
  115.  
  116. LRESULT MsgAuthDlgInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  117. {
  118.     // Set text limits on edit controls
  119.     SendDlgItemMessage(hdlg, IDE_USERNAME, EM_LIMITTEXT, (WPARAM) UNLEN, 0L );
  120.     SendDlgItemMessage(hdlg, IDE_PASSWORD, EM_LIMITTEXT, (WPARAM) PWLEN, 0L );
  121.     SendDlgItemMessage(hdlg, IDE_DOMAIN,   EM_LIMITTEXT, (WPARAM) DNLEN, 0L );
  122.  
  123.     // reset password
  124.     g_szPassword[0] = '\0';
  125.  
  126.     // Set default text in edit controls
  127.     SendDlgItemMessage(hdlg, IDE_USERNAME, WM_SETTEXT, (WPARAM) 0, (LPARAM)(LPSTR) g_szUserName );
  128.     SendDlgItemMessage(hdlg, IDE_PASSWORD, WM_SETTEXT, (WPARAM) 0, (LPARAM)(LPSTR) g_szPassword );
  129.     SendDlgItemMessage(hdlg, IDE_DOMAIN,   WM_SETTEXT, (WPARAM) 0, (LPARAM)(LPSTR) g_szDomain );
  130.  
  131.     // Center the dialog over the application window
  132.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  133.  
  134.     return TRUE;
  135. }
  136.  
  137.  
  138. //
  139. //  FUNCTION: MsgAuthDlgCommand(HWND, UINT, WPARAM, LPARAM)
  140. //
  141. //  PURPOSE: Process WM_COMMAND message sent to the authdlg box.
  142. //
  143. //  PARAMETERS:
  144. //    hwnd - The window handing the message.
  145. //    uMessage - The message number. (unused).
  146. //    wparam - Message specific data (unused).
  147. //    lparam - Message specific data (unused).
  148. //
  149. //  RETURN VALUE:
  150. //    Always returns TRUE - message handled.
  151. //
  152. //  COMMENTS:
  153. //    Uses this DispCommand function defined in wndproc.c combined
  154. //    with the cmdiAuthDlg structure defined in this file to handle
  155. //    the command messages for the authdlg dialog box.
  156. //
  157.  
  158. LRESULT MsgAuthDlgCommand(HWND   hwnd,
  159.                         UINT   uMessage,
  160.                         WPARAM wparam,
  161.                         LPARAM lparam)
  162. {
  163.     return DispCommand(&cmdiAuthDlg, hwnd, wparam, lparam);
  164. }
  165.  
  166. //
  167. //  FUNCTION: CmdAuthDlgOK(HWND, WORD, WORD,  HWND)
  168. //
  169. //  PURPOSE: Free the authdlg box and related data.
  170. //
  171. //  PARAMETERS:
  172. //    hwnd - The window handling the command.
  173. //    wCommand - The command to be handle. IDOK.
  174. //    wNotify - The notification to be handled (unused).
  175. //    hwndCtrl - NULL (unused).
  176. //
  177. //  RETURN VALUE:
  178. //    Always returns TRUE.
  179. //
  180. //  COMMENTS:
  181. //    Calls EndDialog to finish the dialog session.
  182. //
  183.  
  184. LRESULT CmdAuthDlgOK(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  185. {
  186.     // Get text entered by the user
  187.     SendDlgItemMessage(hdlg, IDE_USERNAME, WM_GETTEXT, (WPARAM) UNLEN+1, (LPARAM)(LPSTR) g_szUserName );
  188.     SendDlgItemMessage(hdlg, IDE_PASSWORD, WM_GETTEXT, (WPARAM) PWLEN+1, (LPARAM)(LPSTR) g_szPassword );
  189.     SendDlgItemMessage(hdlg, IDE_DOMAIN,   WM_GETTEXT, (WPARAM) DNLEN+1, (LPARAM)(LPSTR) g_szDomain );
  190.  
  191.     EndDialog(hdlg, TRUE);          // Exit the dialog
  192.     return TRUE;
  193. }
  194.  
  195. //
  196. //  FUNCTION: CmdAuthDlgCancel(HWND, WORD, WORD,  HWND)
  197. //
  198. //  PURPOSE: Free the authdlg box and related data.
  199. //
  200. //  PARAMETERS:
  201. //    hwnd - The window handling the command.
  202. //    wCommand - The command to be handled. IDCANCEL.
  203. //    wNotify - The notification to be handled (unused).
  204. //    hwndCtrl - NULL (unused).
  205. //
  206. //  RETURN VALUE:
  207. //    Always returns TRUE.
  208. //
  209. //  COMMENTS:
  210. //    Calls EndDialog to finish the dialog session.
  211. //
  212.  
  213. LRESULT CmdAuthDlgCancel(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  214. {
  215.     EndDialog(hdlg, FALSE);          // Exit the dialog
  216.     return TRUE;
  217. }
  218.  
  219.  
  220.