Leaked source code of windows server 2003
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.

144 lines
3.1 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. snapbar.cpp
  5. Abstract:
  6. Implementation of the snapshot icon.
  7. --*/
  8. #include <windows.h>
  9. #include "snapbar.h"
  10. #include "resource.h"
  11. #define SNAPBTN_HEIGHT 24
  12. #define SNAPBTN_WIDTH 32
  13. #define SNAPBTN_VMARGIN 1
  14. #define SNAPBTN_HMARGIN 8
  15. #define SNAPBAR_HEIGHT (SNAPBTN_HEIGHT + 2 * SNAPBTN_VMARGIN)
  16. #define SNAPBAR_WIDTH (SNAPBTN_WIDTH + SNAPBTN_HMARGIN)
  17. CSnapBar::CSnapBar (
  18. VOID
  19. )
  20. {
  21. m_hWnd = NULL;
  22. m_hBitmap = NULL;
  23. }
  24. CSnapBar::~CSnapBar (
  25. VOID
  26. )
  27. {
  28. if (m_hWnd != NULL && IsWindow(m_hWnd))
  29. DestroyWindow(m_hWnd);
  30. if (m_hBitmap != NULL)
  31. DeleteObject(m_hBitmap);
  32. }
  33. BOOL
  34. CSnapBar::Init (
  35. IN CSysmonControl *pCtrl,
  36. IN HWND hWndParent
  37. )
  38. {
  39. HINSTANCE hInst;
  40. m_pCtrl = pCtrl;
  41. hInst = (HINSTANCE) GetWindowLongPtr(hWndParent, GWLP_HINSTANCE);
  42. // Create the button window
  43. m_hWnd = CreateWindow(L"BUTTON", NULL,
  44. WS_VISIBLE| WS_CHILD| BS_BITMAP| BS_PUSHBUTTON,
  45. 0, 0, SNAPBTN_WIDTH, SNAPBTN_HEIGHT,
  46. hWndParent,
  47. (HMENU)IDC_SNAPBTN,
  48. hInst,
  49. NULL);
  50. if (m_hWnd == NULL)
  51. return FALSE;
  52. // Point back to object
  53. //SetWindowLongPtr(m_hWnd, 0, (INT_PTR)this);
  54. // Insert our own window procedure for special processing
  55. //m_WndProc = (WNDPROC)SetWindowLongPtr(hWndParent, GWLP_WNDPROC, (INT_PTR)SnapBarWndProc);
  56. // Load the bitmap
  57. m_hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SNAPBTN));
  58. if (m_hBitmap == NULL)
  59. return FALSE;
  60. // Assign it to the button
  61. SendMessage(m_hWnd, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)m_hBitmap);
  62. return TRUE;
  63. }
  64. INT
  65. CSnapBar::Height (
  66. IN INT iMaxHeight
  67. )
  68. {
  69. return (iMaxHeight >= SNAPBAR_HEIGHT) ? SNAPBAR_HEIGHT : 0;
  70. }
  71. VOID
  72. CSnapBar::SizeComponents (
  73. IN LPRECT pRect
  74. )
  75. {
  76. // If room for the button
  77. if ((pRect->bottom - pRect->top) >= SNAPBAR_HEIGHT &&
  78. (pRect->right - pRect->left) >= SNAPBAR_WIDTH ) {
  79. // Position it in top right corner of space
  80. MoveWindow(m_hWnd, pRect->right - SNAPBAR_WIDTH,
  81. pRect->top + SNAPBTN_VMARGIN, SNAPBTN_WIDTH, SNAPBTN_HEIGHT,
  82. FALSE);
  83. ShowWindow(m_hWnd, TRUE);
  84. }
  85. else {
  86. ShowWindow(m_hWnd, FALSE);
  87. }
  88. }
  89. LRESULT CALLBACK
  90. SnapBarWndProc (
  91. HWND hWnd,
  92. UINT uiMsg,
  93. WPARAM wParam,
  94. LPARAM lParam
  95. )
  96. {
  97. PSNAPBAR pObj = (PSNAPBAR)GetWindowLongPtr(hWnd,0);
  98. // Give up focus after mouse activation
  99. if (uiMsg == WM_CAPTURECHANGED)
  100. SetFocus(GetParent(hWnd));
  101. // Do normal processing
  102. #ifdef STRICT
  103. return CallWindowProc(pObj->m_WndProc, hWnd, uiMsg, wParam, lParam);
  104. #else
  105. return CallWindowProc((FARPROC)pObj->m_WndProc, hWnd, uiMsg, wParam, lParam);
  106. #endif
  107. }