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.

128 lines
2.6 KiB

  1. // dsubmit.cpp
  2. //
  3. // Copyright 2000 Microsoft Corporation, all rights reserved
  4. //
  5. // Created 2-00 anbrad
  6. //
  7. #include "pch.h"
  8. #pragma hdrstop
  9. #include "dsubmit.h"
  10. #include "resource.h"
  11. #include "main.h"
  12. const DWORD c_cbName = sizeof(g_szName)/sizeof(TCHAR);
  13. const DWORD c_cbProblem = sizeof(g_szProblem)/sizeof(TCHAR);
  14. INT_PTR CALLBACK DlgProcSubmit(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  15. {
  16. DWORD cbName = c_cbName;
  17. switch (msg)
  18. {
  19. case WM_INITDIALOG:
  20. CentreWindow(hwnd);
  21. SendMessage (GetDlgItem(hwnd, IDC_USER), EM_LIMITTEXT, c_cbName, 0);
  22. SendMessage (GetDlgItem(hwnd, IDC_PROBLEM), EM_LIMITTEXT, c_cbProblem, 0);
  23. GetUserName(g_szName, &cbName);
  24. if (cbName)
  25. {
  26. SetDlgItemText(hwnd, IDC_USER, g_szName);
  27. SetFocus(GetDlgItem(hwnd, IDC_PROBLEM));
  28. return FALSE;
  29. }
  30. return TRUE;
  31. case WM_COMMAND:
  32. switch (LOWORD(wParam))
  33. {
  34. case IDOK:
  35. GetDlgItemText(hwnd, IDC_USER, g_szName, c_cbName);
  36. GetDlgItemText(hwnd, IDC_PROBLEM, g_szProblem, c_cbProblem);
  37. EndDialog(hwnd, TRUE);
  38. break;
  39. case IDCANCEL:
  40. g_szName[0] = '\0';
  41. g_szProblem[0] = '\0';
  42. EndDialog(hwnd, FALSE);
  43. break;
  44. }
  45. return TRUE;
  46. default:
  47. return FALSE;
  48. }
  49. return TRUE;
  50. }
  51. //////////////////////////////////////////////////////////////////////////////
  52. //
  53. // CentreWindow
  54. //
  55. // Positions a window so that it is centered in its parent.
  56. //
  57. //////////////////////////////////////////////////////////////////////////////
  58. void CentreWindow(HWND hwnd)
  59. {
  60. RECT rect;
  61. RECT rectParent;
  62. HWND hwndParent;
  63. LONG dx, dy;
  64. LONG dxParent, dyParent;
  65. LONG Style;
  66. //
  67. // Get window rect.
  68. //
  69. GetWindowRect(hwnd, &rect);
  70. dx = rect.right - rect.left;
  71. dy = rect.bottom - rect.top;
  72. //
  73. // Get parent rect.
  74. //
  75. Style = GetWindowLong(hwnd, GWL_STYLE);
  76. if ((Style & WS_CHILD) == 0)
  77. {
  78. hwndParent = GetDesktopWindow();
  79. }
  80. else
  81. {
  82. hwndParent = GetParent(hwnd);
  83. if (hwndParent == NULL)
  84. {
  85. hwndParent = GetDesktopWindow();
  86. }
  87. }
  88. GetWindowRect(hwndParent, &rectParent);
  89. dxParent = rectParent.right - rectParent.left;
  90. dyParent = rectParent.bottom - rectParent.top;
  91. //
  92. // Centre the child in the parent.
  93. //
  94. rect.left = (dxParent - dx) / 2;
  95. rect.top = (dyParent - dy) / 3;
  96. //
  97. // Move the child into position.
  98. //
  99. SetWindowPos( hwnd,
  100. NULL,
  101. rect.left,
  102. rect.top,
  103. 0,
  104. 0,
  105. SWP_NOSIZE | SWP_NOZORDER );
  106. SetForegroundWindow(hwnd);
  107. }