⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontsviewdlg.cpp

📁 字模信息的提取与显示
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	*pResult = 0;
}


void CFontsViewDlg::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if(this->pbmpinfo!=NULL)
		delete []this->pbmpinfo;
	if(this->pfileinfo!=NULL)
		delete []this->pfileinfo;
	if(this->pBuf!=NULL)
		delete []this->pBuf;

	CDialog::OnClose();
}

void CFontsViewDlg::FormBitmapInfo(int nWidth, int nHeight, int nBits)
{
	if(this->pbmpinfo!=NULL)
		delete []this->pbmpinfo;
	this->pbmpinfo=(LPBITMAPINFO)(new BYTE[sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*BITSTABLE[nBits-1]]);
	this->pbmpinfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	this->pbmpinfo->bmiHeader.biWidth=nWidth;
	this->pbmpinfo->bmiHeader.biHeight=-nHeight;
	this->pbmpinfo->bmiHeader.biPlanes=1;
	this->pbmpinfo->bmiHeader.biBitCount=nBits==1?1:8;
	this->pbmpinfo->bmiHeader.biCompression=BI_RGB;
	this->pbmpinfo->bmiHeader.biSizeImage=0;
	this->pbmpinfo->bmiHeader.biXPelsPerMeter=0;
	this->pbmpinfo->bmiHeader.biYPelsPerMeter=0;
	this->pbmpinfo->bmiHeader.biClrUsed=BITSTABLE[nBits-1];
	this->pbmpinfo->bmiHeader.biClrImportant=BITSTABLE[nBits-1];
	RGBQUAD* pquad=(new RGBQUAD[BITSTABLE[nBits-1]]);
	if(nBits==1)
	{	if(this->m_bCheckReverse==false)
	  {
		(*pquad).rgbRed=255;
		(*pquad).rgbGreen=255;
		(*pquad).rgbBlue=255;
		(*pquad).rgbReserved=0;
		(*(pquad+1)).rgbRed=0;
		(*(pquad+1)).rgbGreen=0;
		(*(pquad+1)).rgbBlue=0;
		(*(pquad+1)).rgbReserved=0;
	  }
	else
	  {
		(*pquad).rgbRed=0;
		(*pquad).rgbGreen=0;
		(*pquad).rgbBlue=0;
		(*pquad).rgbReserved=0;
		(*(pquad+1)).rgbRed=255;
		(*(pquad+1)).rgbGreen=255;
		(*(pquad+1)).rgbBlue=255;
		(*(pquad+1)).rgbReserved=0;

	  }
	}
	else
	{  if(this->m_bCheckReverse==false)
		{
			for(int i=0;i<BITSTABLE[nBits-1];i++)
			{
				(*(pquad+i)).rgbRed=(*(pquad+i)).rgbGreen=(*(pquad+i)).rgbBlue=255-255*i/(BITSTABLE[nBits-1]-1);
				(*(pquad+i)).rgbReserved=0;

			}
		}
		else
		{
			    for(int i=0;i<BITSTABLE[nBits-1];i++)
			{
				(*(pquad+i)).rgbRed=(*(pquad+i)).rgbGreen=(*(pquad+i)).rgbBlue=255*i/(BITSTABLE[nBits-1]-1);
				
				(*(pquad+i)).rgbReserved=0;

			}

		}
	}
	memcpy(&this->pbmpinfo->bmiColors,pquad,sizeof(RGBQUAD)*BITSTABLE[nBits-1]);
	delete []pquad;
}

void CFontsViewDlg::FormFileHeader(int nWidth, int nHeight,int nBits)
{
	
	
		if(this->pfileinfo!=NULL)
			delete []this->pfileinfo;
		this->pfileinfo=(LPBITMAPFILEHEADER)new BYTE[sizeof(BITMAPFILEHEADER)];
		this->pfileinfo->bfType=*(WORD*)(&"BM");
		this->pfileinfo->bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*BITSTABLE[nBits-1];
		this->pfileinfo->bfSize=this->pfileinfo->bfOffBits+this->charLineW*nHeight;
	
	
}

void CFontsViewDlg::OnBnClickedButtonSave()
{
    
	CString strfile; 
	CFileDialog cfd(FALSE,".bmp","未命名.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"BMP files(*.bmp)|*.bmp|All files(*.*)|*.*||",this);
	 if(cfd.DoModal()==IDOK)
	 {
		 strfile=cfd.GetPathName();

	 }
	 if(strfile.IsEmpty())
	 {
		 ::AfxMessageBox("请输入所要保存的文件名!");
		 return ;
	 }
	 CFile cf;
	 cf.Open(strfile,CFile::modeCreate|CFile::modeWrite);
	 this->FormFileHeader(this->m_intPixX,this->m_intPixY,this->m_intBits);
	 cf.Write(this->pfileinfo,sizeof(BITMAPFILEHEADER));
	 cf.Write(this->pbmpinfo,sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*BITSTABLE[this->m_intBits-1]);
	 cf.Write(this->pBuf,this->charLineW*this->m_intPixY);
	 cf.Close();
	 
	 


	// TODO: 在此添加控件通知处理程序代码
}

void CFontsViewDlg::ShowFontChar(CDC* pdc)
{
	if(this->pBuf!=NULL)
	{
	        CRect rect;
			this->GetDlgItem(IDC_STATIC_PIC)->GetWindowRect(&rect);
			CDC memdc;
			memdc.CreateCompatibleDC(pdc);
			CBitmap nbitmap,*poldbitmap;
			nbitmap.CreateCompatibleBitmap(pdc,rect.Width(),rect.Height());
			poldbitmap=memdc.SelectObject(&nbitmap);
			if(this->m_bCheckReverse==false)
			memdc.FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(255,255,255));
			::StretchDIBits(memdc.m_hDC,-this->m_intScrollHPos,-this->m_intScrollVPos,this->m_intPixX,this->m_intPixY,0,0,this->m_intPixX,this->m_intPixY,this->pBuf,this->pbmpinfo,DIB_RGB_COLORS,SRCCOPY);
			
			pdc->BitBlt(0,0,rect.Width(),rect.Height(),&memdc,0,0,SRCCOPY);
			memdc.DeleteDC();
			
	}
}

void CFontsViewDlg::OnBnClickedCheckReverse()
{
	// TODO: 在此添加控件通知处理程序代码
	this->m_bCheckReverse=(bool)this->m_ctlBtnReverse.GetCheck();
	this->OnLbnSelchangeLfonts();
}

void CFontsViewDlg::ShowVHScrollBar(void)
{
	CRect rect;
	GetDlgItem(IDC_STATIC_PIC)->GetWindowRect(&rect);
	if(rect.Width()<this->m_intPixX) 
	{	
		SCROLLINFO info;
   info.cbSize = sizeof(SCROLLINFO);     
   info.fMask = SIF_ALL;     
   info.nMin = 0;     
   info.nMax = this->m_intPixX-rect.Width()+50; 
   info.nPage = 50;     
   info.nPos = 0;    
   info.nTrackPos = 10;


		
   this->m_ctlScrollH.SetScrollInfo(&info);
   this->m_ctlScrollH.SetScrollPos(this->m_intScrollHPos);
		this->m_ctlScrollH.EnableScrollBar(ESB_ENABLE_BOTH );
		this->m_ctlScrollH.ShowWindow(SW_SHOW);
	}
	else
         this->m_ctlScrollH.ShowWindow(SW_HIDE);
	if(rect.Height()<this->m_intPixY)
	{
		SCROLLINFO info;
   info.cbSize = sizeof(SCROLLINFO);     
   info.fMask = SIF_ALL;     
   info.nMin = 0;     
   info.nMax = this->m_intPixY-rect.Height()+50; 
   info.nPage = 50;     
   info.nPos = 0;    
   info.nTrackPos = 10;
   this->m_ctlScrollV.SetScrollInfo(&info);
		this->m_ctlScrollV.SetScrollPos(this->m_intScrollHPos);
		this->m_ctlScrollV.EnableScrollBar(ESB_ENABLE_BOTH );
		this->m_ctlScrollV.ShowWindow(SW_SHOW);
	}
	else
		 this->m_ctlScrollV.ShowWindow(SW_HIDE);

}

void CFontsViewDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	if(pScrollBar==&this->m_ctlScrollH)
	{  
		
		 int minpos;
        int maxpos;
        pScrollBar->GetScrollRange(&minpos, &maxpos); 
       maxpos = pScrollBar->GetScrollLimit();

       // Get the current position of scroll box.
       int curpos = pScrollBar->GetScrollPos();

      // Determine the new position of scroll box.
   switch (nSBCode)
   {
   case SB_LEFT:      // Scroll to far left.
      curpos = minpos;
      break;

   case SB_RIGHT:      // Scroll to far right.
      curpos = maxpos;
      break;

   case SB_ENDSCROLL:   // End scroll.
      break;

   case SB_LINELEFT:      // Scroll left.
      if (curpos > minpos)
         curpos--;
      break;

   case SB_LINERIGHT:   // Scroll right.
      if (curpos < maxpos)
         curpos++;
      break;

   case SB_PAGELEFT:    // Scroll one page left.
   {
      // Get the page size. 
      SCROLLINFO   info;
      pScrollBar->GetScrollInfo(&info, SIF_ALL);
   
      if (curpos > minpos)
      curpos = max(minpos, curpos - (int) info.nPage);
   }
      break;

   case SB_PAGERIGHT:      // Scroll one page right.
   {
      // Get the page size. 
      SCROLLINFO   info;
      pScrollBar->GetScrollInfo(&info, SIF_ALL);

      if (curpos < maxpos)
         curpos = min(maxpos, curpos + (int) info.nPage);
   }
      break;

   case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
      curpos = nPos;      // of the scroll box at the end of the drag operation.
      break;

   case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
      curpos = nPos;     // position that the scroll box has been dragged to.
      break;
   }

   // Set the new position of the thumb (scroll box).
   pScrollBar->SetScrollPos(curpos);
   this->m_intScrollHPos=curpos;
  this->OnPaint();
		
	}

	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CFontsViewDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	if(pScrollBar==&this->m_ctlScrollV)
	{  
		
		 int minpos;
        int maxpos;
        pScrollBar->GetScrollRange(&minpos, &maxpos); 
       maxpos = pScrollBar->GetScrollLimit();

       // Get the current position of scroll box.
       int curpos = pScrollBar->GetScrollPos();

      // Determine the new position of scroll box.
   switch (nSBCode)
   {
   case SB_LEFT:      // Scroll to far left.
      curpos = minpos;
      break;

   case SB_RIGHT:      // Scroll to far right.
      curpos = maxpos;
      break;

   case SB_ENDSCROLL:   // End scroll.
      break;

   case SB_LINELEFT:      // Scroll left.
      if (curpos > minpos)
         curpos--;
      break;

   case SB_LINERIGHT:   // Scroll right.
      if (curpos < maxpos)
         curpos++;
      break;

   case SB_PAGELEFT:    // Scroll one page left.
   {
      // Get the page size. 
      SCROLLINFO   info;
      pScrollBar->GetScrollInfo(&info, SIF_ALL);
   
      if (curpos > minpos)
      curpos = max(minpos, curpos - (int) info.nPage);
   }
      break;

   case SB_PAGERIGHT:      // Scroll one page right.
   {
      // Get the page size. 
      SCROLLINFO   info;
      pScrollBar->GetScrollInfo(&info, SIF_ALL);

      if (curpos < maxpos)
         curpos = min(maxpos, curpos + (int) info.nPage);
   }
      break;

   case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
      curpos = nPos;      // of the scroll box at the end of the drag operation.
      break;

   case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
      curpos = nPos;     // position that the scroll box has been dragged to.
      break;
   }

   // Set the new position of the thumb (scroll box).
   pScrollBar->SetScrollPos(curpos);
   this->m_intScrollVPos=curpos;

  this->OnPaint();
		
	}

	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CFontsViewDlg::OnCbnSelchangeComboNbits()
{
	// TODO: 在此添加控件通知处理程序代码
	int i=this->m_ctlComboNbits.GetCurSel();
	if(i!=CB_ERR)
		this->m_intBits=i+1;
	this->OnLbnSelchangeLfonts();
}

void CFontsViewDlg::OnEnChangeEditHeight()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	this->UpdateData(1);
	this->m_slider_height.SetPos(this->m_intHeight);
	this->OnLbnSelchangeLfonts();
}

void CFontsViewDlg::OnEnChangeEditBold()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码

	this->UpdateData(1);
	this->m_slider_bold.SetPos(this->m_intBold);
	this->OnLbnSelchangeLfonts();
}

void CFontsViewDlg::OnEnChangeEditAngle()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	this->UpdateData(1);
	this->m_slider_angle.SetPos(this->m_intAngle);
	this->OnLbnSelchangeLfonts();
}

HBRUSH CFontsViewDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何属性
	if(pWnd->GetDlgCtrlID()==IDC_STATIC_STATUS)
	{
		if(this->m_strStatus.Compare("正常!")!=0)
		pDC->SetTextColor(RGB(255,0,0));
		
	}
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
}

void CFontsViewDlg::OnEnChangeEditPixx()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -