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

📄 dnwdlg.cpp

📁 该软件的主要功能是用鼠标就能“写”出常用的汉字
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DNWDlg.cpp : implementation file
//
 
#include "stdafx.h"
#include "DNW.h"
#include"bihua.h"
#include"pinyin.h"
#include "DNWDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int lon=145,wid=146;
int Startx=32,Starty=43;
CPoint down_point,up_point,cur_point;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#define FONTF "data\\hzk24f"//标准24点阵仿宋体汉字字库
#define FONTS "data\\hzk24s"//标准24点阵宋体汉字字库
#define FONTH "data\\hzk24h"//标准24点阵黑体汉字字库
#define FONTK "data\\hzk24k"//标准24点阵楷体汉字字库
#define FONTT "data\\hzk24t"//标准24点阵符号字库
CFile cf;CString hzfile;BOOL bOpenOK;

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDNWDlg dialog
CDNWDlg::CDNWDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDNWDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDNWDlg)
	m_hzfind = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	for (i=0;i<24;i++) for (j=0;j<24;j++) zm[i][j]=0;
	qh=16;wh=1; //初始化
}


void ToggleTopMost(
CWnd *pWnd)
{
ASSERT_VALID(pWnd);
//pWnd->SetWindowPos(pWnd->GetStyle()&WS_EX_TOPMOST)?&wndNoTopMOST:&wndTopMost,0,0,0,0,SSP_NOSIZE|WSP_NOMOVE);
}



void CDNWDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDNWDlg)
	DDX_Control(pDX, IDC_EDIT4, m_zk);
	DDX_Control(pDX, IDC_COMBO1, m_ftlist);
	DDX_Control(pDX, IDC_LIST1, m_show);
	DDX_Control(pDX, IDC_EDIT3, m_hzcount);
	DDX_Control(pDX, IDC_EDIT1, m_hzs);
	DDX_Control(pDX, IDC_SPIN3, m_counting);
	DDX_Control(pDX, IDC_EDIT2, m_cot);
	DDX_Control(pDX, IDC_3, m_font);
	DDX_Control(pDX, IDC_2, m_buff);
	DDX_Control(pDX, IDC_1, m_user);
	DDX_Text(pDX, IDC_EDIT3, m_hzfind);
	DDV_MaxChars(pDX, m_hzfind, 6);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDNWDlg, CDialog)
	//{{AFX_MSG_MAP(CDNWDlg)
	ON_WM_TIMER()   //cpp文件消息循环
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDS_ABOUTBOX, OnAboutbox)
	ON_UPDATE_COMMAND_UI(IDC_SHOW, OnShow)
	ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_CLOSE()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_RBUTTONDBLCLK()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_BN_CLICKED(IDD_ABOUTBOX, OnAboutbox)
	ON_BN_CLICKED(IDM_ABOUTBOX, OnAboutbox)
	ON_COMMAND(IDM_ABOUTBOX, OnAboutbox)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	//}}AFX_MSG_MAP

ON_MESSAGE(MYWM_NOTIFYICON,OnTrayNotification)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDNWDlg message handlers
#define ID_TASKBARICON 100 //定义托盘图标id 
#define ID_STATUSBAR 101
#define WM_ICONNOTIFY           (WM_USER + 101)        //定义托盘消息

#define IDT_TIMER_FIND 101  //一般定义
CStatusBarCtrl m_bar; //状态栏
NOTIFYICONDATA tnd;//托盘图标数据
HICON hIcon; //托盘图标



BOOL CDNWDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CRect wrect;
GetClientRect(&wrect);
int nFullWidth=GetSystemMetrics(SM_CXSCREEN); 
int nFullHeight=GetSystemMetrics(SM_CYSCREEN); //取得屏幕尺寸
SetWindowPos(NULL,nFullWidth-wrect.right+wrect.left-150,nFullHeight-wrect.bottom+wrect.top-63,0,0,SWP_NOSIZE);
//初始化窗口出现在屏幕下角

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}//创建菜单


	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
::SetTimer(m_hWnd, IDT_TIMER_FIND, 100 , NULL);//oninitdialog
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=this->m_hWnd;
tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage=MYWM_NOTIFYICON;  
//用户定义的回调消息
CString szToolTip;
szToolTip=_T("手写汉字识别系统");
_tcscpy(tnd.szTip, szToolTip);
tnd.uID=IDR_MAINFRAME;

hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
tnd.hIcon=hIcon;
::Shell_NotifyIcon(NIM_ADD,&tnd);
if(hIcon)::DestroyIcon(hIcon);
//创建托盘区图标

CMenu menu; 

menu.LoadMenu(IDR_MAIN_MENU); //载入事先定义的选单 
SetMenu(&menu);


RECT rect = { 0, 0, 0, 0 };
	m_bar.Create(WS_CHILD|WS_VISIBLE|SBS_SIZEGRIP, rect, this, ID_STATUSBAR);

	m_bar.SetBkColor(RGB(200, 200, 250));

	int arWidth[] = { 250, -1 };
m_bar.SetParts(2, arWidth);
m_bar.SetText("请在客户区用鼠标写字。", 0, 0);
m_bar.SetText("  QQ: 12377388  ", 1, 0); //状态栏

arch=0;arcs=0;arcp=0;arcl=0;arcz=0; //基本笔划计数器清0
m_counting.SetRange ( -1 ,100 ) ; //spin控件设置
m_hzcount.SetWindowText("0");  //汉字找到数设为0
hzsfind=0;//
m_zk.SetWindowText("江"); //机器写字默认字初始化
//m_show.InsertColumn(0,"汉字列表",LVCFMT_CENTER,10   ); //列表框
m_ftlist.InsertString(0,"仿宋体"); //组合框设置
m_ftlist.InsertString(1,"宋体"); //组合框设置
m_ftlist.InsertString(2,"黑体"); //组合框设置
m_ftlist.InsertString(3,"楷体"); //组合框设置
m_ftlist.InsertString(4,"常用符号"); //组合框设置
m_ftlist.SetCurSel(0);


hzfile=FONTF;
bOpenOK = cf.Open(hzfile,CFile::modeRead );
if (bOpenOK==0)
 {
CString Msg="字库文件:"+hzfile+"不能打开!";
AfxMessageBox(Msg,MB_OK|MB_ICONINFORMATION);
OnCancel();
 } 
rec1x=34;
rec2x=190;
rec3x=348;
recy=43;

//汉字在字库中的偏移量L=(区码*94+位码)*n ,n为每个汉字占用字节数
//我是用的24*24点阵字库,所以 n=72








//m_user.Canvas.moveto(100,100);
m_down=false;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDNWDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}



else if ((nID & 0xFFF0)==SC_MINIMIZE){
  //OnClose();本来这个是关闭的这里也改为隐藏。

  ShowWindow(SW_HIDE);//系统菜单的关闭也改为隐藏。
 }









	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.
//if (m_down==true) {pDC->MoveTo(down_point.x,down_point.y);
//	pDC->LineTo(cur_point.x,cur_point.y);}
//down_point=point;
void CDNWDlg::OnPaint() 
{CBrush brushWhite(RGB(255, 255, 255));
CBrush brushBlue(RGB(0, 0, 255));
CBrush brushRed(RGB(255, 0, 0));
CBrush brushGreen(RGB(0, 255, 0)); //画刷的定义	
	CDC *pDC=GetDC();
	CBrush* pOldBrush = pDC->SelectObject (&brushWhite);
	pDC->Rectangle(Startx,Starty,Startx+wid-1,Starty+lon-1);
//显示写字板
	if (IsIconic())
	{  // CPaintDC *pDc =GetPaintDC();
		CPaintDC dc(this); // device context for painting
	
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);










	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDNWDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CDNWDlg::OnOK() 
{

}

void CDNWDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
::Shell_NotifyIcon(NIM_DELETE,&tnd);
	CDialog::OnCancel();
}

void CDNWDlg::OnAboutbox() 
{	CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	// TODO: Add your control notification handler code here
	
}
LONG CDNWDlg::OnTrayNotification(WPARAM wparam, LPARAM lparam)
{
 switch ( lparam ){// The tray icon sent us a message. 
     //Let's see what it is

        /*case WM_CONTEXTMENU:
            TRACE( "WM_CONTEXTMENU\n" );*/
  case WM_RBUTTONDOWN:
  case WM_LBUTTONDBLCLK:
  case WM_LBUTTONDOWN:
  OnShow();
   break;
    }

 return 0;
}



void CDNWDlg::OnShow() 
{//m_down=false;
m_count=0;
	
	
	if (!IsWindowVisible()) {
  ShowWindow(SW_SHOW);
 }
 else{
  ShowWindow(SW_HIDE);
 }
	// TODO: Add your command update UI handler code here
	
}

void CDNWDlg::OnMenuitem32771() 
{
	// TODO: Add your command handler code here
	::ShellExecute(NULL, NULL, "使用说明.txt", NULL, NULL, SW_SHOW);
}




void CDNWDlg::OnTimer(UINT nIDEvent) 
{CPoint point;
GetCursorPos(&point);
ScreenToClient(&point); 

if((point.x>=Startx)&&(point.x<Startx+wid)&&(point.y>=Starty)&&(point.y<Starty+lon))
	{ 
		HCURSOR m_HCross;
		m_HCross=AfxGetApp()->LoadCursor(IDC_CURSOR1);
		SetCursor(m_HCross);
	}


	

	CDialog::OnTimer(nIDEvent);
}











void CDNWDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
down_point=point;
SetCapture();

	// TODO: Add your message handler code here and/or call default
	if((point.x>=Startx)&&(point.x<Startx+wid)&&(point.y>=Starty)&&(point.y<Starty+lon))
	{ m_down=true;
		HCURSOR m_HCross;
		m_HCross=AfxGetApp()->LoadCursor(IDC_CURSOR1);
		SetCursor(m_HCross);
sx=point.x;sy=point.y;
minarc=0;maxarc=0;
	}

	CDialog::OnLButtonDown(nFlags, point);
}

void CDNWDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{float arc;
up_point=point;
if (m_down) m_counting.SetPos(m_counting.GetPos()+1);
ReleaseCapture(); 
	// TODO: Add your message handler code here and/or call default

	if (m_down) {
	

ex=point.x;ey=point.y;
if (ex==sx) arc=100;
else arc=(float)(ey-sy)/(ex-sx);  //计算水平夹角
//if (arc==0) if (ey!=sy) arc=(ex-sx)/(ey-sy);
CString ms;
if ((float)abs((float)arc)<(float)0.414) //{ms.Format("横");
arch=arch+1;
//}
if (abs(arc)>2.414) {ms.Format("竖");arcs++;}
ms.Format("%d,%d,%d",minarc,maxarc,arch);
if ((arc<=-0.414)&&(arc>=-2.414)) {ms.Format("撇");arcp++;}
if ((arc>=0.414)&&(arc<=2.414)) {ms.Format("拉");arcl++;}
if (abs(ex-sx)<10&&abs(ey-sy)<10) //{m_down=false;return;}
 ms.Format("点");

int   nLength= m_hzs.SendMessage(WM_GETTEXTLENGTH);
m_hzs.SetSel(nLength,nLength);
m_hzs.ReplaceSel(ms);
	

	

	if((point.x>=Startx)&&(point.x<Startx+wid)&&(point.y>=Starty)&&(point.y<Starty+lon))
	{ 
		HCURSOR m_HCross;
		m_HCross=AfxGetApp()->LoadCursor(IDC_CURSOR1);
		SetCursor(m_HCross);
		CDNWDlg::OnButton1() ;}	}

m_down=false;
	CDialog::OnLButtonUp(nFlags, point);
}

void CDNWDlg::OnMouseMove(UINT nFlags, CPoint point) 
{float arc;
CBrush brushBlue(RGB(0, 0, 255));

	cur_point=point;
	CDC *pDC=GetDC();
	CRgn Rgn;
	Rgn.CreateRectRgn(Startx,Starty,Startx+wid-1,Starty+lon-1);
	pDC->SelectClipRgn(&Rgn);
if((point.x>=Startx)&&(point.x<Startx+wid)&&(point.y>=Starty)&&(point.y<Starty+lon))
	{ 
		HCURSOR m_HCross;
		m_HCross=AfxGetApp()->LoadCursor(IDC_CURSOR1);
		SetCursor(m_HCross);
	}

if((m_down==true)&&(point.x>=Startx)&&(point.x<Startx+wid)
		&&(point.y>=Starty)&&(point.y<Starty+lon))

⌨️ 快捷键说明

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