BaseProDlg.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. // BaseProDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "BaseProDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. extern void DrawColorButton(LPDRAWITEMSTRUCT lpDIS,COLORREF clrButton);
  12. // LoadBMPImage - Loads a BMP file and creates a bitmap GDI object
  13. // also creates logical palette for it.
  14. // Returns - TRUE for success
  15. // sBMPFile - Full path of the BMP file
  16. // bitmap - The bitmap object to initialize
  17. // pPal - Will hold the logical palette. Can be NULL
  18. BOOL LoadBMPImage( LPCTSTR sBMPFile, CBitmap* bitmap, CPalette *pPal )
  19. {
  20. CFile file;
  21. if( !file.Open( sBMPFile, CFile::modeRead) )
  22. return FALSE;
  23. BITMAPFILEHEADER bmfHeader;
  24. // Read file header
  25. if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
  26. return FALSE;
  27. // File type should be 'BM'
  28. if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
  29. return FALSE;
  30. // Get length of the remainder of the file and allocate memory
  31. DWORD nPackedDIBLen = file.GetLength() - sizeof(BITMAPFILEHEADER);
  32. HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nPackedDIBLen);
  33. if (hDIB == 0)
  34. return FALSE;
  35. // Read the remainder of the bitmap file.
  36. if (file.Read((LPSTR)hDIB, nPackedDIBLen) != nPackedDIBLen )
  37. {
  38. ::GlobalFree(hDIB);
  39. return FALSE;
  40. }
  41. BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ;
  42. BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
  43. // If bmiHeader.biClrUsed is zero we have to infer the number
  44. // of colors from the number of bits used to specify it.
  45. int nColors = bmiHeader.biClrUsed ? bmiHeader.biClrUsed :
  46. 1 << bmiHeader.biBitCount;
  47. LPVOID lpDIBBits;
  48. if( bmInfo.bmiHeader.biBitCount > 8 )
  49. lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) +
  50. ((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
  51. else
  52. lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
  53. // Create the logical palette
  54. if( pPal != NULL )
  55. {
  56. // Create the palette
  57. if( nColors <= 256 )
  58. {
  59. UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
  60. LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
  61. pLP->palVersion = 0x300;
  62. pLP->palNumEntries = nColors;
  63. for( int i=0; i < nColors; i++)
  64. {
  65. pLP->palPalEntry[i].peRed = bmInfo.bmiColors[i].rgbRed;
  66. pLP->palPalEntry[i].peGreen = bmInfo.bmiColors[i].rgbGreen;
  67. pLP->palPalEntry[i].peBlue = bmInfo.bmiColors[i].rgbBlue;
  68. pLP->palPalEntry[i].peFlags = 0;
  69. }
  70. pPal->CreatePalette( pLP );
  71. delete[] pLP;
  72. }
  73. }
  74. CClientDC dc(NULL);
  75. CPalette* pOldPalette = NULL;
  76. if( pPal )
  77. {
  78. pOldPalette = dc.SelectPalette( pPal, FALSE );
  79. dc.RealizePalette();
  80. }
  81. HBITMAP hBmp = CreateDIBitmap( dc.m_hDC, // handle to device context
  82. &bmiHeader, // pointer to bitmap size and format data
  83. CBM_INIT, // initialization flag
  84. lpDIBBits, // pointer to initialization data
  85. &bmInfo, // pointer to bitmap color-format data
  86. DIB_RGB_COLORS); // color-data usage
  87. bitmap->Attach( hBmp );
  88. if( pOldPalette )
  89. {
  90. dc.SelectPalette( pOldPalette, FALSE );
  91. }
  92. //CloseHandle(hBmp);
  93. ::GlobalFree(hDIB);
  94. return TRUE;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CBaseProDlg property page
  98. IMPLEMENT_DYNCREATE(CBaseProDlg, CPropertyPage)
  99. CBaseProDlg::CBaseProDlg(CWnd* pParent) : CPropertyPage(CBaseProDlg::IDD)
  100. {
  101. //{{AFX_DATA_INIT(CBaseProDlg)
  102. m_strCaption = _T("");
  103. m_strLineType = _T("");
  104. m_strLineWidth = _T("");
  105. m_strShowCondition = _T("");
  106. m_bDynShow = FALSE;
  107. m_bVariant = FALSE;
  108. //}}AFX_DATA_INIT
  109. m_bMoreEdit = false;
  110. }
  111. CBaseProDlg::~CBaseProDlg()
  112. {
  113. }
  114. void CBaseProDlg::DoDataExchange(CDataExchange* pDX)
  115. {
  116. CPropertyPage::DoDataExchange(pDX);
  117. //{{AFX_DATA_MAP(CBaseProDlg)
  118. DDX_Text(pDX, IDC_CAPTION, m_strCaption);
  119. DDX_CBString(pDX, IDC_LINETYPE, m_strLineType);
  120. DDX_CBString(pDX, IDC_LINEWIDTH, m_strLineWidth);
  121. DDX_Text(pDX, IDC_SHOWCONDITION, m_strShowCondition);
  122. DDX_Check(pDX, IDC_DYNSHOW, m_bDynShow);
  123. DDX_Check(pDX, IDC_VARIANT, m_bVariant);
  124. DDX_Control(pDX, IDC_FILLTYPE, m_BitmapCombo);
  125. DDX_CBIndex(pDX, IDC_FILLTYPE, m_nFillMode);
  126. //}}AFX_DATA_MAP
  127. }
  128. BEGIN_MESSAGE_MAP(CBaseProDlg, CPropertyPage)
  129. //{{AFX_MSG_MAP(CBaseProDlg)
  130. ON_BN_CLICKED(IDC_LINECOLOR, OnLinecolor)
  131. ON_BN_CLICKED(IDC_BACKCOLOR, OnBackcolor)
  132. ON_BN_CLICKED(IDC_FORECOLOR, OnForecolor)
  133. ON_BN_CLICKED(IDC_FONT, OnFont)
  134. ON_WM_DRAWITEM()
  135. ON_BN_CLICKED(IDC_FILLCOLOR, OnFillcolor)
  136. ON_BN_CLICKED(IDC_SELVAR, OnSelvar)
  137. ON_BN_CLICKED(IDC_SHOWEDIT, OnShowedit)
  138. //}}AFX_MSG_MAP
  139. END_MESSAGE_MAP()
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CBaseProDlg message handlers
  142. void CBaseProDlg::OnLinecolor()
  143. {
  144. CColorDialog dlg(m_clrLine);
  145. if(dlg.DoModal()==IDOK)
  146. {
  147. m_clrLine = dlg.GetColor();
  148. CButton* pButton = (CButton *)GetDlgItem(IDC_LINECOLOR);
  149. pButton->ShowWindow(SW_HIDE);
  150. pButton->ShowWindow(SW_SHOW);
  151. }
  152. }
  153. void CBaseProDlg::OnBackcolor()
  154. {
  155. CColorDialog dlg(m_clrBack);
  156. if(dlg.DoModal()==IDOK)
  157. {
  158. m_clrBack = dlg.GetColor();
  159. CButton* pButton = (CButton *)GetDlgItem(IDC_BACKCOLOR);
  160. pButton->ShowWindow(SW_HIDE);
  161. pButton->ShowWindow(SW_SHOW);
  162. }
  163. }
  164. void CBaseProDlg::OnForecolor()
  165. {
  166. CColorDialog dlg(m_clrFore);
  167. if(dlg.DoModal()==IDOK)
  168. {
  169. m_clrFore = dlg.GetColor();
  170. CButton* pButton = (CButton *)GetDlgItem(IDC_FORECOLOR);
  171. pButton->ShowWindow(SW_HIDE);
  172. pButton->ShowWindow(SW_SHOW);
  173. }
  174. }
  175. void CBaseProDlg::OnFont()
  176. {
  177. CFontDialog dlg(&m_logfont);
  178. dlg.DoModal();
  179. }
  180. void CBaseProDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
  181. {
  182. switch(nIDCtl)
  183. {
  184. case IDC_FORECOLOR:
  185. DrawColorButton(lpDrawItemStruct,m_clrFore);
  186. break;
  187. case IDC_BACKCOLOR:
  188. DrawColorButton(lpDrawItemStruct,m_clrBack);
  189. break;
  190. case IDC_LINECOLOR:
  191. DrawColorButton(lpDrawItemStruct,m_clrLine);
  192. break;
  193. case IDC_FILLCOLOR:
  194. DrawColorButton(lpDrawItemStruct,m_clrFill);
  195. break;
  196. case IDC_FONTSHOW:
  197. CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
  198. CRect rectButton = lpDrawItemStruct->rcItem;
  199. UINT nStyle = DFCS_BUTTONPUSH;
  200. if(lpDrawItemStruct->itemState & ODS_SELECTED) nStyle |= DFCS_PUSHED;
  201. if(lpDrawItemStruct->itemState & ODS_DISABLED) nStyle |= DFCS_INACTIVE;
  202. pDC->DrawFrameControl(rectButton,DFC_BUTTON,nStyle);
  203. CRect rectColor = lpDrawItemStruct->rcItem;
  204. if(lpDrawItemStruct->itemState & ODS_SELECTED) rectColor.InflateRect(0,0,0,0);
  205. pDC->SelectStockObject(BLACK_PEN);
  206. pDC->SetTextColor( m_clrFore );
  207. CFont font;
  208. font.CreateFontIndirect(&m_logfont);
  209. pDC->SelectObject(font);
  210. CRect m_rect(0, 0, 100, 40);
  211. int nX0 = (m_rect.left+m_rect.right) / 2;
  212. int nY0 = (m_rect.top+m_rect.bottom) / 2;
  213. CSize sizeText = pDC->GetTextExtent(g_strStoneuTech);
  214. int nInterval = sizeText.cy / 2;
  215. int nYText = nY0 - nInterval + 1;
  216. int nXText;
  217. pDC->SetTextAlign(TA_CENTER|TA_TOP);
  218. nXText = nX0;
  219. pDC->SetBkMode(TRANSPARENT);
  220. pDC->TextOut(nXText,nYText, g_strStoneuTech);
  221. //2011-10-31 add
  222. //DeleteObject( pDC );//????
  223. DeleteObject( font );
  224. }
  225. CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct);
  226. }
  227. void CBaseProDlg::OnFillcolor()
  228. {
  229. CColorDialog dlg(m_clrFill);
  230. if(dlg.DoModal()==IDOK)
  231. {
  232. m_clrFill = dlg.GetColor();
  233. CButton* pButton = (CButton *)GetDlgItem(IDC_FILLCOLOR);
  234. pButton->ShowWindow(SW_HIDE);
  235. pButton->ShowWindow(SW_SHOW);
  236. }
  237. }
  238. BOOL CBaseProDlg::OnInitDialog()
  239. {
  240. CPropertyPage::OnInitDialog();
  241. CBitmap *bitmap; CPalette pPal;
  242. // °ÑĿ¼ÉèÖõ½Î»Í¼Ä¿Â¼
  243. bitmap = new CBitmap;
  244. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\blank.bmp", bitmap, &pPal);
  245. m_vtbitmapList.push_back(bitmap);
  246. bitmap = new CBitmap;
  247. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\full.bmp", bitmap, &pPal);
  248. m_vtbitmapList.push_back(bitmap);
  249. bitmap = new CBitmap;
  250. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\hline.bmp", bitmap, &pPal);
  251. m_vtbitmapList.push_back(bitmap);
  252. bitmap = new CBitmap;
  253. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\vline.bmp", bitmap, &pPal);
  254. m_vtbitmapList.push_back(bitmap);
  255. bitmap = new CBitmap;
  256. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\fflash.bmp", bitmap, &pPal);
  257. m_vtbitmapList.push_back(bitmap);
  258. bitmap = new CBitmap;
  259. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\flash.bmp", bitmap, &pPal);
  260. m_vtbitmapList.push_back(bitmap);
  261. bitmap = new CBitmap;
  262. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\grid.bmp", bitmap, &pPal);
  263. m_vtbitmapList.push_back(bitmap);
  264. bitmap = new CBitmap;
  265. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\fgrid.bmp", bitmap, &pPal);
  266. m_vtbitmapList.push_back(bitmap);
  267. bitmap = new CBitmap;
  268. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\left.bmp", bitmap, &pPal);
  269. m_vtbitmapList.push_back(bitmap);
  270. bitmap = new CBitmap;
  271. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\right.bmp", bitmap, &pPal);
  272. m_vtbitmapList.push_back(bitmap);
  273. bitmap = new CBitmap;
  274. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\middle.bmp", bitmap, &pPal);
  275. m_vtbitmapList.push_back(bitmap);
  276. bitmap = new CBitmap;
  277. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\top.bmp", bitmap, &pPal);
  278. m_vtbitmapList.push_back(bitmap);
  279. bitmap = new CBitmap;
  280. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\bottom.bmp", bitmap, &pPal);
  281. m_vtbitmapList.push_back(bitmap);
  282. bitmap = new CBitmap;
  283. LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\center.bmp", bitmap, &pPal);
  284. m_vtbitmapList.push_back(bitmap);
  285. for (int i=0; i<(int)m_vtbitmapList.size(); i++)
  286. m_BitmapCombo.AddBitmap(m_vtbitmapList[i]);
  287. m_BitmapCombo.SetCurSel( m_nFillMode );
  288. if( m_bMoreEdit )
  289. {
  290. GetDlgItem(IDC_VARIANT)->EnableWindow( false );
  291. GetDlgItem(IDC_CAPTION)->EnableWindow( false );
  292. GetDlgItem(IDC_SELVAR)->EnableWindow( false );
  293. GetDlgItem(IDC_DYNSHOW)->EnableWindow( false );
  294. GetDlgItem(IDC_SHOWCONDITION)->EnableWindow( false );
  295. GetDlgItem(IDC_SHOWEDIT)->EnableWindow( false );
  296. }
  297. return TRUE;
  298. }
  299. void CBaseProDlg::OnSelvar()
  300. {
  301. }
  302. void CBaseProDlg::OnShowedit()
  303. {
  304. }