BtnST.cpp 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. #include "stdafx.h"
  2. #include "BtnST.h"
  3. #ifdef _DEBUG
  4. #define new DEBUG_NEW
  5. #undef THIS_FILE
  6. static char THIS_FILE[] = __FILE__;
  7. #endif
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CButtonST
  10. CButtonST::CButtonST()
  11. {
  12. m_bIsPressed = FALSE;
  13. m_bIsFocused = FALSE;
  14. m_bIsDisabled = FALSE;
  15. m_bMouseOnButton = FALSE;
  16. FreeResources(FALSE);
  17. // Default type is "flat" button
  18. m_bIsFlat = TRUE;
  19. // By default draw border in "flat" button
  20. m_bDrawBorder = TRUE;
  21. // By default icon is aligned horizontally
  22. m_nAlign = ST_ALIGN_HORIZ;
  23. // By default, for "flat" button, don't draw the focus rect
  24. m_bDrawFlatFocus = FALSE;
  25. // By default the button is not the default button
  26. m_bIsDefault = FALSE;
  27. // By default the button is not a checkbox
  28. m_bIsCheckBox = FALSE;
  29. m_nCheck = 0;
  30. // Set default colors
  31. SetDefaultColors(FALSE);
  32. // No tooltip created
  33. m_ToolTip.m_hWnd = NULL;
  34. // Do not draw as a transparent button
  35. m_bDrawTransparent = FALSE;
  36. m_pbmpOldBk = NULL;
  37. // No URL defined
  38. ::ZeroMemory(&m_szURL, sizeof(m_szURL));
  39. // No cursor defined
  40. m_hCursor = NULL; // Fix by kawasaki@us.dnttm.ro
  41. // No autorepeat
  42. m_bAutoRepeat = FALSE;
  43. m_hWndAutoRepeat = NULL;
  44. m_nMsgAutoRepeat = WM_APP;
  45. m_dwPeriodAutoRepeat = 100;
  46. } // End of CButtonST
  47. CButtonST::~CButtonST()
  48. {
  49. // Restore old bitmap (if any)
  50. if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
  51. {
  52. m_dcBk.SelectObject(m_pbmpOldBk);
  53. }
  54. FreeResources();
  55. // Destroy the cursor (if any)
  56. if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
  57. } // End of ~CButtonST
  58. BEGIN_MESSAGE_MAP(CButtonST, CButton)
  59. //{{AFX_MSG_MAP(CButtonST)
  60. ON_WM_CAPTURECHANGED()
  61. ON_WM_SETCURSOR()
  62. ON_WM_KILLFOCUS()
  63. ON_WM_MOUSEMOVE()
  64. ON_WM_SYSCOLORCHANGE()
  65. ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)
  66. ON_WM_ACTIVATE()
  67. ON_WM_ENABLE()
  68. ON_WM_CANCELMODE()
  69. ON_WM_CTLCOLOR_REFLECT()
  70. ON_WM_LBUTTONDOWN()
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. DWORD CButtonST::SetIcon(int nIconInId, int nIconOutId)
  74. {
  75. HICON hIconIn;
  76. HICON hIconOut;
  77. HINSTANCE hInstResource;
  78. // Find correct resource handle
  79. hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId), RT_GROUP_ICON);
  80. // Set icon when the mouse is IN the button
  81. hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0);
  82. // Set icon when the mouse is OUT the button
  83. hIconOut = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);
  84. return SetIcon(hIconIn, hIconOut);
  85. } // End of SetIcon
  86. DWORD CButtonST::SetIcon(HICON hIconIn, HICON hIconOut)
  87. {
  88. BOOL bRetValue;
  89. ICONINFO ii;
  90. // Free any loaded resource
  91. FreeResources();
  92. if (hIconIn != NULL)
  93. {
  94. m_csIcons[0].hIcon = hIconIn;
  95. // Get icon dimension
  96. ZeroMemory(&ii, sizeof(ICONINFO));
  97. bRetValue = ::GetIconInfo(hIconIn, &ii);
  98. if (bRetValue == FALSE)
  99. {
  100. FreeResources();
  101. return BTNST_INVALIDRESOURCE;
  102. } // if
  103. m_csIcons[0].dwWidth = (DWORD)(ii.xHotspot * 2);
  104. m_csIcons[0].dwHeight = (DWORD)(ii.yHotspot * 2);
  105. ::DeleteObject(ii.hbmMask);
  106. ::DeleteObject(ii.hbmColor);
  107. if (hIconOut != NULL)
  108. {
  109. m_csIcons[1].hIcon = hIconOut;
  110. // Get icon dimension
  111. ZeroMemory(&ii, sizeof(ICONINFO));
  112. bRetValue = ::GetIconInfo(hIconOut, &ii);
  113. if (bRetValue == FALSE)
  114. {
  115. FreeResources();
  116. return BTNST_INVALIDRESOURCE;
  117. } // if
  118. m_csIcons[1].dwWidth = (DWORD)(ii.xHotspot * 2);
  119. m_csIcons[1].dwHeight = (DWORD)(ii.yHotspot * 2);
  120. ::DeleteObject(ii.hbmMask);
  121. ::DeleteObject(ii.hbmColor);
  122. } // if
  123. } // if
  124. RedrawWindow();
  125. return BTNST_OK;
  126. } // End of SetIcon
  127. BOOL CButtonST::SetBtnCursor(int nCursorId)
  128. {
  129. HINSTANCE hInstResource;
  130. // Destroy any previous cursor
  131. if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
  132. m_hCursor = NULL;
  133. // If we want a cursor
  134. if (nCursorId != NULL)
  135. {
  136. hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId),
  137. RT_GROUP_CURSOR);
  138. // Load icon resource
  139. m_hCursor = (HCURSOR)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);
  140. // If something wrong then return FALSE
  141. if (m_hCursor == NULL) return FALSE;
  142. }
  143. return TRUE;
  144. } // End of SetBtnCursor
  145. void CButtonST::SetFlat(BOOL bState)
  146. {
  147. m_bIsFlat = bState;
  148. Invalidate();
  149. } // End of SetFlat
  150. BOOL CButtonST::GetFlat()
  151. {
  152. return m_bIsFlat;
  153. } // End of GetFlat
  154. void CButtonST::SetAlign(int nAlign)
  155. {
  156. switch (nAlign)
  157. {
  158. case ST_ALIGN_HORIZ:
  159. case ST_ALIGN_HORIZ_RIGHT:
  160. case ST_ALIGN_VERT:
  161. m_nAlign = nAlign;
  162. break;
  163. }
  164. Invalidate();
  165. } // End of SetAlign
  166. int CButtonST::GetAlign()
  167. {
  168. return m_nAlign;
  169. } // End of GetAlign
  170. void CButtonST::DrawBorder(BOOL bEnable)
  171. {
  172. m_bDrawBorder = bEnable;
  173. } // End of DrawBorder
  174. void CButtonST::OnMouseMove(UINT nFlags, CPoint point)
  175. {
  176. CWnd* pWnd; // Active window
  177. CWnd* pParent; // Window that owns the button
  178. CButton::OnMouseMove(nFlags, point);
  179. // If the mouse enter the button with the left button pressed then do nothing
  180. if (nFlags & MK_LBUTTON && m_bMouseOnButton == FALSE) return;
  181. // If our button is not flat then do nothing
  182. if (m_bIsFlat == FALSE) return;
  183. pWnd = GetActiveWindow();
  184. pParent = GetOwner();
  185. if ((GetCapture() != this) &&
  186. (
  187. #ifndef ST_LIKEIE
  188. pWnd != NULL &&
  189. #endif
  190. pParent != NULL))
  191. {
  192. m_bMouseOnButton = TRUE;
  193. //SetFocus(); // Thanks Ralph!
  194. SetCapture();
  195. Invalidate();
  196. } // if
  197. else
  198. {
  199. /*
  200. CRect rc;
  201. GetClientRect(&rc);
  202. if (!rc.PtInRect(point))
  203. {
  204. */
  205. POINT p2 = point;
  206. ClientToScreen(&p2);
  207. CWnd* wndUnderMouse = WindowFromPoint(p2);
  208. // if (wndUnderMouse != this)
  209. if (wndUnderMouse && wndUnderMouse->m_hWnd != this->m_hWnd)
  210. {
  211. // Redraw only if mouse goes out
  212. if (m_bMouseOnButton == TRUE)
  213. {
  214. m_bMouseOnButton = FALSE;
  215. Invalidate();
  216. } // if
  217. // If user is NOT pressing left button then release capture!
  218. if (!(nFlags & MK_LBUTTON)) ReleaseCapture();
  219. } // if
  220. } // else
  221. } // End of OnMouseMove
  222. void CButtonST::OnKillFocus(CWnd * pNewWnd)
  223. {
  224. CButton::OnKillFocus(pNewWnd);
  225. CancelHover();
  226. } // End of OnKillFocus
  227. void CButtonST::OnLButtonDown(UINT nFlags, CPoint point)
  228. {
  229. CButton::OnLButtonDown(nFlags, point);
  230. if (m_bAutoRepeat == TRUE)
  231. {
  232. MSG csMsg;
  233. int nButtonID;
  234. HWND hWndParent;
  235. BOOL bInitialState = TRUE;
  236. nButtonID = GetDlgCtrlID();
  237. hWndParent = GetParent()->GetSafeHwnd();
  238. SetCapture();
  239. while (PeekMessage(&csMsg, m_hWnd, WM_LBUTTONUP, WM_LBUTTONUP, PM_REMOVE) == FALSE)
  240. {
  241. ::SendMessage(hWndParent, WM_COMMAND, MAKEWPARAM((WORD)nButtonID, BN_CLICKED), (LPARAM)m_hWnd);
  242. ::Sleep(m_dwPeriodAutoRepeat);
  243. bInitialState = !bInitialState;
  244. } // while
  245. if (!bInitialState)
  246. {
  247. ::SendMessage(hWndParent, WM_COMMAND, MAKEWPARAM((WORD)nButtonID, BN_CLICKED), (LPARAM)m_hWnd);
  248. } // if
  249. ReleaseCapture();
  250. SendMessage(WM_LBUTTONUP);
  251. CPoint ptCursor;
  252. GetCursorPos(&ptCursor);
  253. ScreenToClient(&ptCursor);
  254. SendMessage(WM_MOUSEMOVE, 0, MAKELPARAM(ptCursor.x, ptCursor.y));
  255. } // if
  256. } // End of OnLButtonDown
  257. void CButtonST::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
  258. {
  259. CButton::OnActivate(nState, pWndOther, bMinimized);
  260. if (nState == WA_INACTIVE) CancelHover();
  261. } // End of OnActivate
  262. void CButtonST::OnEnable(BOOL bEnable)
  263. {
  264. CButton::OnEnable(bEnable);
  265. if (bEnable == FALSE) CancelHover();
  266. } // End of OnEnable
  267. void CButtonST::OnCancelMode()
  268. {
  269. CButton::OnCancelMode();
  270. CancelHover();
  271. } // End of OnCancelMode
  272. void CButtonST::OnCaptureChanged(CWnd *pWnd)
  273. {
  274. if (m_bMouseOnButton == TRUE)
  275. {
  276. ReleaseCapture();
  277. Invalidate();
  278. } // if
  279. CButton::OnCaptureChanged(pWnd);
  280. } // End of OnCaptureChanged
  281. void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  282. {
  283. CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  284. CPen *pOldPen;
  285. // Checkbox or Radiobutton style ?
  286. if (m_bIsCheckBox == TRUE)
  287. {
  288. m_bIsPressed = (lpDIS->itemState & ODS_SELECTED)
  289. || (m_nCheck != 0);
  290. //m_bIsPressed = TRUE;
  291. }
  292. // Normal button OR other button style ...
  293. else
  294. {
  295. m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);
  296. }
  297. m_bIsFocused = (lpDIS->itemState & ODS_FOCUS);
  298. m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);
  299. CRect itemRect = lpDIS->rcItem;
  300. pDC->SetBkMode(TRANSPARENT);
  301. if (m_bIsFlat == FALSE)
  302. {
  303. if (m_bIsFocused || (GetDefault() == TRUE))
  304. {
  305. CBrush br(RGB(0,0,0));
  306. pDC->FrameRect(&itemRect, &br);
  307. itemRect.DeflateRect(1, 1);
  308. } // if
  309. } // if
  310. // Prepare draw... paint button background
  311. // Draw transparent?
  312. if (m_bDrawTransparent == TRUE)
  313. PaintBk(pDC);
  314. else
  315. OnDrawBackground(pDC, &itemRect);
  316. // Draw pressed button
  317. if (m_bIsPressed)
  318. {
  319. if (m_bIsFlat == TRUE)
  320. {
  321. if (m_bDrawBorder)
  322. OnDrawBorder(pDC, &itemRect);
  323. }
  324. else
  325. {
  326. CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
  327. pDC->FrameRect(&itemRect, &brBtnShadow);
  328. }
  329. }
  330. else // ...else draw non pressed button
  331. {
  332. CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
  333. CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); // Light gray
  334. CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Dark gray
  335. CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black
  336. if (m_bIsFlat == TRUE)
  337. {
  338. if (m_bMouseOnButton && m_bDrawBorder)
  339. OnDrawBorder(pDC, &itemRect);
  340. }
  341. else
  342. {
  343. // Draw top-left borders
  344. // White line
  345. pOldPen = pDC->SelectObject(&penBtnHiLight);
  346. pDC->MoveTo(itemRect.left, itemRect.bottom-1);
  347. pDC->LineTo(itemRect.left, itemRect.top);
  348. pDC->LineTo(itemRect.right, itemRect.top);
  349. // Light gray line
  350. pDC->SelectObject(pen3DLight);
  351. pDC->MoveTo(itemRect.left+1, itemRect.bottom-1);
  352. pDC->LineTo(itemRect.left+1, itemRect.top+1);
  353. pDC->LineTo(itemRect.right, itemRect.top+1);
  354. // Draw bottom-right borders
  355. // Black line
  356. pDC->SelectObject(pen3DDKShadow);
  357. pDC->MoveTo(itemRect.left, itemRect.bottom-1);
  358. pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
  359. pDC->LineTo(itemRect.right-1, itemRect.top-1);
  360. // Dark gray line
  361. pDC->SelectObject(penBtnShadow);
  362. pDC->MoveTo(itemRect.left+1, itemRect.bottom-2);
  363. pDC->LineTo(itemRect.right-2, itemRect.bottom-2);
  364. pDC->LineTo(itemRect.right-2, itemRect.top);
  365. //
  366. pDC->SelectObject(pOldPen);
  367. }
  368. }
  369. // Read the button's title
  370. CString sTitle;
  371. GetWindowText(sTitle);
  372. CRect captionRect = lpDIS->rcItem;
  373. // Draw the icon
  374. if (m_csIcons[0].hIcon != NULL)
  375. {
  376. DrawTheIcon(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
  377. }
  378. if (m_csBitmaps[0].hBitmap != NULL)
  379. {
  380. pDC->SetBkColor(RGB(255,255,255));
  381. DrawTheBitmap(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
  382. } // if
  383. // Write the button title (if any)
  384. if (sTitle.IsEmpty() == FALSE)
  385. {
  386. // Draw the button's title
  387. // If button is pressed then "press" title also
  388. if (m_bIsPressed && m_bIsCheckBox == FALSE)
  389. captionRect.OffsetRect(1, 1);
  390. // ONLY FOR DEBUG
  391. //CBrush brBtnShadow(RGB(255, 0, 0));
  392. //pDC->FrameRect(&captionRect, &brBtnShadow);
  393. /*
  394. if ((m_bMouseOnButton == TRUE) || (bIsPressed))
  395. {
  396. pDC->SetTextColor(GetActiveFgColor());
  397. pDC->SetBkColor(GetActiveBgColor());
  398. }
  399. else
  400. {
  401. pDC->SetTextColor(GetInactiveFgColor());
  402. pDC->SetBkColor(GetInactiveBgColor());
  403. }
  404. */
  405. // Center text
  406. CRect centerRect = captionRect;
  407. pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);
  408. captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2);
  409. /* RFU
  410. captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);
  411. captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);
  412. */
  413. pDC->SetBkMode(TRANSPARENT);
  414. /*
  415. pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
  416. TRUE, 0, (CBrush*)NULL);
  417. */
  418. if (m_bIsDisabled)
  419. {
  420. captionRect.OffsetRect(1, 1);
  421. pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
  422. pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
  423. captionRect.OffsetRect(-1, -1);
  424. pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
  425. pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
  426. } // if
  427. else
  428. {
  429. if (m_bMouseOnButton || m_bIsPressed)
  430. {
  431. pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_IN]);
  432. pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_IN]);
  433. } // if
  434. else
  435. {
  436. pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]);
  437. pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]);
  438. } // else
  439. pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
  440. } // if
  441. } // if
  442. if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE))
  443. {
  444. // Draw the focus rect
  445. if (m_bIsFocused)
  446. {
  447. CRect focusRect = itemRect;
  448. focusRect.DeflateRect(3, 3);
  449. pDC->DrawFocusRect(&focusRect);
  450. } // if
  451. } // if
  452. } // End of DrawItem
  453. void CButtonST::DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, BOOL bIsDisabled)
  454. {
  455. BYTE byIndex = 0;
  456. // Select the icon to use
  457. if (m_bIsCheckBox == TRUE)
  458. {
  459. if (bIsPressed == TRUE)
  460. byIndex = 0;
  461. else
  462. byIndex = (m_csIcons[1].hIcon == NULL ? 0 : 1);
  463. } // if
  464. else
  465. {
  466. if (m_bMouseOnButton == TRUE || bIsPressed == TRUE)
  467. byIndex = 0;
  468. else
  469. byIndex = (m_csIcons[1].hIcon == NULL ? 0 : 1);
  470. } // else
  471. CRect rImage;
  472. PrepareImageRect(bHasTitle, rpItem, rpTitle, bIsPressed, m_csIcons[byIndex].dwWidth, m_csIcons[byIndex].dwHeight, &rImage);
  473. // Ole'!
  474. pDC->DrawState( rImage.TopLeft(),
  475. rImage.Size(),
  476. m_csIcons[byIndex].hIcon,
  477. (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
  478. (CBrush*)NULL);
  479. } // End of DrawTheIcon
  480. void CButtonST::PreSubclassWindow()
  481. {
  482. UINT nBS;
  483. nBS = GetButtonStyle();
  484. // Check if this is the default button
  485. if (nBS & BS_DEFPUSHBUTTON) m_bIsDefault = TRUE;
  486. // Check if this is a checkbox
  487. if (nBS & BS_CHECKBOX) m_bIsCheckBox = TRUE;
  488. // Add BS_OWNERDRAW style
  489. SetButtonStyle(nBS | BS_OWNERDRAW);
  490. CButton::PreSubclassWindow();
  491. } // End of PreSubclassWindow
  492. BOOL CButtonST::PreTranslateMessage(MSG* pMsg)
  493. {
  494. InitToolTip();
  495. m_ToolTip.RelayEvent(pMsg);
  496. return CButton::PreTranslateMessage(pMsg);
  497. } // End of PreTranslateMessage
  498. LRESULT CButtonST::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  499. {
  500. if (message == WM_LBUTTONDBLCLK)
  501. {
  502. message = WM_LBUTTONDOWN;
  503. } // if
  504. return CButton::DefWindowProc(message, wParam, lParam);
  505. } // End of DefWindowProc
  506. void CButtonST::SetFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint)
  507. {
  508. m_bDrawFlatFocus = bDrawFlatFocus;
  509. // Repaint the button
  510. if (bRepaint == TRUE) Invalidate();
  511. } // End of SetFlatFocus
  512. BOOL CButtonST::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  513. {
  514. // If a cursor was specified then use it!
  515. if (m_hCursor != NULL)
  516. {
  517. ::SetCursor(m_hCursor);
  518. return TRUE;
  519. } // if
  520. return CButton::OnSetCursor(pWnd, nHitTest, message);
  521. } // End of OnSetCursor
  522. void CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)
  523. {
  524. // We cannot accept NULL pointer
  525. if (lpszText == NULL) return;
  526. // Initialize ToolTip
  527. InitToolTip();
  528. // If there is no tooltip defined then add it
  529. if (m_ToolTip.GetToolCount() == 0)
  530. {
  531. CRect rectBtn;
  532. GetClientRect(rectBtn);
  533. m_ToolTip.AddTool(this, lpszText, rectBtn, 1);
  534. }
  535. // Set text for tooltip
  536. m_ToolTip.UpdateTipText(lpszText, this, 1);
  537. m_ToolTip.Activate(bActivate);
  538. } // End of SetTooltipText
  539. void CButtonST::SetTooltipText(int nId, BOOL bActivate)
  540. {
  541. CString sText;
  542. // load string resource
  543. sText.LoadString(nId);
  544. // If string resource is not empty
  545. if (sText.IsEmpty() == FALSE) SetTooltipText((LPCTSTR)sText, bActivate);
  546. } // End of SetTooltipText
  547. void CButtonST::ActivateTooltip(BOOL bActivate)
  548. {
  549. // If there is no tooltip then do nothing
  550. if (m_ToolTip.GetToolCount() == 0) return;
  551. // Activate tooltip
  552. m_ToolTip.Activate(bActivate);
  553. } // End of EnableTooltip
  554. BOOL CButtonST::GetDefault()
  555. {
  556. return m_bIsDefault;
  557. } // End of GetDefault
  558. void CButtonST::DrawTransparent(BOOL bRepaint)
  559. {
  560. m_bDrawTransparent = TRUE;
  561. // Restore old bitmap (if any)
  562. if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
  563. {
  564. m_dcBk.SelectObject(m_pbmpOldBk);
  565. } // if
  566. m_bmpBk.DeleteObject();
  567. m_dcBk.DeleteDC();
  568. // Repaint the button
  569. if (bRepaint == TRUE) Invalidate();
  570. } // End of DrawTransparent
  571. void CButtonST::InitToolTip()
  572. {
  573. if (m_ToolTip.m_hWnd == NULL)
  574. {
  575. // Create ToolTip control
  576. m_ToolTip.Create(this);
  577. // Create inactive
  578. m_ToolTip.Activate(FALSE);
  579. // Enable multiline
  580. m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 400);
  581. } // if
  582. } // End of InitToolTip
  583. void CButtonST::PaintBk(CDC* pDC)
  584. {
  585. CClientDC clDC(GetParent());
  586. CRect rect;
  587. CRect rect1;
  588. GetClientRect(rect);
  589. GetWindowRect(rect1);
  590. GetParent()->ScreenToClient(rect1);
  591. if (m_dcBk.m_hDC == NULL)
  592. {
  593. m_dcBk.CreateCompatibleDC(&clDC);
  594. m_bmpBk.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());
  595. m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk);
  596. m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);
  597. //2011-11-02 add
  598. DeleteObject( m_dcBk );
  599. } // if
  600. pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_dcBk, 0, 0, SRCCOPY);
  601. //2011-11-02 add
  602. DeleteObject( clDC );
  603. } // End of PaintBk
  604. HBRUSH CButtonST::CtlColor(CDC* pDC, UINT nCtlColor)
  605. {
  606. return (HBRUSH)::GetStockObject(NULL_BRUSH);
  607. } // End of CtlColor
  608. void CButtonST::OnSysColorChange()
  609. {
  610. CButton::OnSysColorChange();
  611. m_dcBk.DeleteDC();
  612. m_bmpBk.DeleteObject();
  613. } // End of OnSysColorChange
  614. BOOL CButtonST::OnClicked()
  615. {
  616. if (m_bIsCheckBox == TRUE)
  617. {
  618. m_nCheck = !m_nCheck;
  619. Invalidate();
  620. } // if
  621. else
  622. {
  623. // Handle the URL (if any)
  624. if (::lstrlen(m_szURL) > 0)
  625. ::ShellExecute(NULL, _T("open"), m_szURL, NULL,NULL, SW_SHOWMAXIMIZED);
  626. } // else
  627. return FALSE;
  628. } // End of OnClicked
  629. void CButtonST::SetCheck(int nCheck, BOOL bRepaint)
  630. {
  631. if (m_bIsCheckBox == TRUE)
  632. {
  633. if (nCheck == 0) m_nCheck = 0;
  634. else m_nCheck = 1;
  635. if (bRepaint == TRUE) Invalidate();
  636. } // if
  637. } // End of SetCheck
  638. int CButtonST::GetCheck()
  639. {
  640. return m_nCheck;
  641. } // End of GetCheck
  642. void CButtonST::FreeResources(BOOL bCheckForNULL)
  643. {
  644. if (bCheckForNULL == TRUE)
  645. {
  646. // Destroy icons
  647. // Note: the following two lines MUST be here! even if
  648. // BoundChecker says they are unnecessary!
  649. if (m_csIcons[0].hIcon != NULL) ::DeleteObject(m_csIcons[0].hIcon);
  650. if (m_csIcons[1].hIcon != NULL) ::DeleteObject(m_csIcons[1].hIcon);
  651. // Destroy bitmaps
  652. if (m_csBitmaps[0].hBitmap != NULL) ::DeleteObject(m_csBitmaps[0].hBitmap);
  653. if (m_csBitmaps[1].hBitmap != NULL) ::DeleteObject(m_csBitmaps[1].hBitmap);
  654. // Destroy mask bitmaps
  655. if (m_csBitmaps[0].hMask != NULL) ::DeleteObject(m_csBitmaps[0].hMask);
  656. if (m_csBitmaps[1].hMask != NULL) ::DeleteObject(m_csBitmaps[1].hMask);
  657. } // if
  658. ::ZeroMemory(&m_csIcons, sizeof(m_csIcons));
  659. ::ZeroMemory(&m_csBitmaps, sizeof(m_csBitmaps));
  660. } // End of FreeResources
  661. DWORD CButtonST::SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut, COLORREF crTransColorOut)
  662. {
  663. int nRetValue;
  664. BITMAP csBitmapSize;
  665. // Free any loaded resource
  666. FreeResources();
  667. if (hBitmapIn != NULL)
  668. {
  669. m_csBitmaps[0].hBitmap = hBitmapIn;
  670. m_csBitmaps[0].crTransparent = crTransColorIn;
  671. // Get bitmap size
  672. nRetValue = ::GetObject(hBitmapIn, sizeof(csBitmapSize), &csBitmapSize);
  673. if (nRetValue == 0)
  674. {
  675. FreeResources();
  676. return BTNST_INVALIDRESOURCE;
  677. } // if
  678. m_csBitmaps[0].dwWidth = (DWORD)csBitmapSize.bmWidth;
  679. m_csBitmaps[0].dwHeight = (DWORD)csBitmapSize.bmHeight;
  680. // Create mask for bitmap In
  681. m_csBitmaps[0].hMask = CreateBitmapMask(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);
  682. if (m_csBitmaps[0].hMask == NULL)
  683. {
  684. FreeResources();
  685. return BTNST_FAILEDMASK;
  686. } // if
  687. if (hBitmapOut != NULL)
  688. {
  689. m_csBitmaps[1].hBitmap = hBitmapOut;
  690. m_csBitmaps[1].crTransparent = crTransColorOut;
  691. // Get bitmap size
  692. nRetValue = ::GetObject(hBitmapOut, sizeof(csBitmapSize), &csBitmapSize);
  693. if (nRetValue == 0)
  694. {
  695. FreeResources();
  696. return BTNST_INVALIDRESOURCE;
  697. } // if
  698. m_csBitmaps[1].dwWidth = (DWORD)csBitmapSize.bmWidth;
  699. m_csBitmaps[1].dwHeight = (DWORD)csBitmapSize.bmHeight;
  700. // Create mask for bitmap Out
  701. m_csBitmaps[1].hMask = CreateBitmapMask(hBitmapOut, m_csBitmaps[1].dwWidth, m_csBitmaps[1].dwHeight, crTransColorOut);
  702. if (m_csBitmaps[1].hMask == NULL)
  703. {
  704. FreeResources();
  705. return BTNST_FAILEDMASK;
  706. } // if
  707. } // if
  708. } // if
  709. RedrawWindow();
  710. return BTNST_OK;
  711. } // End of SetBitmaps
  712. DWORD CButtonST::SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut, COLORREF crTransColorOut)
  713. {
  714. HBITMAP hBitmapIn = NULL;
  715. HBITMAP hBitmapOut = NULL;
  716. HINSTANCE hInstResource = NULL;
  717. // Find correct resource handle
  718. hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nBitmapIn), RT_BITMAP);
  719. // Load bitmap In
  720. hBitmapIn = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapIn), IMAGE_BITMAP, 0, 0, 0);
  721. // Load bitmap Out
  722. hBitmapOut = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapOut), IMAGE_BITMAP, 0, 0, 0);
  723. return SetBitmaps(hBitmapIn, crTransColorIn, hBitmapOut, crTransColorOut);
  724. } // End of SetBitmaps
  725. void CButtonST::DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rItem, CRect *rCaption, BOOL bIsPressed, BOOL bIsDisabled)
  726. {
  727. HDC hdcBmpMem = NULL;
  728. HBITMAP hbmOldBmp = NULL;
  729. HDC hdcMem = NULL;
  730. HBITMAP hbmT = NULL;
  731. BYTE byIndex = 0;
  732. // Select the bitmap to use
  733. if (m_bIsCheckBox == TRUE)
  734. {
  735. if (bIsPressed == TRUE)
  736. byIndex = 0;
  737. else
  738. byIndex = (m_csBitmaps[1].hBitmap == NULL ? 0 : 1);
  739. } // if
  740. else
  741. {
  742. if (m_bMouseOnButton == TRUE || bIsPressed == TRUE)
  743. byIndex = 0;
  744. else
  745. byIndex = (m_csBitmaps[1].hBitmap == NULL ? 0 : 1);
  746. } // else
  747. CRect rImage;
  748. PrepareImageRect(bHasTitle, rItem, rCaption, bIsPressed, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, &rImage);
  749. hdcBmpMem = ::CreateCompatibleDC(pDC->m_hDC);
  750. hbmOldBmp = (HBITMAP)::SelectObject(hdcBmpMem, m_csBitmaps[byIndex].hBitmap);
  751. hdcMem = ::CreateCompatibleDC(NULL);
  752. hbmT = (HBITMAP)::SelectObject(hdcMem, m_csBitmaps[byIndex].hMask);
  753. ::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);
  754. ::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);
  755. ::SelectObject(hdcMem, hbmT);
  756. ::DeleteDC(hdcMem);
  757. ::SelectObject(hdcBmpMem, hbmOldBmp);
  758. ::DeleteDC(hdcBmpMem);
  759. } // End of DrawTheBitmap
  760. HBITMAP CButtonST::CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor)
  761. {
  762. HBITMAP hMask = NULL;
  763. HDC hdcSrc = NULL;
  764. HDC hdcDest = NULL;
  765. HBITMAP hbmSrcT = NULL;
  766. HBITMAP hbmDestT = NULL;
  767. COLORREF crSaveBk;
  768. COLORREF crSaveDestText;
  769. hMask = ::CreateBitmap(dwWidth, dwHeight, 1, 1, NULL);
  770. if (hMask == NULL) return NULL;
  771. hdcSrc = ::CreateCompatibleDC(NULL);
  772. hdcDest = ::CreateCompatibleDC(NULL);
  773. hbmSrcT = (HBITMAP)::SelectObject(hdcSrc, hSourceBitmap);
  774. hbmDestT = (HBITMAP)::SelectObject(hdcDest, hMask);
  775. crSaveBk = ::SetBkColor(hdcSrc, crTransColor);
  776. ::BitBlt(hdcDest, 0, 0, dwWidth, dwHeight, hdcSrc, 0, 0, SRCCOPY);
  777. crSaveDestText = ::SetTextColor(hdcSrc, RGB(255, 255, 255));
  778. ::SetBkColor(hdcSrc,RGB(0, 0, 0));
  779. ::BitBlt(hdcSrc, 0, 0, dwWidth, dwHeight, hdcDest, 0, 0, SRCAND);
  780. SetTextColor(hdcDest, crSaveDestText);
  781. ::SetBkColor(hdcSrc, crSaveBk);
  782. ::SelectObject(hdcSrc, hbmSrcT);
  783. ::SelectObject(hdcDest, hbmDestT);
  784. ::DeleteDC(hdcSrc);
  785. ::DeleteDC(hdcDest);
  786. return hMask;
  787. } // End of CreateBitmapMask
  788. //
  789. // Parameters:
  790. // [IN] bHasTitle
  791. // TRUE if the button has a text
  792. // [IN] rpItem
  793. // A pointer to a RECT structure indicating the allowed paint area
  794. // [IN/OUT]rpTitle
  795. // A pointer to a CRect object indicating the paint area reserved for the
  796. // text. This structure will be modified if necessary.
  797. // [IN] bIsPressed
  798. // TRUE if the button is currently pressed
  799. // [IN] dwWidth
  800. // Width of the image (icon or bitmap)
  801. // [IN] dwHeight
  802. // Height of the image (icon or bitmap)
  803. // [OUT] rpImage
  804. // A pointer to a CRect object that will receive the area available to the image
  805. //
  806. void CButtonST::PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage)
  807. {
  808. CRect rBtn;
  809. rpImage->CopyRect(rpItem);
  810. switch (m_nAlign)
  811. {
  812. case ST_ALIGN_HORIZ:
  813. if (bHasTitle == FALSE /*spTitle->IsEmpty()*/)
  814. {
  815. // Center image horizontally
  816. rpImage->left += ((rpImage->Width() - dwWidth)/2);
  817. }
  818. else
  819. {
  820. // Image must be placed just inside the focus rect
  821. rpImage->left += 3;
  822. rpTitle->left += dwWidth + 3;
  823. }
  824. // Center image vertically
  825. rpImage->top += ((rpImage->Height() - dwHeight)/2);
  826. break;
  827. case ST_ALIGN_HORIZ_RIGHT:
  828. GetClientRect(&rBtn);
  829. if (bHasTitle == FALSE /*spTitle->IsEmpty()*/)
  830. {
  831. // Center image horizontally
  832. rpImage->left += ((rpImage->Width() - dwWidth)/2);
  833. }
  834. else
  835. {
  836. // Image must be placed just inside the focus rect
  837. rpTitle->right = rpTitle->Width() - dwWidth - 3;
  838. rpTitle->left = 3;
  839. rpImage->left = rBtn.right - dwWidth - 3;
  840. // Center image vertically
  841. rpImage->top += ((rpImage->Height() - dwHeight)/2);
  842. }
  843. break;
  844. case ST_ALIGN_VERT:
  845. // Center image horizontally
  846. rpImage->left += ((rpImage->Width() - dwWidth)/2);
  847. if (bHasTitle == FALSE /*spTitle->IsEmpty()*/)
  848. {
  849. // Center image vertically
  850. rpImage->top += ((rpImage->Height() - dwHeight)/2);
  851. }
  852. else
  853. {
  854. rpImage->top = 3;
  855. rpTitle->top += dwHeight;
  856. }
  857. break;
  858. }
  859. // If button is pressed then press image also
  860. if (bIsPressed == TRUE && m_bIsCheckBox == FALSE)
  861. rpImage->OffsetRect(1, 1);
  862. } // End of PrepareImageRect
  863. //
  864. // Parameters:
  865. // [IN] bRepaint
  866. // If TRUE the control will be repainted.
  867. // Return value:
  868. // BTNST_OK
  869. // Function executed successfully.
  870. //
  871. DWORD CButtonST::SetDefaultColors(BOOL bRepaint)
  872. {
  873. m_crColors[BTNST_COLOR_BK_IN] = ::GetSysColor(COLOR_BTNFACE);
  874. m_crColors[BTNST_COLOR_FG_IN] = ::GetSysColor(COLOR_BTNTEXT);
  875. m_crColors[BTNST_COLOR_BK_OUT] = ::GetSysColor(COLOR_BTNFACE);
  876. m_crColors[BTNST_COLOR_FG_OUT] = ::GetSysColor(COLOR_BTNTEXT);
  877. if (bRepaint == TRUE) Invalidate();
  878. return BTNST_OK;
  879. } // End of SetDefaultColors
  880. //
  881. // Parameters:
  882. // [IN] byColorIndex
  883. // Index of the color to set. This index is zero-based.
  884. // [IN] crColor
  885. // New color.
  886. // [IN] bRepaint
  887. // If TRUE the control will be repainted.
  888. //
  889. // Return value:
  890. // BTNST_OK
  891. // Function executed successfully.
  892. // BTNST_INVALIDINDEX
  893. // Invalid color index.
  894. //
  895. DWORD CButtonST::SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint)
  896. {
  897. if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;
  898. // Set new color
  899. m_crColors[byColorIndex] = crColor;
  900. if (bRepaint == TRUE) Invalidate();
  901. return BTNST_OK;
  902. } // End of SetColor
  903. //
  904. // Parameters:
  905. // [IN] byColorIndex
  906. // Index of the color to get. This index is zero-based.
  907. // [OUT] crpColor
  908. // A pointer to a COLORREF that will receive the color.
  909. //
  910. // Return value:
  911. // BTNST_OK
  912. // Function executed successfully.
  913. // BTNST_INVALIDINDEX
  914. // Invalid color index.
  915. //
  916. DWORD CButtonST::GetColor(BYTE byColorIndex, COLORREF* crpColor)
  917. {
  918. if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;
  919. // Get color
  920. *crpColor = m_crColors[byColorIndex];
  921. return BTNST_OK;
  922. } // End of GetColor
  923. //
  924. // Parameters:
  925. // [IN] lpszURL
  926. // Pointer to a null-terminated string that contains the URL.
  927. //
  928. // Return value:
  929. // BTNST_OK
  930. // Function executed successfully.
  931. //
  932. DWORD CButtonST::SetURL(LPCTSTR lpszURL)
  933. {
  934. if (lpszURL != NULL)
  935. {
  936. // Store the URL
  937. ::lstrcpyn(m_szURL, lpszURL, _MAX_PATH);
  938. } // if
  939. else
  940. {
  941. // Remove any existing URL
  942. ::ZeroMemory(&m_szURL, sizeof(m_szURL));
  943. } // else
  944. return BTNST_OK;
  945. } // End of SetURL
  946. void CButtonST::CancelHover()
  947. {
  948. // If our button is not flat then do nothing
  949. if (m_bIsFlat == FALSE) return;
  950. if (m_bMouseOnButton == TRUE)
  951. {
  952. m_bMouseOnButton = FALSE;
  953. Invalidate();
  954. } // if
  955. } // End of CancelHover
  956. // This function enable or disable the autorepeat feature.
  957. //
  958. // Parameters:
  959. // [IN] bSet
  960. // TRUE to enable autorepeat. FALSE to disable.
  961. // [IN] dwMilliseconds
  962. // Time (in milliseconds) between each button click.
  963. // If bSet is FALSE this parameter is ignored.
  964. //
  965. // Return value:
  966. // BTNST_OK
  967. // Function executed successfully.
  968. //
  969. DWORD CButtonST::SetAutoRepeat(BOOL bSet, DWORD dwMilliseconds)
  970. {
  971. m_bAutoRepeat = bSet;
  972. m_dwPeriodAutoRepeat = dwMilliseconds;
  973. return BTNST_OK;
  974. } // End of SetAutoRepeat
  975. // This function is called every time the button background needs to be painted.
  976. // If the button is in transparent mode this function will NOT be called.
  977. //
  978. // Parameters:
  979. // [IN] pDC
  980. // Pointer to a CDC object that indicates the device context.
  981. // [IN] pRect
  982. // Pointer to a CRect object that indicates the bounds of the
  983. // area to be painted.
  984. //
  985. // Return value:
  986. // BTNST_OK
  987. // Function executed successfully.
  988. //
  989. DWORD CButtonST::OnDrawBackground(CDC* pDC, LPCRECT pRect)
  990. {
  991. COLORREF crColor;
  992. if (m_bMouseOnButton || m_bIsPressed)
  993. crColor = m_crColors[BTNST_COLOR_BK_IN];
  994. else
  995. crColor = m_crColors[BTNST_COLOR_BK_OUT];
  996. CBrush brBackground(crColor);
  997. pDC->FillRect(pRect, &brBackground);
  998. return BTNST_OK;
  999. } // End of OnDrawBackground
  1000. // This function is called every time the button border needs to be painted.
  1001. // If the button is in standard (not flat) mode this function will NOT be called.
  1002. //
  1003. // Parameters:
  1004. // [IN] pDC
  1005. // Pointer to a CDC object that indicates the device context.
  1006. // [IN] pRect
  1007. // Pointer to a CRect object that indicates the bounds of the
  1008. // area to be painted.
  1009. //
  1010. // Return value:
  1011. // BTNST_OK
  1012. // Function executed successfully.
  1013. //
  1014. DWORD CButtonST::OnDrawBorder(CDC* pDC, LPCRECT pRect)
  1015. {
  1016. if (m_bIsPressed)
  1017. pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));
  1018. else
  1019. pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
  1020. return BTNST_OK;
  1021. } // End of OnDrawBorder
  1022. #undef ST_LIKEIE