SelTransparentColorDlg.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SelTransparentColorDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CreateGIF.h"
  5. #include "SelTransparentColorDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSelTransparentColorDlg dialog
  13. CSelTransparentColorDlg::CSelTransparentColorDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSelTransparentColorDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CSelTransparentColorDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_transparentColorIndex = 0;
  20. }
  21. void CSelTransparentColorDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CSelTransparentColorDlg)
  25. // NOTE: the ClassWizard will add DDX and DDV calls here
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CSelTransparentColorDlg, CDialog)
  29. //{{AFX_MSG_MAP(CSelTransparentColorDlg)
  30. ON_WM_CTLCOLOR()
  31. ON_WM_LBUTTONDOWN()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CSelTransparentColorDlg message handlers
  36. void CSelTransparentColorDlg::SetBitmap(BYTE *pData,BYTE*palette,int nWidth,int nHeight)
  37. {
  38. m_pData = pData;
  39. m_palette = palette;
  40. m_nWidth = nWidth;
  41. m_nHeight = nHeight;
  42. }
  43. HBRUSH CSelTransparentColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  44. {
  45. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  46. // TODO: Change any attributes of the DC here
  47. if(pWnd->GetDlgCtrlID() == IDC_STATIC_BMP)
  48. {
  49. for(int i=0; i<m_nHeight; i++)
  50. {
  51. for(int j=0; j<m_nWidth; j++)
  52. {
  53. int nIndex = m_pData[i*m_nWidth+j]*3;
  54. pDC->SetPixel(j,i,RGB(m_palette[nIndex],m_palette[nIndex+1],m_palette[nIndex+2]));
  55. }
  56. }
  57. }
  58. // TODO: Return a different brush if the default is not desired
  59. return hbr;
  60. }
  61. void CSelTransparentColorDlg::OnLButtonDown(UINT nFlags, CPoint point)
  62. {
  63. // TODO: Add your message handler code here and/or call default
  64. CPoint pt;
  65. GetCursorPos(&pt);
  66. GetDlgItem(IDC_STATIC_BMP)->ScreenToClient(&pt);
  67. m_transparentColorIndex = m_pData[pt.y*m_nWidth+pt.x];
  68. CDialog::OnLButtonDown(nFlags, point);
  69. }
  70. void CSelTransparentColorDlg::OnOK()
  71. {
  72. // TODO: Add extra validation here
  73. CDialog::OnOK();
  74. }