// LCDDisplay1.cpp: 实现文件 // #include "pch.h" #include "LCDDisplay1.h" #define WM_MENUST (WM_USER+1500) // CMyPicDisp IMPLEMENT_DYNAMIC(LCDDisplay1, CStatic) static unsigned int font3_5[128] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x007720,0x002770, // ▲▼ 0x000000,0x020222,0x000055,0x017574,0x036736,0x051245,0x053730,0x000122, // ! " # $ % & ' 0x021112,0x024442,0x052725,0x022722,0x012200,0x000700,0x020000,0x012244, // ( ) * + , - . / 0x075557,0x022222,0x071747,0x074747,0x044755,0x074717,0x075717,0x044557, // 0 1 2 3 4 5 6 7 0x075757,0x074757,0x002020,0x012020,0x042124,0x007070,0x012421,0x020452, // 8 9 : ; < = > ? 0x025752,0x055752,0x035353,0x071117,0x035553,0x071717,0x011717,0x075517, // @ A B C D E F G 0x055755,0x072227,0x032227,0x055355,0x071111,0x055575,0x055535,0x025552, // H I J K L M N O 0x011353,0x065552,0x055353,0x034216,0x022227,0x075555,0x025555,0x057555, // P Q R S T U V W 0x055255,0x022255,0x071247,0x071117,0x042211,0x074447,0x000052,0x070000, // X Y Z [ \ ] ^ _ 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, }; static unsigned long long font5_7[128] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, // ▲▼ 0x000000000000,0x00400410e384,0x00000000a6db,0x00015f29f500, // ! " # 0x0043d4385784,0x0186421084c3,0x016255085080,0x00000000430c, // $ % & ' 0x004081041084,0x004210410204,0x0112847c4291,0x0001047c4100, // ( ) * + 0x00230c000000,0x0000007c0000,0x00c300000000,0x000042108400, // , - . / // , 0x00e45355944e,0x00e104104184,0x01f08421044e,0x00e45039044e, // 0 1 2 3 0x01e21f24a308,0x00e45040f05f,0x00e4513c108c,0x00410410841f, // 4 5 6 7 0x00e45139144e,0x00e41079144e,0x00030c00c300,0x00330c00c300, // 8 9 : ; 0x008102042108,0x00001f01f000,0x002108408102,0x00400421044e, // < = > ? 0x01e04d55544e,0x01145f451284,0x00f4513d144f,0x00e44104144e, // @ A B C 0x00f45145144f,0x01f0413c105f,0x0010413c105f,0x00e45174144e, // D E F G 0x0114517d1451,0x00e10410410e,0x00614410410e,0x0112450c5251, // H I J K 0x01f041041041,0x0114555556d1,0x011459553451,0x00e45145144e, // L M N O 0x0010413d144f,0x01625545144e,0x0112453d144f,0x00e45038144e, // P Q R S 0x00410410411f,0x00e451451451,0x004291451451,0x00a555551451, // T U V W 0x01144a10a451,0x00410410a451,0x01f04210841f,0x00e08208208e, // X Y Z [ 0x000408102040,0x00e20820820e,0x000000011284,0x01f000000000, // \ ] ^ _ 0x000000204082,0x00058924e000,0x0003d144f041,0x00038104e000, // ` a b c 0x00079145e410,0x0003817d1380,0x00208208f08c,0x00620e249380, // d e f g 0x000249247041,0x000384106004,0x00614410e004,0x0002450c5241, // h i j k 0x000382082082,0x000451555280,0x0002492491c0,0x000391451380, // l m n o 0x0010472491c0,0x00820e249380,0x000082092340,0x000390302700, // p q r s 0x00070411e100,0x000389249000,0x000085249000,0x000295551000, // t u v w 0x00024a1c9000,0x00620e28a000,0x0003c210f000,0x008104084108, // x y z { 0x004104004104,0x002104204102,0x000000000352,0x000000000000, // | } ~ }; LCDDisplay1::LCDDisplay1() { m_nBkColor = 0xffc4d8d0; m_nHideColor = m_nBkColor - 0x00080808; m_nFntColor = 0xff404040; m_nMouseWndX = 0; m_nMouseWndY = 0; m_nMouseMode = MouseModeCursor; m_fDispOffsetX = 0; m_fDispOffsetY = 0; m_fScaleX = 1; m_fScaleY = 1; SetTextMode(TextModeDefault); nExtMenuCount = 0; nOldMenuSel = 0; bViewMoving = 0; m_menu1.CreatePopupMenu(); m_menu1.AppendMenu(MF_STRING | MF_CHECKED | MFT_RADIOCHECK, WM_MENUST + ID_Point, _T("指针(&P)")); m_menu1.AppendMenu(MF_STRING | MFT_RADIOCHECK, WM_MENUST + ID_Move, _T("平移(&A)")); m_menu1.AppendMenu(MF_STRING | MFT_RADIOCHECK, WM_MENUST + ID_ZoomIn, _T("放大(&I)")); m_menu1.AppendMenu(MF_STRING | MFT_RADIOCHECK, WM_MENUST + ID_ZoomOut, _T("缩小(&O)")); m_menu1.AppendMenu(MF_SEPARATOR); m_menu1.AppendMenu(MF_STRING | MF_CHECKED, WM_MENUST + ID_PixelGrid, _T("像素网格(&G)")); m_menu1.AppendMenu(MF_STRING | MF_CHECKED, WM_MENUST + ID_SubPixelGrid, _T("子像素网格(&S)")); m_menu1.AppendMenu(MF_SEPARATOR); m_menu1.AppendMenu(MF_STRING, WM_MENUST + ID_ZoomFit, _T("适合图像")); m_menu1.AppendMenu(MF_STRING, WM_MENUST + ID_OrgScale, _T("原始尺寸100%")); m_menu1.AppendMenu(MF_SEPARATOR); m_menu1.AppendMenu(MF_STRING, WM_MENUST + ID_Seprate_Window, _T("分离窗口")); //menu1.AppendMenu(MF_STRING, WM_MENUST + ID_Restore_Window, _T("恢复窗口")); //menu1.AppendMenu(MF_SEPARATOR); m_menu1.AppendMenu(MF_STRING, WM_MENUST + ID_LoadImage, _T("加载图片...")); m_menu1.AppendMenu(MF_SEPARATOR); m_menu1.AppendMenu(MF_STRING, WM_MENUST + ID_SaveImageAs, _T("图像另存为...")); } LCDDisplay1::~LCDDisplay1() { } BEGIN_MESSAGE_MAP(LCDDisplay1, CStatic) ON_WM_SIZE() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_MOUSEWHEEL() ON_WM_MOUSELEAVE() ON_WM_MOUSEMOVE() ON_WM_KILLFOCUS() ON_CONTROL_REFLECT(STN_CLICKED, &LCDDisplay1::OnStnClicked) ON_CONTROL_REFLECT(STN_DBLCLK, &LCDDisplay1::OnStnDblclick) ON_WM_RBUTTONDOWN() ON_WM_RBUTTONUP() ON_WM_RBUTTONDBLCLK() ON_WM_MBUTTONDOWN() ON_WM_MBUTTONUP() ON_WM_MBUTTONDBLCLK() ON_WM_LBUTTONDBLCLK() ON_WM_TIMER() ON_WM_CONTEXTMENU() ON_COMMAND_RANGE(WM_MENUST, WM_MENUST + ID_MenuItemCustom - 1, OnMenuS1) ON_COMMAND_RANGE(WM_MENUST + ID_MenuItemCustom, WM_MENUST + ID_MenuItemCustom + 15, OnMenuS) ON_WM_SETCURSOR() END_MESSAGE_MAP() // LCDDisplay1 消息处理程序 BOOL LCDDisplay1::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 if (NULL != m_tooltip.GetSafeHwnd() && pMsg->message == WM_MOUSEMOVE) { m_tooltip.RelayEvent(pMsg); } return CStatic::PreTranslateMessage(pMsg); } void LCDDisplay1::PreSubclassWindow() { // TODO: 在此添加专用代码和/或调用基类 this->ModifyStyle(SS_TYPEMASK, SS_OWNERDRAW | SS_NOTIFY); if (m_tooltip.GetSafeHwnd() == NULL) m_tooltip.Create(this); m_tooltip.AddTool(this); // m_tooltip.AddTool(this); // m_tooltip.Create(this); // , TTS_ALWAYSTIP); m_tooltip.Activate(TRUE); m_tooltip.EnableToolTips(TRUE); this->EnableToolTips(TRUE); m_tooltip.SetTipTextColor(RGB(0, 0, 255));//font color m_tooltip.SetDelayTime(150);//delay time m_tooltip.SetDelayTime(TTDT_AUTOPOP, -1); m_tooltip.SetDelayTime(TTDT_INITIAL, 1); m_tooltip.SetDelayTime(TTDT_RESHOW, 1); m_tooltip.SetMaxTipWidth(1000); // m_tooltip.AddTool(this, _T("这是一个测试")); // m_tooltip.UpdateTipText(_T("提示??????"), this); CStatic::PreSubclassWindow(); } int LCDDisplay1::SetZoom(float fZoom) { m_fZoom = fZoom; bHasChanged = 1; this->RedrawWindow(); return 1; } //HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) //{ // if (!toolID || !hDlg || !pszText) // { // return false; // } // HWND hwndTool = GetDlgItem(hDlg, toolID); // // HWND hwndTip = CreateWindowEx(NULL, // TOOLTIPS_CLASS, // NULL, // WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON, // CW_USEDEFAULT, // CW_USEDEFAULT, // CW_USEDEFAULT, // CW_USEDEFAULT, // hDlg, // NULL, // AfxGetInstanceHandle(), // NULL); // if (!hwndTool || !hwndTip) // { // return (HWND)NULL; // TOOLINFO toolInfo = { 0 }; // toolInfo.cbSize = sizeof(TOOLINFO); // toolInfo.hwnd = hDlg; // toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; // toolInfo.uId = (UINT_PTR)hwndTool; // toolInfo.lpszText = pszText; // SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); // return hwndTip; // } // return hwndTip; //} int LCDDisplay1::SetBkColor(COLORREF bkcolor) { Gdiplus::Color color1; color1.SetFromCOLORREF(bkcolor); m_nBkColor = color1.GetValue(); m_nHideColor = m_nBkColor - 0x00080808; this->RedrawWindow(); return 0; } int LCDDisplay1::SetFontColor(COLORREF fntColor) { Gdiplus::Color color1; color1.SetFromCOLORREF(fntColor); m_nFntColor = color1.GetValue(); this->RedrawWindow(); return 0; } int LCDDisplay1::SetHideColor(COLORREF hideColor) { m_nHideColor = hideColor | 0xff000000; this->RedrawWindow(); return 0; } void LCDDisplay1::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { using namespace Gdiplus; UINT j = lpDrawItemStruct->itemState; Gdiplus::Graphics gr0(lpDrawItemStruct->hDC); CRect rect0 = lpDrawItemStruct->rcItem; //CString s1; //s1.Format(_T("Draw Button Stat %08X \r\n"), j); //SysLog(s1); m_nClientW = rect0.Width(); m_nClientH = rect0.Height(); Gdiplus::Bitmap bitmap1(m_nClientW, m_nClientH); Gdiplus::Graphics gr1(&bitmap1); // gr1.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); Rect rect1; rect1.X = rect0.left; rect1.Y = rect0.top; rect1.Width = rect0.Width(); rect1.Height = rect0.Height(); int mindisindex = -1; float mindis = 999; CString sHintStr; { gr1.Clear(m_nBkColor); //填充背景 m_nOffsetXMax = 0; m_nOffsetYMax = 0; } pixelsizex = 8; pixelsizey = 8; pixelsizex = int(m_nClientW / 128); pixelsizey = int(m_nClientH / 64); if (pixelsizex < 1) pixelsizex = 1; if (pixelsizey < 1) pixelsizey = 1; if (pixelsizex < 2) pixelgapx = 0; else pixelgapx = 1; if (pixelsizey < 2) pixelgapy = 0; else pixelgapy = 1; // pixelgapx = 0.3f; // pixelgapy = 0.3f; left_margin = (m_nClientW - 128 * pixelsizex) / 2; if (left_margin < 0) left_margin = 0; top_margin = (m_nClientH - 64 * pixelsizey) / 2; if (top_margin < 0) top_margin = 0; //显示外框 Pen pen0(m_nHideColor, 1); gr1.DrawRectangle(&pen0, left_margin - 2, top_margin - 2, 128 * (int)pixelsizex + 2, 64 * (int)pixelsizey + 2); SolidBrush brush0(m_nHideColor); SolidBrush brush1(m_nFntColor); for (int i = 0; i < 64; i++) { for (int j = 0; j < 128; j++) { if (displayarray[i][j]){ gr1.FillRectangle(&brush1, left_margin + j * pixelsizex, top_margin + i * pixelsizey, pixelsizex - pixelgapx, pixelsizey - pixelgapy); //gr1.FillEllipse(&brush1, left_margin + j * pixelsizex, top_margin + i * yspace, pixelsizex - pixelgapx, yspace - pixelgapy); } else gr1.FillRectangle(&brush0, left_margin + j * pixelsizex, top_margin + i * pixelsizey, pixelsizex - pixelgapx, pixelsizey - pixelgapy); } } /* for (int i = 0; i < m_nClientH; i += 4) { for (int j = 0; j < m_nClientW; j += 4) { gr1.FillRectangle(&brush0, j, i, 3, 3); } } */ //显示文字 CStringW sw1; GetWindowText(sw1); FontFamily fontfamily1(L"MS Shell Dlg"); float fontsizey = rect0.Height() / 2.2f; float fontsizex = rect0.Width() / 2.8f; float fontsize = 12;// min(fontsizex, fontsizey); Gdiplus::Font font1(&fontfamily1, fontsize, 0);//::FontStyleBold); SolidBrush brush11(Color::White); SolidBrush brush12(Color::LightBlue); StringFormat stringformat1; stringformat1.SetAlignment(Gdiplus::StringAlignmentNear); stringformat1.SetLineAlignment(Gdiplus::StringAlignmentNear); RectF rect2; rect2.X = (float)rect0.left; rect2.Y = rect0.top + 16.0f; rect2.Width = (float)rect0.Width(); rect2.Height = (float)rect0.Height(); // gr1.DrawString(sw1, sw1.GetLength(), &font1, PointF(rect1.right / 2.0f, rect1.bottom / 2.0f), &stringformat1, &brush11); gr1.DrawString(sw1, sw1.GetLength(), &font1, rect2, &stringformat1, &brush11); //显示在窗口右上角 sw1.Format(L"%.2f %d %d ", m_fZoom, m_fDispOffsetX, m_fDispOffsetY); Gdiplus::Font font2(&fontfamily1, 8, 0);//::FontStyleBold); gr1.DrawString(sw1, sw1.GetLength(), &font1, PointF(rect0.right - 120.0f, 0), &stringformat1, &brush11); float scrdis = mindis * m_fZoom; //显示在鼠标右下角 sw1.Format(L"%d %d %.2f %.2f \r\n%d %.2f %.2f %s", m_nMouseWndX, m_nMouseWndY, m_MousePicX, m_MousePicY, mindisindex, mindis, scrdis, sHintStr); // gr1.DrawString(sw1, sw1.GetLength(), &font1, PointF(m_nMouseWndX+8.0f, m_nMouseWndY+16.0f), &stringformat1, &brush12); gr0.DrawImage(&bitmap1, 0, 0); if (scrdis <= 5) { m_tooltip.UpdateTipText(sHintStr, this); m_tooltip.Popup(); ; // CreateToolTip(this->GetDlgCtrlID(), this->GetParent()->GetSafeHwnd(), _T("这是二个测试")); } else { m_tooltip.UpdateTipText(_T(""), this); m_tooltip.HideCaret(); } // TODO: 添加您的代码以绘制指定项 } void LCDDisplay1::OnKillFocus(CWnd* pNewWnd) { CStatic::OnKillFocus(pNewWnd); CString s1; // GetWindowText(s1); // s1.Append(_T("KF ")); // SetWindowText(s1); // TODO: 在此处添加消息处理程序代码 } void LCDDisplay1::OnSize(UINT nType, int cx, int cy) { CStatic::OnSize(nType, cx, cy); CString s1; // GetWindowText(s1); // s1.Append(_T("S ")); // SetWindowText(s1); // TODO: 在此处添加消息处理程序代码 } int LCDDisplay1::TranslatePTtoColRow(int x, int y, int& nCol, int& nRow) { // TODO: 在此处添加实现代码. if (x < left_margin) return false; if (y < top_margin) return false; int refx, refy; refx = x - left_margin; refy = y - top_margin; nCol = refx / pixelsizex; nRow = refy / pixelsizey; if (nCol >= 128) { return false; } if (nRow >= 64) { return false; } return true; } void LCDDisplay1::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; // GetWindowText(s1); // s1.Append(_T("LD ")); // SetWindowText(s1); SetFocus(); m_nLastMouseX = point.x; m_nLastMouseY = point.y; if (m_nMouseMode == MouseModeCursor) { int bFound = 0; int nCol, nRow; if (TranslatePTtoColRow(point.x, point.y, nCol, nRow)) { if (displayarray[nRow][nCol]) displayarray[nRow][nCol] = 0; else displayarray[nRow][nCol] = 1; this->RedrawWindow(); }; //*/ } else if (m_nMouseMode == MouseModeHand) { bViewMoving = 1; SetCapture(); } else if (m_nMouseMode == MouseModeZoomIn) { } else if (m_nMouseMode == MouseModeZoomOut) { } CStatic::OnLButtonDown(nFlags, point); } void LCDDisplay1::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; // GetWindowText(s1); // s1.Append(_T("LU ")); // SetWindowText(s1); /* if (pTargetShape != nullptr) { pTargetShape->EndDrag(nTargetPoint, fDragStartx,fDragStarty,m_MousePicX, m_MousePicY); pTargetShape = nullptr; this->RedrawWindow(); } */ bViewMoving = 0; ReleaseCapture(); CStatic::OnLButtonUp(nFlags, point); } void LCDDisplay1::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; // GetWindowText(s1); // s1.Append(_T("LDB ")); // SetWindowText(s1); CStatic::OnLButtonDblClk(nFlags, point); } void LCDDisplay1::OnMouseMove(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 //CString s1; //GetWindowText(s1); //s1.Append(_T("MM")); //SetWindowText(s1); if (bViewMoving) { int delX, delY; delX = point.x - m_nLastMouseX; delY = point.y - m_nLastMouseY; m_fDispOffsetX += delX; m_fDispOffsetY += delY; if (m_fDispOffsetX > m_nOffsetXMax) { m_fDispOffsetX = m_nOffsetXMax; } if (m_fDispOffsetX < -m_nOffsetXMax) { m_fDispOffsetX = -m_nOffsetXMax; } if (m_fDispOffsetY > m_nOffsetYMax) { m_fDispOffsetY = m_nOffsetYMax; } if (m_fDispOffsetY < -m_nOffsetYMax) { m_fDispOffsetY = -m_nOffsetYMax; } } m_nLastMouseX = point.x; m_nLastMouseY = point.y; m_nMouseWndX = point.x; m_nMouseWndY = point.y;; bHasChanged = 1; // this->RedrawWindow(); /* if (pTargetShape != nullptr) { pTargetShape->DragTo(nTargetPoint, fDragStartx,fDragStarty,m_MousePicX, m_MousePicY); } */ // this->RedrawWindow(); //构造一个MSG //MSG msg; //msg.hwnd = m_hWnd; //msg.message = WM_MOUSEMOVE; //msg.wParam = LOWORD(point.x); //msg.lParam = LOWORD(point.y); //msg.time = 0; //msg.pt.x = LOWORD(point.y); //msg.pt.y = HIWORD(point.y); //m_tooltip.RelayEvent(&msg); //CStatic::OnMouseMove(nFlags, point); } BOOL LCDDisplay1::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; // GetWindowText(s1); // s1.Append(_T("MW ")); // SetWindowText(s1); // m_fDispOffX 居中是0,0 CRect rect0; GetWindowRect(&rect0); // CString s1; //s1.Format(_T("Draw Button Stat %08X \r\n"), j); //SysLog(s1); int w = rect0.Width(); int h = rect0.Height(); ScreenToClient(&pt); int ptx, pty; ptx = pt.x; pty = pt.y; if (zDelta > 0) { if (m_fZoom < 256) { m_fDispOffsetX = int(m_fDispOffsetX*1.41421356237f - (ptx - w / 2)*0.41421356237f); m_fDispOffsetY = int(m_fDispOffsetY*1.41421356237f - (pty - h / 2)*0.41421356237f); m_fZoom *= 1.41421356237f; } } else if (zDelta < 0) { if (m_fZoom > 0.05) { m_fDispOffsetX = int(m_fDispOffsetX / 1.41421356237f + (ptx - w / 2)*0.292893218815f); m_fDispOffsetY = int(m_fDispOffsetY / 1.41421356237f + (pty - h / 2)*0.292893218815f); m_fZoom /= 1.41421356237f; } } if (m_fDispOffsetX > m_nOffsetXMax) { m_fDispOffsetX = m_nOffsetXMax; } if (m_fDispOffsetX < -m_nOffsetXMax) { m_fDispOffsetX = -m_nOffsetXMax; } if (m_fDispOffsetY > m_nOffsetYMax) { m_fDispOffsetY = m_nOffsetYMax; } if (m_fDispOffsetY < -m_nOffsetYMax) { m_fDispOffsetY = -m_nOffsetYMax; } bHasChanged = 1; // this->RedrawWindow(); return CStatic::OnMouseWheel(nFlags, zDelta, pt); } void LCDDisplay1::OnMouseLeave() { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; GetWindowText(s1); s1.Append(_T("ML ")); SetWindowText(s1); CStatic::OnMouseLeave(); } void LCDDisplay1::OnStnClicked() { // TODO: 在此添加控件通知处理程序代码 // CString s1; // GetWindowText(s1); // s1.Append(_T("StnC ")); // SetWindowText(s1); } void LCDDisplay1::OnStnDblclick() { // TODO: 在此添加控件通知处理程序代码 CString s1; // GetWindowText(s1); // s1.Append(_T("StnDb ")); // SetWindowText(s1); } void LCDDisplay1::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; // GetWindowText(s1); // s1.Append(_T("RD ")); // SetWindowText(s1); CStatic::OnRButtonDown(nFlags, point); } void LCDDisplay1::OnRButtonUp(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; // GetWindowText(s1); // s1.Append(_T("RU ")); // SetWindowText(s1); CStatic::OnRButtonUp(nFlags, point); } void LCDDisplay1::OnRButtonDblClk(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; GetWindowText(s1); s1.Append(_T("RDB ")); SetWindowText(s1); CStatic::OnRButtonDblClk(nFlags, point); } void LCDDisplay1::OnMButtonDown(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; GetWindowText(s1); s1.Append(_T("MD ")); SetWindowText(s1); CStatic::OnMButtonDown(nFlags, point); } void LCDDisplay1::OnMButtonUp(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; GetWindowText(s1); s1.Append(_T("MU ")); SetWindowText(s1); CStatic::OnMButtonUp(nFlags, point); } void LCDDisplay1::OnMButtonDblClk(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CString s1; GetWindowText(s1); s1.Append(_T("MDB ")); SetWindowText(s1); CStatic::OnMButtonDblClk(nFlags, point); } void LCDDisplay1::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDEvent == 0) { } else if (nIDEvent == 1) { } else { } CStatic::OnTimer(nIDEvent); } void LCDDisplay1::OnContextMenu(CWnd* pWnd, CPoint point) { // TODO: 在此处添加消息处理程序代码 CString s1; // GetWindowText(s1); // s1.Append(_T("CM ")); // SetWindowText(s1); m_menu1.TrackPopupMenu(NULL, point.x, point.y, pWnd); } int LCDDisplay1::Clear(int bRedraw) { // MyGraphics.clear(); // MyShapeCollections.clear(); for (int i = 0; i < 64; i++) { for (int j = 0; j < 128; j++) { displayarray[i][j] = 0; } } if (bRedraw) this->RedrawWindow(); return HvOk; } int LCDDisplay1::AddData(short * pData, int nSize, int bRedraw) { memcpy(FreqBuf1, pData, nSize); memmove(pullBuf1[1], pullBuf1[0], 1023 * 256); nDataSize = nSize; for (int i = 0; i < nSize; i++) { int value = FreqBuf1[i] - 10; if (FreqBuf1[i] < 0) { pullBuf1[0][i] = 0; } else if (FreqBuf1[i] > 255) { pullBuf1[0][i] = 255; } else { pullBuf1[0][i] = FreqBuf1[i]; } } // if (bRedraw) this->RedrawWindow(); return HvOk; } /* int LCDDisplay1::UpdateData(short * pData, int nSize, int bRedraw) { memcpy(FreqBuf1, pData, nSize); nDataSize = nSize ; if (bRedraw) this->RedrawWindow(); return HvOk; } */ /* int LCDDisplay1::Add(pHvShape theshape, int bRedraw) { MyGraphics.push_back(theshape); if (bRedraw) this->RedrawWindow(); return int(MyGraphics.size()); } int LCDDisplay1::AddList(pHvShapeCollection theShapeColletion, int bRedraw) { MyShapeCollections.push_back(theShapeColletion); if (bRedraw) this->RedrawWindow(); return int(MyShapeCollections.size()); } int LCDDisplay1::Remove(pHvShape theshape, int bRedraw ) { if (theshape == nullptr) return HvErr; int n = MyGraphics.size(); for (int i = 0; i < n; i++) { if (theshape == MyGraphics[i]) { MyGraphics.erase(MyGraphics.begin() + i); break; } } if (bRedraw) this->RedrawWindow(); return int(MyGraphics.size()); } */ BOOL LCDDisplay1::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (m_nMouseMode == MouseModeCursor) { HCURSOR hCur = LoadCursor(NULL, IDC_ARROW); ::SetCursor(hCur); return TRUE; } else if (m_nMouseMode == MouseModeHand) { HCURSOR hCur = LoadCursor(NULL, IDC_HAND); ::SetCursor(hCur); return TRUE; } else if (m_nMouseMode == MouseModeZoomIn) { //HCURSOR hCur = LoadCursor(NULL, IDC_UPARROW); //::SetCursor(hCur); //return TRUE; } else if (m_nMouseMode == MouseModeZoomOut) { //HCURSOR hCur = LoadCursor(NULL, IDC_ARROW); //::SetCursor(hCur); //return TRUE; } // return TRUE; return CStatic::OnSetCursor(pWnd, nHitTest, message); } int LCDDisplay1::AddMenuItem(CString sMenuStr, pMenuCallBack pFunc, void * pParam) { if (nExtMenuCount >= 10) return HvErr; if (nExtMenuCount == 0) m_menu1.InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR); myCallBack[nExtMenuCount].bIsSet = 1; myCallBack[nExtMenuCount].pParam = pParam; myCallBack[nExtMenuCount].pFunc = pFunc; m_menu1.InsertMenu(nExtMenuCount, MF_BYPOSITION | MF_STRING, WM_MENUST + ID_MenuItemCustom + nExtMenuCount, sMenuStr); nExtMenuCount++; return HvOk; } void LCDDisplay1::OnMenuS1(UINT nId) { CString s1; int nMenuId = nId - WM_MENUST; GetWindowText(s1); s1.AppendFormat(_T("M%d "), nId); // SetWindowText(s1); int j; CRect rect1; switch (nMenuId) { case ID_Point: m_menu1.CheckMenuItem(WM_MENUST + nOldMenuSel, 0); m_menu1.CheckMenuItem(WM_MENUST + ID_Point, MF_CHECKED); m_nMouseMode = MouseModeCursor; nOldMenuSel = ID_Point; break; case ID_Move: m_menu1.CheckMenuItem(WM_MENUST + nOldMenuSel, 0); m_menu1.CheckMenuItem(WM_MENUST + ID_Move, MF_CHECKED); m_nMouseMode = MouseModeHand; nOldMenuSel = ID_Move; break; case ID_ZoomIn: m_menu1.CheckMenuItem(WM_MENUST + nOldMenuSel, 0); m_menu1.CheckMenuItem(WM_MENUST + ID_ZoomIn, MF_CHECKED); m_nMouseMode = MouseModeZoomIn; nOldMenuSel = ID_ZoomIn; break; case ID_ZoomOut: m_menu1.CheckMenuItem(WM_MENUST + nOldMenuSel, 0); m_menu1.CheckMenuItem(WM_MENUST + ID_ZoomOut, MF_CHECKED); m_nMouseMode = MouseModeZoomOut; nOldMenuSel = ID_ZoomOut; break; case ID_PixelGrid: j = m_menu1.GetMenuState(WM_MENUST + ID_PixelGrid, MF_CHECKED); if (j) { m_menu1.CheckMenuItem(WM_MENUST + ID_PixelGrid, 0); } else { m_menu1.CheckMenuItem(WM_MENUST + ID_PixelGrid, MF_CHECKED); } break; case ID_SubPixelGrid: j = m_menu1.GetMenuState(WM_MENUST + ID_SubPixelGrid, MF_CHECKED); if (j) { m_menu1.CheckMenuItem(WM_MENUST + ID_SubPixelGrid, 0); } else { m_menu1.CheckMenuItem(WM_MENUST + ID_SubPixelGrid, MF_CHECKED); } break; case ID_ZoomFit: // SetBestFitZoom(); break; case ID_OrgScale: SetZoom(1); break; case ID_Seprate_Window: this->GetParent()->GetClientRect(&rect1);; MoveWindow(&rect1); break; case ID_Restore_Window: ModifyStyle(WS_POPUPWINDOW, WS_CHILDWINDOW); break; case ID_LoadImage: // QLoadImage(); break; case ID_SaveImageAs: break; // QSaveImage(); default: break; } } void LCDDisplay1::OnMenuS(UINT nId) { CString s1; GetWindowText(s1); s1.AppendFormat(_T("M%d "), nId); SetWindowText(s1); int nExtId = nId - WM_MENUST - ID_MenuItemCustom; myCallBack[nExtId].pFunc(myCallBack[nExtId].pParam); } int LCDDisplay1::FFT(float *pBuf1, int nSize, float *pBufOut) { return HvOk; } int LCDDisplay1::SetTextMode(int nMode) { // TODO: 在此处添加实现代码. if (nMode == TextModeDefault) { char_width = 6; char_height = 8; text_cols = 21; text_rows = 8; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else if (nMode == TextMode3_5) { char_width = 4; char_height = 6; text_cols = 32; text_rows = 10; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else if (nMode == TextMode5_7) { char_width = 6; char_height = 8; text_cols = 21; text_rows = 8; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else if (nMode == TextMode5_11) { char_width = 6; char_height = 12; text_cols = 21; text_rows = 5; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else if (nMode == TextMode7_11) { char_width = 8; char_height = 12; text_cols = 16; text_rows = 5; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else if (nMode == TextMode7_12) { char_width = 8; char_height = 13; text_cols = 16; text_rows = 5; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else if (nMode == TextMode7_15) { char_width = 8; char_height = 16; text_cols = 16; text_rows = 4; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } else { char_width = 6; char_height = 8; text_cols = 21; text_rows = 8; m_TextMode = nMode; m_cursor_x = 0; m_cursor_y = 0; } return 0; } int LCDDisplay1::putText(const char * text) { // TODO: 在此处添加实现代码. int l = strlen(text); for (int i = 0; i < l; i++) { int curx = m_cursor_x * char_width; int cury = m_cursor_y * char_height; char ch = text[i]; long long dots = font5_7[ch]; for (int m = 0; m < 7; m++) { int line = dots & 0x3f; int mask = 1; for (int n = 0; n < 5; n++) { if (line&mask){ displayarray[cury + m][curx + n] = 1; } else { displayarray[cury + m][curx + n] = 0; } mask <<= 1; } dots >>= 6; } m_cursor_x += 1; if (m_cursor_x >= text_cols) { m_cursor_x = 0; m_cursor_y += 1; } if (m_cursor_y >= text_rows) { m_cursor_y = 0; } } return 0; } int LCDDisplay1::putTextXY(int x, int y, const char * text) { // TODO: 在此处添加实现代码. int l = strlen(text); m_cursor_x = x; m_cursor_y = y; for (int i = 0; i < l; i++) { int curx = m_cursor_x * char_width; int cury = m_cursor_y * char_height; char ch = text[i]; long long dots = font5_7[ch]; for (int m = 0; m < 7; m++) { int line = dots & 0x3f; int mask = 1; for (int n = 0; n < 5; n++) { if (line&mask){ displayarray[cury + m][curx + n] = 1; } else { displayarray[cury + m][curx + n] = 0; } mask <<= 1; } dots >>= 6; } m_cursor_x += 1; if (m_cursor_x >= text_cols) { m_cursor_x = 0; m_cursor_y += 1; } if (m_cursor_y >= text_rows) { m_cursor_y = 0; } } return 0; }