dcompp.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 8k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /*  DCOMPP.CPP
  2. **
  3. **  Copyright (C) Microsoft, 1997, All Rights Reserved.
  4. **
  5. **  window class to display a preview of the desktop components,
  6. **
  7. */
  8. #include "stdafx.h"
  9. #pragma hdrstop
  10. //#include "deskstat.h"
  11. //#include "dcompp.h"
  12. //#include "dcomp.h"
  13. //#include "dutil.h"
  14. //#include "deskmovr.h"
  15. //#include <multimon.h>
  16. #ifdef POSTSPLIT
  17. #define THISCLASS CCompPreview
  18. class CCompPreview
  19. {
  20. public:
  21. protected:
  22.     HWND _hwnd;
  23.     HBITMAP _hbmMonitor;
  24.     HDC _hdcCompMemory;
  25.     int _iScreenWidth;
  26.     int _iScreenHeight;
  27.     int _iXBorders;
  28.     int _iYBorders;
  29.     static LONG CALLBACK CompPreviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  30.     friend BOOL RegisterCompPreviewClass(void);
  31.     LONG _OnCreate(HWND hwnd);
  32.     void _OnDestroy(void);
  33.     void _OnPaint(void);
  34.     void _RecalcMetrics(void);
  35. };
  36. void THISCLASS::_RecalcMetrics(void)
  37. {
  38.     RECT rect;
  39.     SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, FALSE);
  40.     _iScreenWidth = rect.right - rect.left;
  41.     _iScreenHeight = rect.bottom - rect.top;
  42.     _iXBorders = (2 * GET_CXSIZE);
  43.     _iYBorders = (GET_CYSIZE + GET_CYCAPTION);
  44. }
  45. LONG THISCLASS::_OnCreate(HWND hwnd)
  46. {
  47.     LONG lRet = 0;
  48.     _hwnd = hwnd;
  49.     SetWindowLong(hwnd, GWL_USERDATA, (LONG)this);
  50.     HDC hdc = GetDC(NULL);
  51.     _hdcCompMemory = CreateCompatibleDC(hdc);
  52.     ReleaseDC(NULL, hdc);
  53.     _hbmMonitor = LoadMonitorBitmap();
  54.     if (_hbmMonitor == NULL)
  55.     {
  56.         lRet = -1;
  57.     }
  58.     _RecalcMetrics();  //Initialize the screen width and height etc.,
  59.     return lRet;
  60. }
  61. void THISCLASS::_OnDestroy()
  62. {
  63.     if (_hbmMonitor)
  64.     {
  65.         DeleteObject(_hbmMonitor);
  66.     }
  67.     if (_hdcCompMemory)
  68.     {
  69.         DeleteDC(_hdcCompMemory);
  70.     }
  71.     delete this;
  72. }
  73. void THISCLASS::_OnPaint()
  74. {
  75.     PAINTSTRUCT     ps;
  76.     BITMAP          bm;
  77.     RECT            rc;
  78.     BeginPaint(_hwnd,&ps);
  79.     if (_hbmMonitor)
  80.     {
  81.         DWORD dwDefWidth = (_iScreenWidth / (COMPONENT_PER_ROW + 1)) - _iXBorders;
  82.         DWORD dwDefHeight = (_iScreenHeight / (COMPONENT_PER_COL + 1)) - _iYBorders;
  83.         //
  84.         // Select the monitor bitmap into an hdc.
  85.         //
  86.         HBITMAP hbmOld = (HBITMAP)SelectObject(_hdcCompMemory, _hbmMonitor);
  87.         //
  88.         // Get the size of the bitmap and of our window.
  89.         //
  90.         GetClientRect(_hwnd, &rc);
  91.         GetObject(_hbmMonitor, sizeof(bm), &bm);
  92.         //
  93.         // Center the bitmap in the window.
  94.         //
  95.         rc.left = ( rc.right - bm.bmWidth ) / 2;
  96.         rc.top = ( rc.bottom - bm.bmHeight ) / 2;
  97.         BitBlt(ps.hdc, rc.left, rc.top, bm.bmWidth, bm.bmHeight, _hdcCompMemory,
  98.             0, 0, SRCCOPY);
  99.         SelectObject(_hdcCompMemory, hbmOld);
  100.         COMPONENTSOPT co = { SIZEOF(co) };
  101.         g_pActiveDesk->GetDesktopItemOptions(&co, 0);
  102.         if (co.fActiveDesktop)
  103.         {
  104.             //
  105.             // From now on, only paint in the "monitor" area of the bitmap.
  106.             //
  107.             IntersectClipRect(ps.hdc, rc.left + MON_X, rc.top + MON_Y, rc.left + MON_X + MON_DX, rc.top + MON_Y + MON_DY);
  108.             //
  109.             // Determine who the selected component is.
  110.             //
  111.             int iSelectedComponent;
  112.             SendMessage(GetParent(_hwnd), WM_COMP_GETCURSEL, 0, (LPARAM)&iSelectedComponent);
  113.             //
  114.             // Create two new brush/pen combos, and remember the original
  115.             // brush & pen.
  116.             //
  117.             HBRUSH hbrushActComp = CreateSolidBrush(GetSysColor(COLOR_ACTIVECAPTION));
  118.             HPEN hpenActComp = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_CAPTIONTEXT));
  119.             HBRUSH hbrushComp = CreateSolidBrush(GetSysColor(COLOR_INACTIVECAPTION));
  120.             HPEN hpenComp = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_INACTIVECAPTIONTEXT));
  121.             HBRUSH hbrushOld = (HBRUSH)SelectObject(ps.hdc, hbrushComp);
  122.             HPEN hpenOld = (HPEN)SelectObject(ps.hdc, hpenComp);
  123.             int iPrimaryMonitorX = -GetSystemMetrics(SM_XVIRTUALSCREEN);
  124.             int iPrimaryMonitorY = -GetSystemMetrics(SM_YVIRTUALSCREEN);
  125.             int iPrimaryMonitorCX = GetSystemMetrics(SM_CXSCREEN);
  126.             int iPrimaryMonitorCY = GetSystemMetrics(SM_CYSCREEN);
  127.             //
  128.             // Draw each component in the "monitor" area of the bitmap.
  129.             //
  130.             int i, cComp;
  131.             g_pActiveDesk->GetDesktopItemCount(&cComp, 0);
  132.             for (i=0; i < cComp; i++)
  133.             {
  134.                 COMPONENT comp;
  135.                 comp.dwSize = sizeof(COMPONENT);
  136.                 if (SUCCEEDED(g_pActiveDesk->GetDesktopItem(i, &comp, 0)) && (comp.fChecked))
  137.                 {
  138.                     // BUGBUG: We show only components in the primary monitor in IE v4.01
  139.                     if (comp.cpPos.iLeft < iPrimaryMonitorX
  140.                             || comp.cpPos.iLeft > iPrimaryMonitorX + iPrimaryMonitorCX
  141.                             || comp.cpPos.iTop < iPrimaryMonitorY
  142.                             || comp.cpPos.iTop > iPrimaryMonitorY + iPrimaryMonitorCY)
  143.                     {
  144.                         continue;
  145.                     }
  146.                     //BUGBUG: If the width or Height is -1, then we don't know what the actual
  147.                     // size is going to be. So, we try to give a default size here for comp
  148.                     // in the preview bitmap.
  149.                     DWORD dwCompWidth = (comp.cpPos.dwWidth == COMPONENT_DEFAULT_WIDTH)? dwDefWidth : comp.cpPos.dwWidth;
  150.                     DWORD dwCompHeight = (comp.cpPos.dwHeight == COMPONENT_DEFAULT_HEIGHT)? dwDefHeight : comp.cpPos.dwHeight;
  151.                     if (i == iSelectedComponent)
  152.                     {
  153.                         SelectObject(ps.hdc, hbrushActComp);
  154.                         SelectObject(ps.hdc, hpenActComp);
  155.                     }
  156.                     int nLeft = rc.left + MON_X + MulDiv(comp.cpPos.iLeft - iPrimaryMonitorX, MON_DX, GetDeviceCaps(_hdcCompMemory, HORZRES));
  157.                     int nTop = rc.top + MON_Y + MulDiv(comp.cpPos.iTop - iPrimaryMonitorY, MON_DY, GetDeviceCaps(_hdcCompMemory, VERTRES));
  158.                     int nRight = rc.left + MON_X + MulDiv((comp.cpPos.iLeft - iPrimaryMonitorX) + dwCompWidth, MON_DX, GetDeviceCaps(_hdcCompMemory, HORZRES));
  159.                     int nBottom = rc.top + MON_Y + MulDiv((comp.cpPos.iTop - iPrimaryMonitorY)+ dwCompHeight, MON_DY, GetDeviceCaps(_hdcCompMemory, VERTRES));
  160.                     Rectangle(ps.hdc, nLeft, nTop, nRight, nBottom);
  161.                     if (i == iSelectedComponent)
  162.                     {
  163.                         SelectObject(ps.hdc, hbrushComp);
  164.                         SelectObject(ps.hdc, hpenComp);
  165.                     }
  166.                 }
  167.             }
  168.             SelectObject(ps.hdc, hpenOld);
  169.             SelectObject(ps.hdc, hbrushOld);
  170.             DeleteObject(hpenComp);
  171.             DeleteObject(hbrushComp);
  172.             DeleteObject(hpenActComp);
  173.             DeleteObject(hbrushActComp);
  174.         }
  175.     }
  176.     EndPaint(_hwnd,&ps);
  177. }
  178. LONG CALLBACK THISCLASS::CompPreviewWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  179. {
  180.     CCompPreview *pcp = (CCompPreview *)GetWindowLong(hwnd, GWL_USERDATA);
  181.     switch(message)
  182.     {
  183.     case WM_CREATE:
  184.         pcp = new CCompPreview();
  185.         return pcp ? pcp->_OnCreate(hwnd) : -1;
  186.     case WM_DESTROY:
  187.         pcp->_OnDestroy();
  188.         break;
  189.     case WM_PAINT:
  190.         pcp->_OnPaint();
  191.         return 0;
  192.     case WM_DISPLAYCHANGE:
  193.     case WM_WININICHANGE:
  194.         pcp->_RecalcMetrics();
  195.         break;
  196.     }
  197.     return DefWindowProc(hwnd,message,wParam,lParam);
  198. }
  199. BOOL RegisterCompPreviewClass(void)
  200. {
  201.     WNDCLASS wc;
  202.     if (!GetClassInfo(HINST_THISDLL, c_szComponentPreview, &wc)) {
  203.         wc.style = 0;
  204.         wc.lpfnWndProc = THISCLASS::CompPreviewWndProc;
  205.         wc.cbClsExtra = 0;
  206.         wc.cbWndExtra = 0;
  207.         wc.hInstance = HINST_THISDLL;
  208.         wc.hIcon = NULL;
  209.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  210.         wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
  211.         wc.lpszMenuName = NULL;
  212.         wc.lpszClassName = c_szComponentPreview;
  213.         if (!RegisterClass(&wc))
  214.             return FALSE;
  215.     }
  216.     return TRUE;
  217. }
  218. #endif