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 / statdlg.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  7KB  |  254 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:   statdlg.c
  9. //
  10. //  PURPOSE:   Displays the "StatDlg" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    StatDlg           - Processes messages for "StatDlg" dialog box.
  14. //    MsgStatDlgInit    - To initialize the statdlg box.
  15. //    MsgStatDlgCommand - Process WM_COMMAND message sent to the statdlg box.
  16. //    CmdStatDlgRefresh - Display the connection status.
  17. //    CmdStatDlgOK      - Free the statdlg box and related data.
  18. //
  19. //  COMMENTS:
  20. //    Dialog box to display the status of the selected connection
  21. //
  22.  
  23. #include <windows.h>            // required for all Windows applications
  24. #include <windowsx.h>
  25.  
  26. #ifdef WIN16
  27. #include "win16ext.h"           // required only for win16 applications
  28. #endif
  29.  
  30. #include "globals.h"            // prototypes specific to this application
  31. #include <stdlib.h>
  32. #include <ras.h>
  33. #include <raserror.h>
  34. #include "rasutil.h"
  35. #include "statdlg.h"
  36.  
  37. LRESULT MsgStatDlgInit(HWND, UINT, WPARAM, LPARAM);
  38. LRESULT MsgStatDlgCommand(HWND, UINT, WPARAM, LPARAM);
  39. LRESULT CmdStatDlgRefresh(HWND, WORD, WORD, HWND);
  40. LRESULT CmdStatDlgOK(HWND, WORD, WORD, HWND);
  41.  
  42. // StatDlg dialog message table definition.
  43. MSD rgmsdStatDlg[] =
  44. {
  45.     {WM_COMMAND,    MsgStatDlgCommand},
  46.     {WM_INITDIALOG, MsgStatDlgInit}
  47. };
  48.  
  49. MSDI msdiStatDlg =
  50. {
  51.     sizeof(rgmsdStatDlg) / sizeof(MSD),
  52.     rgmsdStatDlg,
  53.     edwpNone
  54. };
  55.  
  56. // StatDlg dialog command table definition.
  57. CMD rgcmdStatDlg[] =
  58. {
  59.     {IDB_REFRESH, CmdStatDlgRefresh},
  60.     {IDOK,        CmdStatDlgOK}
  61. };
  62.  
  63. CMDI cmdiStatDlg =
  64. {
  65.     sizeof(rgcmdStatDlg) / sizeof(CMD),
  66.     rgcmdStatDlg,
  67.     edwpNone
  68. };
  69.  
  70. // Module specific "globals"  Used when a variable needs to be
  71. // accessed in more than on handler function.
  72.  
  73.  
  74. //
  75. //  FUNCTION: StatDlg(HWND, UINT, WPARAM, LPARAM)
  76. //
  77. //  PURPOSE:  Processes messages for "StatDlg" dialog box.
  78. //
  79. //  PARAMETERS:
  80. //    hdlg - window handle of the dialog box
  81. //    wMessage - type of message
  82. //    wparam - message-specific information
  83. //    lparam - message-specific information
  84. //
  85. //  RETURN VALUE:
  86. //    TRUE - message handled
  87. //    FALSE - message not handled
  88. //
  89. //  COMMENTS:
  90. //    Dispatch messages
  91. //
  92.  
  93. LRESULT CALLBACK StatDlg(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  94. {
  95.     return DispMessage(&msdiStatDlg, hdlg, uMessage, wparam, lparam);
  96. }
  97.  
  98.  
  99. //
  100. //  FUNCTION: MsgStatDlgInit(HWND, UINT, WPARAM, LPARAM)
  101. //
  102. //  PURPOSE: To initialize the statdlg box.
  103. //
  104. //  PARAMETERS:
  105. //    hwnd - The window handing the message.
  106. //    uMessage - The message number. WM_INITDLG.
  107. //    wparam - Message specific data (unused).
  108. //    lparam - Message specific data (unused).
  109. //
  110. //  RETURN VALUE:
  111. //    Always returns 0 - message handled.
  112. //
  113. //  COMMENTS:
  114. //
  115.  
  116. LRESULT MsgStatDlgInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  117. {
  118.     // Center the dialog over the application window
  119.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  120.  
  121.     SendMessage(hdlg, WM_COMMAND, (WPARAM) IDB_REFRESH, 0L );
  122.  
  123.     return TRUE;
  124. }
  125.  
  126. //
  127. //  FUNCTION: MsgStatDlgCommand(HWND, UINT, WPARAM, LPARAM)
  128. //
  129. //  PURPOSE: Process WM_COMMAND message sent to the statdlg box.
  130. //
  131. //  PARAMETERS:
  132. //    hwnd - The window handing the message.
  133. //    uMessage - The message number. WM_COMMAND.
  134. //    wparam - Message specific data (unused).
  135. //    lparam - Message specific data (unused).
  136. //
  137. //  RETURN VALUE:
  138. //    TRUE for message handled.
  139. //    FALSE for message not handled.
  140. //
  141. //  COMMENTS:
  142. //    Uses this DispCommand function defined in wndproc.c combined
  143. //    with the cmdiStatDlg structure defined in this file to handle
  144. //    the command messages for the statdlg dialog box.
  145. //
  146.  
  147. LRESULT MsgStatDlgCommand(HWND   hwnd, 
  148.                         UINT   uMessage, 
  149.                         WPARAM wparam, 
  150.                         LPARAM lparam)
  151. {
  152.     return DispCommand(&cmdiStatDlg, hwnd, wparam, lparam);
  153. }
  154.  
  155. //
  156. //  FUNCTION: CmdStatDlgRefresh(HWND, WORD, WORD, HWND)
  157. //
  158. //  PURPOSE: Refresh the information displayed in the dialog box.
  159. //
  160. //  PARAMETERS:
  161. //    hwnd - The window handling the command.
  162. //    wCommand - The command to be handled IDB_REFRESH.
  163. //    wNotify  - The notifcation message (unused).
  164. //    hwndCtrl - NULL (unused).
  165. //
  166. //  RETURN VALUE:
  167. //    Always returns TRUE.
  168. //
  169. //  COMMENTS:
  170. //    Calls RasGetConnectStatus to populate dialog box.
  171. //
  172.  
  173. LRESULT CmdStatDlgRefresh(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  174. {
  175.     HRASCONN hrasconn;
  176.     RASCONNSTATUS rasStatus;
  177.     DWORD dwRet;
  178.     CHAR  szBuf[256];
  179.     HWND  hwndConn;
  180.     UINT  ndx;
  181.  
  182.     // get the connection text from previous window
  183.     hwndConn = GetDlgItem( GetParent(hdlg), IDL_CONN);
  184.     ndx = (UINT) SendMessage( hwndConn, LB_GETCURSEL, 0,  0L );
  185.     SendMessage( hwndConn, LB_GETTEXT, ndx, (LPARAM)(LPSTR)szBuf );
  186.     SetDlgItemText(hdlg, IDE_CONNECTION, (LPSTR)szBuf );
  187.  
  188.     // get to HRASCONN
  189.     hrasconn = g_lphRasConn[ndx];
  190.        
  191.     // get connection status
  192.     rasStatus.dwSize = sizeof(RASCONNSTATUS);
  193.     dwRet = RasGetConnectStatus( hrasconn, &rasStatus );
  194.     if ( dwRet )
  195.     {
  196.         if ( RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
  197.             wsprintf( (LPSTR)szBuf, "Undefined RAS Connect Status Error (%ld).", dwRet );
  198.  
  199.         MessageBox(hdlg, (LPSTR)szBuf, szAppName, MB_OK | MB_ICONSTOP );
  200.         EndDialog(hdlg, FALSE);
  201.         return TRUE;
  202.     }
  203.     else 
  204.     {
  205.         LoadString( hInst,
  206.                     GetRasConnState( rasStatus.rasconnstate ),
  207.                     (LPSTR)szBuf,
  208.                     256 );
  209.         SetDlgItemText(hdlg, IDE_STATUS, (LPSTR)szBuf);
  210.  
  211.         if ( rasStatus.dwError ) // there is an error
  212.         {
  213.             if ( RasGetErrorString( (UINT)rasStatus.dwError, (LPSTR)szBuf, 256 ) != 0 )
  214.                 wsprintf( (LPSTR)szBuf, "Undefined Connection Error (%ld).", rasStatus.dwError );
  215.         }
  216.         else
  217.         {
  218.             wsprintf( (LPSTR)szBuf, "No Error" );
  219.         }
  220.         SetDlgItemText(hdlg, IDE_ERROR, (LPSTR)szBuf);
  221.  
  222.         SetDlgItemText(hdlg, IDE_DEVICE, rasStatus.szDeviceName);
  223.  
  224.         SetDlgItemText(hdlg, IDE_TYPE, rasStatus.szDeviceType);
  225.  
  226.     }
  227.  
  228.     return TRUE;
  229. }
  230.  
  231. //
  232. //  FUNCTION: CmdStatDlgOK(HWND, WORD, HWND)
  233. //
  234. //  PURPOSE: Free the statdlg box and related data.
  235. //
  236. //  PARAMETERS:
  237. //    hwnd - The window handling the command.
  238. //    wCommand - The command to be handled (unused).
  239. //    wNotify  - The notifcation message (unused).
  240. //    hwndCtrl - NULL (unused).
  241. //
  242. //  RETURN VALUE:
  243. //    Always returns TRUE.
  244. //
  245. //  COMMENTS:
  246. //    Calls EndDialog to finish the dialog session.
  247. //
  248.  
  249. LRESULT CmdStatDlgOK(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  250. {
  251.     EndDialog(hdlg, TRUE);          // Exit the dialog
  252.     return TRUE;
  253. }
  254.