Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.8 KiB

  1. // CnctDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "KeyObjs.h"
  6. #include "CmnKey.h"
  7. #include "W3Key.h"
  8. #include "W3Serv.h"
  9. #include "CnctDlg.h"
  10. #include "IPDlg.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CConnectionDlg dialog
  18. CConnectionDlg::CConnectionDlg(CWnd* pParent /*=NULL*/)
  19. : CDialog(CConnectionDlg::IDD, pParent),
  20. m_pKey( NULL )
  21. {
  22. //{{AFX_DATA_INIT(CConnectionDlg)
  23. m_int_connection_type = -1;
  24. //}}AFX_DATA_INIT
  25. }
  26. void CConnectionDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CConnectionDlg)
  30. DDX_Control(pDX, IDC_BTN_SELECT_IPADDRESS, m_cbutton_choose_ip);
  31. DDX_Radio(pDX, IDC_BTN_KEYVIEW_NONE, m_int_connection_type);
  32. //}}AFX_DATA_MAP
  33. // do the ip address field by hand
  34. if ( pDX->m_bSaveAndValidate )
  35. m_szIPAddress = GetIPAddress();
  36. else
  37. FSetIPAddress( m_szIPAddress );
  38. }
  39. BEGIN_MESSAGE_MAP(CConnectionDlg, CDialog)
  40. //{{AFX_MSG_MAP(CConnectionDlg)
  41. ON_BN_CLICKED(IDC_BTN_KEYVIEW_DEFAULT, OnBtnKeyviewDefault)
  42. ON_BN_CLICKED(IDC_BTN_KEYVIEW_IPADDR, OnBtnKeyviewIpaddr)
  43. ON_BN_CLICKED(IDC_BTN_KEYVIEW_NONE, OnBtnKeyviewNone)
  44. ON_BN_CLICKED(IDC_BTN_SELECT_IPADDRESS, OnBtnSelectIpaddress)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CConnectionDlg message handlers
  49. //----------------------------------------------------------------
  50. // override virtual oninitdialog
  51. BOOL CConnectionDlg::OnInitDialog( )
  52. {
  53. // call the base oninit
  54. CDialog::OnInitDialog();
  55. // set enable the ip address as appropriate to start with
  56. switch( m_int_connection_type )
  57. {
  58. case CONNECTION_NONE:
  59. m_cbutton_choose_ip.EnableWindow( FALSE );
  60. GetDlgItem(IDC_IPA_IPADDRESS)->EnableWindow(FALSE);
  61. break;
  62. case CONNECTION_DEFAULT:
  63. m_cbutton_choose_ip.EnableWindow( FALSE );
  64. GetDlgItem(IDC_IPA_IPADDRESS)->EnableWindow(FALSE);
  65. break;
  66. case CONNECTION_IPADDRESS:
  67. m_cbutton_choose_ip.EnableWindow( TRUE );
  68. GetDlgItem(IDC_IPA_IPADDRESS)->EnableWindow(TRUE);
  69. break;
  70. };
  71. // return 0 to say we set the default item
  72. // return 1 to just select the default default item
  73. return 1;
  74. }
  75. //------------------------------------------------------------------------------
  76. void CConnectionDlg::OnBtnKeyviewNone()
  77. {
  78. // clear the address field
  79. UpdateData( TRUE );
  80. m_szIPStorage = m_szIPAddress;
  81. ClearIPAddress();
  82. // disable the address field and chooser
  83. m_cbutton_choose_ip.EnableWindow( FALSE );
  84. GetDlgItem(IDC_IPA_IPADDRESS)->EnableWindow(FALSE);
  85. }
  86. //------------------------------------------------------------------------------
  87. void CConnectionDlg::OnBtnKeyviewDefault()
  88. {
  89. // get the data from the form
  90. UpdateData( TRUE );
  91. m_szIPStorage = m_szIPAddress;
  92. ClearIPAddress();
  93. // disable the address field and chooser
  94. m_cbutton_choose_ip.EnableWindow( FALSE );
  95. GetDlgItem(IDC_IPA_IPADDRESS)->EnableWindow(FALSE);
  96. }
  97. //------------------------------------------------------------------------------
  98. void CConnectionDlg::OnBtnKeyviewIpaddr()
  99. {
  100. // enable the address field and chooser
  101. m_cbutton_choose_ip.EnableWindow( TRUE );
  102. GetDlgItem(IDC_IPA_IPADDRESS)->EnableWindow(TRUE);
  103. // ip address field
  104. UpdateData( TRUE );
  105. m_szIPAddress = m_szIPStorage;
  106. UpdateData( FALSE );
  107. }
  108. //------------------------------------------------------------------------------
  109. void CConnectionDlg::OnBtnSelectIpaddress()
  110. {
  111. // run the choose ip dialog here
  112. CChooseIPDlg dlg;
  113. // set up the ip dialog member variables
  114. dlg.m_szIPAddress = m_szIPAddress;
  115. dlg.m_pKey = m_pKey;
  116. // run the dialog
  117. if ( dlg.DoModal() == IDOK )
  118. {
  119. UpdateData( TRUE );
  120. m_szIPAddress = dlg.m_szIPAddress;
  121. UpdateData( FALSE );
  122. }
  123. }
  124. //------------------------------------------------------------------------------
  125. // Set and get the ip STRING from the ip edit control
  126. BOOL CConnectionDlg::FSetIPAddress( CString& szAddress )
  127. {
  128. DWORD dword, b1, b2, b3, b4;
  129. // break the string into 4 numerical bytes (reading left to right)
  130. dword = sscanf( szAddress, "%d.%d.%d.%d", &b1, &b2, &b3, &b4 );
  131. // if we didn't get all four, fail
  132. if ( dword != 4 )
  133. return FALSE;
  134. // make the numerical ip address out of the bytes
  135. dword = (DWORD)MAKEIPADDRESS(b1,b2,b3,b4);
  136. // set the ip address into the control
  137. SendDlgItemMessage( IDC_IPA_IPADDRESS, IPM_SETADDRESS, 0, dword );
  138. #ifdef _DEBUG
  139. dword = 0;
  140. // dword = SendDlgItemMessage( IDC_IPA_IPADDRESS, IPM_GETADDRESS, 0, 0 );
  141. #endif
  142. // return success
  143. return TRUE;
  144. }
  145. //------------------------------------------------------------------------------
  146. CString CConnectionDlg::GetIPAddress()
  147. {
  148. CString szAnswer;
  149. DWORD dword, b1, b2, b3, b4;
  150. // get the ip address from the control
  151. SendDlgItemMessage( IDC_IPA_IPADDRESS, IPM_GETADDRESS, 0, (LPARAM)&dword );
  152. // get the constituent parts
  153. b1 = FIRST_IPADDRESS( dword );
  154. b2 = SECOND_IPADDRESS( dword );
  155. b3 = THIRD_IPADDRESS( dword );
  156. b4 = FOURTH_IPADDRESS( dword );
  157. // format the string
  158. if ( dword )
  159. szAnswer.Format( "%d.%d.%d.%d", b1, b2, b3, b4 );
  160. else
  161. szAnswer.Empty();
  162. return szAnswer;
  163. }
  164. //------------------------------------------------------------------------------
  165. // Set and get the ip STRING from the ip edit control
  166. void CConnectionDlg::ClearIPAddress()
  167. {
  168. // clear the ip address control
  169. SendDlgItemMessage( IDC_IPA_IPADDRESS, IPM_CLEARADDRESS, 0, 0 );
  170. }