// BaseProDlg.cpp : implementation file // #include "stdafx.h" #include "IDE.h" #include "BaseProDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern void DrawColorButton(LPDRAWITEMSTRUCT lpDIS,COLORREF clrButton); // LoadBMPImage - Loads a BMP file and creates a bitmap GDI object // also creates logical palette for it. // Returns - TRUE for success // sBMPFile - Full path of the BMP file // bitmap - The bitmap object to initialize // pPal - Will hold the logical palette. Can be NULL BOOL LoadBMPImage( LPCTSTR sBMPFile, CBitmap* bitmap, CPalette *pPal ) { CFile file; if( !file.Open( sBMPFile, CFile::modeRead) ) return FALSE; BITMAPFILEHEADER bmfHeader; // Read file header if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader)) return FALSE; // File type should be 'BM' if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B')) return FALSE; // Get length of the remainder of the file and allocate memory DWORD nPackedDIBLen = file.GetLength() - sizeof(BITMAPFILEHEADER); HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nPackedDIBLen); if (hDIB == 0) return FALSE; // Read the remainder of the bitmap file. if (file.Read((LPSTR)hDIB, nPackedDIBLen) != nPackedDIBLen ) { ::GlobalFree(hDIB); return FALSE; } BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ; BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ; // If bmiHeader.biClrUsed is zero we have to infer the number // of colors from the number of bits used to specify it. int nColors = bmiHeader.biClrUsed ? bmiHeader.biClrUsed : 1 << bmiHeader.biBitCount; LPVOID lpDIBBits; if( bmInfo.bmiHeader.biBitCount > 8 ) lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) + ((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0)); else lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors); // Create the logical palette if( pPal != NULL ) { // Create the palette if( nColors <= 256 ) { UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors); LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize]; pLP->palVersion = 0x300; pLP->palNumEntries = nColors; for( int i=0; i < nColors; i++) { pLP->palPalEntry[i].peRed = bmInfo.bmiColors[i].rgbRed; pLP->palPalEntry[i].peGreen = bmInfo.bmiColors[i].rgbGreen; pLP->palPalEntry[i].peBlue = bmInfo.bmiColors[i].rgbBlue; pLP->palPalEntry[i].peFlags = 0; } pPal->CreatePalette( pLP ); delete[] pLP; } } CClientDC dc(NULL); CPalette* pOldPalette = NULL; if( pPal ) { pOldPalette = dc.SelectPalette( pPal, FALSE ); dc.RealizePalette(); } HBITMAP hBmp = CreateDIBitmap( dc.m_hDC, // handle to device context &bmiHeader, // pointer to bitmap size and format data CBM_INIT, // initialization flag lpDIBBits, // pointer to initialization data &bmInfo, // pointer to bitmap color-format data DIB_RGB_COLORS); // color-data usage bitmap->Attach( hBmp ); if( pOldPalette ) { dc.SelectPalette( pOldPalette, FALSE ); } //CloseHandle(hBmp); ::GlobalFree(hDIB); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CBaseProDlg property page IMPLEMENT_DYNCREATE(CBaseProDlg, CPropertyPage) CBaseProDlg::CBaseProDlg(CWnd* pParent) : CPropertyPage(CBaseProDlg::IDD) { //{{AFX_DATA_INIT(CBaseProDlg) m_strCaption = _T(""); m_strLineType = _T(""); m_strLineWidth = _T(""); m_strShowCondition = _T(""); m_bDynShow = FALSE; m_bVariant = FALSE; //}}AFX_DATA_INIT m_bMoreEdit = false; } CBaseProDlg::~CBaseProDlg() { } void CBaseProDlg::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBaseProDlg) DDX_Text(pDX, IDC_CAPTION, m_strCaption); DDX_CBString(pDX, IDC_LINETYPE, m_strLineType); DDX_CBString(pDX, IDC_LINEWIDTH, m_strLineWidth); DDX_Text(pDX, IDC_SHOWCONDITION, m_strShowCondition); DDX_Check(pDX, IDC_DYNSHOW, m_bDynShow); DDX_Check(pDX, IDC_VARIANT, m_bVariant); DDX_Control(pDX, IDC_FILLTYPE, m_BitmapCombo); DDX_CBIndex(pDX, IDC_FILLTYPE, m_nFillMode); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CBaseProDlg, CPropertyPage) //{{AFX_MSG_MAP(CBaseProDlg) ON_BN_CLICKED(IDC_LINECOLOR, OnLinecolor) ON_BN_CLICKED(IDC_BACKCOLOR, OnBackcolor) ON_BN_CLICKED(IDC_FORECOLOR, OnForecolor) ON_BN_CLICKED(IDC_FONT, OnFont) ON_WM_DRAWITEM() ON_BN_CLICKED(IDC_FILLCOLOR, OnFillcolor) ON_BN_CLICKED(IDC_SELVAR, OnSelvar) ON_BN_CLICKED(IDC_SHOWEDIT, OnShowedit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBaseProDlg message handlers void CBaseProDlg::OnLinecolor() { CColorDialog dlg(m_clrLine); if(dlg.DoModal()==IDOK) { m_clrLine = dlg.GetColor(); CButton* pButton = (CButton *)GetDlgItem(IDC_LINECOLOR); pButton->ShowWindow(SW_HIDE); pButton->ShowWindow(SW_SHOW); } } void CBaseProDlg::OnBackcolor() { CColorDialog dlg(m_clrBack); if(dlg.DoModal()==IDOK) { m_clrBack = dlg.GetColor(); CButton* pButton = (CButton *)GetDlgItem(IDC_BACKCOLOR); pButton->ShowWindow(SW_HIDE); pButton->ShowWindow(SW_SHOW); } } void CBaseProDlg::OnForecolor() { CColorDialog dlg(m_clrFore); if(dlg.DoModal()==IDOK) { m_clrFore = dlg.GetColor(); CButton* pButton = (CButton *)GetDlgItem(IDC_FORECOLOR); pButton->ShowWindow(SW_HIDE); pButton->ShowWindow(SW_SHOW); } } void CBaseProDlg::OnFont() { CFontDialog dlg(&m_logfont); dlg.DoModal(); } void CBaseProDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { switch(nIDCtl) { case IDC_FORECOLOR: DrawColorButton(lpDrawItemStruct,m_clrFore); break; case IDC_BACKCOLOR: DrawColorButton(lpDrawItemStruct,m_clrBack); break; case IDC_LINECOLOR: DrawColorButton(lpDrawItemStruct,m_clrLine); break; case IDC_FILLCOLOR: DrawColorButton(lpDrawItemStruct,m_clrFill); break; case IDC_FONTSHOW: CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rectButton = lpDrawItemStruct->rcItem; UINT nStyle = DFCS_BUTTONPUSH; if(lpDrawItemStruct->itemState & ODS_SELECTED) nStyle |= DFCS_PUSHED; if(lpDrawItemStruct->itemState & ODS_DISABLED) nStyle |= DFCS_INACTIVE; pDC->DrawFrameControl(rectButton,DFC_BUTTON,nStyle); CRect rectColor = lpDrawItemStruct->rcItem; if(lpDrawItemStruct->itemState & ODS_SELECTED) rectColor.InflateRect(0,0,0,0); pDC->SelectStockObject(BLACK_PEN); pDC->SetTextColor( m_clrFore ); CFont font; font.CreateFontIndirect(&m_logfont); pDC->SelectObject(font); CRect m_rect(0, 0, 100, 40); int nX0 = (m_rect.left+m_rect.right) / 2; int nY0 = (m_rect.top+m_rect.bottom) / 2; CSize sizeText = pDC->GetTextExtent(g_strStoneuTech); int nInterval = sizeText.cy / 2; int nYText = nY0 - nInterval + 1; int nXText; pDC->SetTextAlign(TA_CENTER|TA_TOP); nXText = nX0; pDC->SetBkMode(TRANSPARENT); pDC->TextOut(nXText,nYText, g_strStoneuTech); //2011-10-31 add //DeleteObject( pDC );//???? DeleteObject( font ); } CPropertyPage::OnDrawItem(nIDCtl, lpDrawItemStruct); } void CBaseProDlg::OnFillcolor() { CColorDialog dlg(m_clrFill); if(dlg.DoModal()==IDOK) { m_clrFill = dlg.GetColor(); CButton* pButton = (CButton *)GetDlgItem(IDC_FILLCOLOR); pButton->ShowWindow(SW_HIDE); pButton->ShowWindow(SW_SHOW); } } BOOL CBaseProDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); CBitmap *bitmap; CPalette pPal; // 把目录设置到位图目录 bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\blank.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\full.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\hline.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\vline.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\fflash.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\flash.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\grid.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\fgrid.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\left.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\right.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\middle.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\top.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\bottom.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); bitmap = new CBitmap; LoadBMPImage(CString(g_strDirectory) + "\\Bitmap\\center.bmp", bitmap, &pPal); m_vtbitmapList.push_back(bitmap); for (int i=0; i<(int)m_vtbitmapList.size(); i++) m_BitmapCombo.AddBitmap(m_vtbitmapList[i]); m_BitmapCombo.SetCurSel( m_nFillMode ); if( m_bMoreEdit ) { GetDlgItem(IDC_VARIANT)->EnableWindow( false ); GetDlgItem(IDC_CAPTION)->EnableWindow( false ); GetDlgItem(IDC_SELVAR)->EnableWindow( false ); GetDlgItem(IDC_DYNSHOW)->EnableWindow( false ); GetDlgItem(IDC_SHOWCONDITION)->EnableWindow( false ); GetDlgItem(IDC_SHOWEDIT)->EnableWindow( false ); } return TRUE; } void CBaseProDlg::OnSelvar() { } void CBaseProDlg::OnShowedit() { }