Old fashion design for PC-104
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.

156 lines
3.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: MessageBox.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of MessageBox.cpp
  13. //----------------------------------------------------------------------------
  14. // MessageBox.cpp: implementation of the CMessageBox class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "..\LgLib\Version.h"
  19. #include "Resource.h"
  20. #include "MessageBox.h"
  21. //////////////////////////////////////////////////////////////////////
  22. // Construction/Destruction
  23. //////////////////////////////////////////////////////////////////////
  24. CMessageBox::CMessageBox( LPCTSTR pTemplateName ) : CDialog( pTemplateName )
  25. {
  26. m_pText = "";
  27. m_pCaption = "";
  28. m_uType = 0;
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CMessageBox::CMessageBox" );
  30. }
  31. CMessageBox::~CMessageBox()
  32. {
  33. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CMessageBox::~CMessageBox" );
  34. }
  35. BOOL CMessageBox::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  36. {
  37. switch( uMsg )
  38. {
  39. case WM_INITDIALOG:
  40. return OnInitDialog( hWnd, wParam, lParam );
  41. case WM_COMMAND:
  42. return OnCommand( hWnd, wParam, lParam );
  43. }
  44. return FALSE;
  45. }
  46. BOOL CMessageBox::OnInitDialog( HWND hWnd, WPARAM wParam, LPARAM lParam )
  47. {
  48. ::SetWindowText( hWnd, m_pCaption );
  49. ::SendDlgItemMessage( hWnd, IDC_STATIC_TEXT, WM_SETTEXT, 0, (LPARAM)m_pText );
  50. enum { BT_OK = 0, BT_YES = 1, BT_NO = 2, BT_CANCEL = 3 };
  51. HWND hButton[4] =
  52. {
  53. ::GetDlgItem( hWnd, IDOK ),
  54. ::GetDlgItem( hWnd, IDYES ),
  55. ::GetDlgItem( hWnd, IDNO ),
  56. ::GetDlgItem( hWnd, IDCANCEL )
  57. };
  58. BOOL bShow[4] = { FALSE, FALSE, FALSE, FALSE };
  59. if( m_uType & MB_OK )
  60. {
  61. bShow[ BT_OK ] = TRUE;
  62. }
  63. else
  64. if( m_uType & MB_OKCANCEL )
  65. {
  66. bShow[ BT_OK ] = TRUE;
  67. bShow[ BT_CANCEL ] = TRUE;
  68. }
  69. else
  70. if( m_uType & MB_YESNO )
  71. {
  72. bShow[ BT_YES ] = TRUE;
  73. bShow[ BT_NO ] = TRUE;
  74. }
  75. else
  76. if( m_uType & MB_YESNOCANCEL )
  77. {
  78. bShow[ BT_YES ] = TRUE;
  79. bShow[ BT_NO ] = TRUE;
  80. bShow[ BT_CANCEL ] = TRUE;
  81. }
  82. else
  83. {
  84. bShow[ BT_OK ] = TRUE;
  85. }
  86. int nCountButton = 0;
  87. for( int i = BT_OK; i <= BT_CANCEL; i++ )
  88. {
  89. if( bShow[i] )
  90. {
  91. ::ShowWindow( hButton[i], SW_SHOW );
  92. nCountButton++;
  93. }
  94. else
  95. ::ShowWindow( hButton[i], SW_HIDE );
  96. }
  97. RECT rectButton;
  98. ::GetWindowRect( hButton[0], &rectButton );
  99. ::OffsetRect( &rectButton, -rectButton.left, -rectButton.top );
  100. RECT rectWindow;
  101. ::GetClientRect( hWnd, &rectWindow );
  102. int nWidthWindow = rectWindow.right - rectWindow.left;
  103. int nHeightWindow = rectWindow.bottom - rectWindow.top;
  104. int nWidthButton = rectButton.right - rectButton.left;
  105. int nHeightButton = rectButton.bottom - rectButton.top;
  106. const int spaceBetweenButtons = 5;
  107. int nButtonLeft = ( nWidthWindow - ( nWidthButton * nCountButton + spaceBetweenButtons * ( nCountButton - 1 ) ) ) / 2;
  108. int nButtonTop = ( nHeightWindow - spaceBetweenButtons - nHeightButton );
  109. ::OffsetRect( &rectButton, nButtonLeft, nButtonTop );
  110. for( i = BT_OK; i <= BT_CANCEL; i++ )
  111. {
  112. if( bShow[i] )
  113. {
  114. ::MoveWindow( hButton[i], rectButton.left, rectButton.top, nWidthButton, nHeightButton, TRUE );
  115. ::OffsetRect( &rectButton, nWidthButton + spaceBetweenButtons, 0 );
  116. }
  117. }
  118. return FALSE;
  119. }
  120. BOOL CMessageBox::OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam)
  121. {
  122. switch( LOWORD( wParam ) )
  123. {
  124. case IDOK:
  125. case IDYES:
  126. case IDNO:
  127. case IDCANCEL:
  128. ::EndDialog( hWnd, LOWORD( wParam ) );
  129. break;
  130. }
  131. return FALSE;
  132. }