1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
8 BEGIN_MESSAGE_MAP(view_header, CWnd)
9     ON_WM_PAINT()
10 END_MESSAGE_MAP()
11 
12 extern CFont ViewHeaderFont;
13 extern CFont NormalFont;
14 
15 
view_header(char * title,int IconId)16 view_header ::view_header(char *title, int IconId)
17 {
18     m_title = CString(title);
19     m_icon_id = IconId;
20 
21     BITMAP bmp;
22 
23     int dpi = GetSystemDPI();
24 
25     if (m_icon_id)
26     {
27         if (m_left_bmp.LoadBitmap(m_icon_id))
28         {
29             m_left_bmp.GetBitmap(&bmp);
30             m_icon_src_width = bmp.bmWidth;
31             m_icon_src_height = bmp.bmHeight;
32             m_icon_width = MulDiv(m_icon_src_width, dpi, DEFAULT_DPI_96);
33             m_icon_height = MulDiv(m_icon_src_height, dpi, DEFAULT_DPI_96);
34         }
35     }
36 }
37 
FillHeader(CDC * dc,int y,int xstart,int xend)38 void view_header::FillHeader(CDC *dc, int y, int xstart, int xend)
39 {
40     CDC dcMemory;
41     CBitmap fillmap;
42     fillmap.LoadBitmap(IDB_HEADER_BACKGROUND);
43     BITMAP bm;
44 
45     // go through hoops to get bitmap width:
46     fillmap.GetObject(sizeof(BITMAP), &bm);
47     int width = bm.bmWidth;
48 
49     dcMemory.CreateCompatibleDC(dc);
50     dcMemory.SelectObject(&fillmap);
51 
52     CRect client;
53     GetClientRect(&client);
54 
55     while(xstart < xend)
56     {
57         dc->StretchBlt(xstart, y, width, client.Height(), &dcMemory, 0, 0, width, bm.bmHeight, SRCCOPY);
58         xstart += width;
59     }
60 }
61 
PaintIcon(CDC * dc,int x,int y)62 void view_header::PaintIcon(CDC *dc, int x, int y)
63 {
64     CDC dcMemory;
65     dcMemory.CreateCompatibleDC(dc);
66     dcMemory.SelectObject(&m_left_bmp);
67     dc->StretchBlt(x, y, m_icon_width, m_icon_height, &dcMemory, 0, 0, m_icon_src_width, m_icon_src_height, SRCCOPY);
68 }
69 
PaintRightIcon(CDC * dc,int iconId,CRect & size)70 void view_header::PaintRightIcon(CDC *dc, int iconId, CRect &size)
71 {
72     CBitmap map;
73     BITMAP bm;
74 
75     map.LoadBitmap(iconId);
76 
77     // go through hoops to get bitmap width:
78     map.GetObject(sizeof(BITMAP), &bm);
79     int width = bm.bmWidth;
80     int right = size.right - (width + 8);
81 
82     int vspace = size.bottom - size.top;
83     vspace -= bm.bmHeight;
84     vspace /= 2;
85 
86     CDC dcMemory;
87     dcMemory.CreateCompatibleDC(dc);
88     dcMemory.SelectObject(&map);
89     dc->BitBlt(right, size.top + vspace, width, bm.bmHeight, &dcMemory, 0, 0, SRCCOPY);
90 }
91 
OnPaint()92 void view_header::OnPaint()
93 {
94     CFont *old_font;
95     CRect size;
96 
97     GetClientRect(&size);
98     CDC *dc = GetDC();
99     CWnd::OnPaint();
100     FillHeader(dc, size.top, size.left, size.right);
101 
102     int vspace = size.bottom - size.top;
103     vspace -= m_icon_height;
104     vspace /= 2;
105 
106     if (m_icon_id)
107     {
108         PaintIcon(dc, size.left + 8, size.top + vspace);
109         size.left += m_icon_width + 8;
110 
111         PaintRightIcon(dc, IDB_MINUS, size);
112     }
113 
114     dc->SetTextColor(RGB(255, 255, 255));
115     dc->SetBkMode(TRANSPARENT);
116     old_font = dc->SelectObject(&ViewHeaderFont);
117     size.left += 6;
118     dc->DrawText(m_title, &size, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
119     dc->SelectObject(old_font);
120     ReleaseDC(dc);
121 }
122 
123