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.

76 lines
1.6 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1997
  3. All rights reserved
  4. ***************************************************************************/
  5. #include "pch.h"
  6. DEFINE_MODULE("Utils");
  7. #define SMALL_BUFFER_SIZE 256
  8. //
  9. // Centers a dialog.
  10. //
  11. void
  12. CenterDialog(
  13. HWND hwndDlg )
  14. {
  15. RECT rc;
  16. RECT rcScreen;
  17. int x, y;
  18. int cxDlg, cyDlg;
  19. int cxScreen;
  20. int cyScreen;
  21. SystemParametersInfo( SPI_GETWORKAREA, 0, &rcScreen, 0 );
  22. cxScreen = rcScreen.right - rcScreen.left;
  23. cyScreen = rcScreen.bottom - rcScreen.top;
  24. GetWindowRect( hwndDlg, &rc );
  25. cxDlg = rc.right - rc.left;
  26. cyDlg = rc.bottom - rc.top;
  27. y = rcScreen.top + ( ( cyScreen - cyDlg ) / 2 );
  28. x = rcScreen.left + ( ( cxScreen - cxDlg ) / 2 );
  29. SetWindowPos( hwndDlg, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE );
  30. }
  31. //
  32. // Eats all mouse and keyboard messages.
  33. //
  34. void
  35. ClearMessageQueue( void )
  36. {
  37. MSG msg;
  38. while ( PeekMessage( (LPMSG)&msg, NULL, WM_KEYFIRST, WM_MOUSELAST,
  39. PM_NOYIELD | PM_REMOVE ) );
  40. }
  41. //
  42. // Create a message box from resource strings.
  43. //
  44. int
  45. MessageBoxFromStrings(
  46. HWND hParent,
  47. UINT idsCaption,
  48. UINT idsText,
  49. UINT uType )
  50. {
  51. TCHAR szText[ SMALL_BUFFER_SIZE ];
  52. TCHAR szCaption[ SMALL_BUFFER_SIZE ];
  53. DWORD dw;
  54. dw = LoadString( g_hinstance, idsCaption, szCaption, ARRAYSIZE( szCaption ));
  55. Assert( dw );
  56. dw = LoadString( g_hinstance, idsText, szText, ARRAYSIZE( szText ));
  57. Assert( dw );
  58. return MessageBox( hParent, szText, szCaption, uType );
  59. }