dialog.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * WineMine (dialog.c)
  3. *
  4. * Copyright 2000 Joshua Thielen
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #define WIN32_LEAN_AND_MEAN
  21. #include <windows.h>
  22. #include "main.h"
  23. #include "resource.h"
  24. INT_PTR CALLBACK CustomDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  25. {
  26. BOOL IsRet;
  27. static BOARD *p_board;
  28. switch( uMsg ) {
  29. case WM_INITDIALOG:
  30. p_board = (BOARD*) lParam;
  31. SetDlgItemInt( hDlg, IDC_EDITROWS, p_board->rows, FALSE );
  32. SetDlgItemInt( hDlg, IDC_EDITCOLS, p_board->cols, FALSE );
  33. SetDlgItemInt( hDlg, IDC_EDITMINES, p_board->mines, FALSE );
  34. return TRUE;
  35. case WM_COMMAND:
  36. switch( LOWORD( wParam ) ) {
  37. case IDOK:
  38. p_board->rows = GetDlgItemInt( hDlg, IDC_EDITROWS, &IsRet, FALSE );
  39. p_board->cols = GetDlgItemInt( hDlg, IDC_EDITCOLS, &IsRet, FALSE );
  40. p_board->mines = GetDlgItemInt( hDlg, IDC_EDITMINES, &IsRet, FALSE );
  41. CheckLevel( p_board );
  42. EndDialog( hDlg, 0 );
  43. return TRUE;
  44. case IDCANCEL:
  45. EndDialog( hDlg, 1 );
  46. return TRUE;
  47. }
  48. break;
  49. }
  50. return FALSE;
  51. }
  52. INT_PTR CALLBACK CongratsDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  53. {
  54. static BOARD *p_board;
  55. switch( uMsg ) {
  56. case WM_INITDIALOG:
  57. p_board = (BOARD*) lParam;
  58. SetDlgItemTextW( hDlg, IDC_EDITNAME, p_board->best_name[p_board->difficulty] );
  59. return TRUE;
  60. case WM_COMMAND:
  61. switch( LOWORD( wParam ) ) {
  62. case IDOK:
  63. GetDlgItemTextW( hDlg, IDC_EDITNAME, p_board->best_name[p_board->difficulty],
  64. ARRAY_SIZE(p_board->best_name[p_board->difficulty] ));
  65. EndDialog( hDlg, 0 );
  66. return TRUE;
  67. case IDCANCEL:
  68. EndDialog( hDlg, 0 );
  69. return TRUE;
  70. }
  71. break;
  72. }
  73. return FALSE;
  74. }
  75. INT_PTR CALLBACK TimesDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  76. {
  77. static BOARD *p_board;
  78. unsigned i;
  79. int confirm_msgbox_result;
  80. WCHAR confirm_title[256], confirm_text[256];
  81. switch( uMsg ) {
  82. case WM_INITDIALOG:
  83. p_board = (BOARD*) lParam;
  84. /* set best names */
  85. for( i = 0; i < 3; i++ )
  86. SetDlgItemTextW( hDlg, (IDC_NAME1) + i, p_board->best_name[i] );
  87. /* set best times */
  88. for( i = 0; i < 3; i++ )
  89. SetDlgItemInt( hDlg, (IDC_TIME1) + i, p_board->best_time[i], FALSE );
  90. return TRUE;
  91. case WM_COMMAND:
  92. switch( LOWORD( wParam ) ) {
  93. case IDC_RESET:
  94. LoadStringW( NULL, IDC_CONFIRMTITLE, confirm_title, ARRAY_SIZE(confirm_title));
  95. LoadStringW( NULL, IDC_CONFIRMTEXT, confirm_text, ARRAY_SIZE(confirm_text));
  96. confirm_msgbox_result = MessageBoxW( hDlg, confirm_text, confirm_title, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONWARNING );
  97. if( confirm_msgbox_result != IDOK )
  98. break;
  99. /* reset best names and times */
  100. ResetResults( p_board );
  101. /* save to registry */
  102. SaveBoard( p_board );
  103. /* update dialog */
  104. for( i = 0; i < 3; i++ ) {
  105. SetDlgItemTextW( hDlg, (IDC_NAME1) + i, p_board->best_name[i] );
  106. SetDlgItemInt( hDlg, (IDC_TIME1) + i, p_board->best_time[i], FALSE );
  107. }
  108. break;
  109. case IDOK:
  110. case IDCANCEL:
  111. EndDialog( hDlg, 0 );
  112. return TRUE;
  113. }
  114. break;
  115. }
  116. return FALSE;
  117. }