MFC在对话框中实现打印和打印预览
首先在这里感谢互联网的大哥们!同时我讨厌动不动就是要vip才能查看!所以我写的不需要vip就能看。只求点个赞。
直接上代码,新建6个文件CPrintFrame.cpp;CPrintFrame.h;CPrintPreviewView.cpp;CPrintPreviewView.h;CPrintView.cpp;CPrintView.h;
下面是代码
CPrintFrame.h
#pragma once// CPrintFrame 框架
#include "CPrintView.h"
#include "CertEditPage.h"
#include "DemarManageDlg.h"class CPrintFrame : public CFrameWnd
{DECLARE_DYNCREATE(CPrintFrame)
protected:CPrintFrame(); // 动态创建所使用的受保护的构造函数virtual ~CPrintFrame();public:CPrintFrame(CCertEditPage* pCCertEditPage, CDemarManageDlg* pDemarManageDlg, BOOL bPreview);CCertEditPage* m_pCCertEditPage;CPrintView* m_pCPrintView;CDemarManageDlg* m_pDemarManageDlg;BOOL m_bPreview;
protected:DECLARE_MESSAGE_MAP()
public:afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);afx_msg void OnClose();void SetOrientation(short orientation);virtual BOOL PreCreateWindow(CREATESTRUCT& cs);virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
};
CPrintFrame.cpp
// CPrintFrame.cpp: 实现文件
//#include "stdafx.h"
#include "CPrintFrame.h"// CPrintFrameIMPLEMENT_DYNCREATE(CPrintFrame, CFrameWnd)CPrintFrame::CPrintFrame():m_pCCertEditPage(NULL),m_pCPrintView(NULL), m_bPreview(TRUE)
{m_pCCertEditPage = NULL;
}CPrintFrame::CPrintFrame(CCertEditPage* pCCertEditPage, CDemarManageDlg* pDemarManageDlg,BOOL bPreview): m_pCCertEditPage(NULL), m_pCPrintView(NULL)
{m_bPreview = bPreview;m_pCCertEditPage = pCCertEditPage;m_pDemarManageDlg = pDemarManageDlg;CString title;if (m_bPreview)title = L"打印预览";elsetitle = L"打印";if (Create(NULL, title, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, CRect(200, 200, 500, 500))){//创建失败return;}SetOrientation(DMORIENT_LANDSCAPE);
}CPrintFrame::~CPrintFrame()
{//CWinApp* pApp = AfxGetApp();//pApp->m_pMainWnd = m_pDemarManageDlg;if (m_pCCertEditPage)m_pCCertEditPage->ShowWindow(SW_SHOW);
}BEGIN_MESSAGE_MAP(CPrintFrame, CFrameWnd)ON_WM_CREATE()ON_WM_CLOSE()
END_MESSAGE_MAP()// CPrintFrame 消息处理程序int CPrintFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{if (CFrameWnd::OnCreate(lpCreateStruct) == -1)return -1;if (!m_pCCertEditPage)return -1;// TODO: 在此添加您专用的创建代码CCreateContext context;context.m_pNewViewClass = RUNTIME_CLASS(CPrintView);context.m_pCurrentFrame = this;context.m_pCurrentDoc = NULL;context.m_pLastView = NULL;m_pCPrintView = STATIC_DOWNCAST(CPrintView, CreateView(&context));if (!m_pCPrintView)return -1;if (m_bPreview){m_pCPrintView->ShowWindow(SW_SHOW);}SetActiveView(m_pCPrintView);SetIcon(m_pCCertEditPage->GetIcon(FALSE), FALSE);SetIcon(m_pCCertEditPage->GetIcon(TRUE), TRUE);//ShowWindow(SW_MAXIMIZE);CRect rect;m_pCCertEditPage->GetWindowRect(rect);MoveWindow(rect);ShowWindow(SW_SHOW);m_pCPrintView->m_pCPrintFrame = this;CWinApp* pApp = AfxGetApp();pApp->m_pMainWnd = this;if (m_bPreview){m_pCPrintView->OnFilePrintPreview();m_pCCertEditPage->ShowWindow(SW_HIDE);}elsem_pCPrintView->SendMessage(WM_COMMAND, ID_FILE_PRINT);return 0;
}void CPrintFrame::OnClose()
{// TODO: 在此添加消息处理程序代码和/或调用默认值CWinApp* pApp = AfxGetApp();pApp->m_pMainWnd = m_pDemarManageDlg;this->DestroyWindow();//CFrameWnd::OnClose();
}
void CPrintFrame::SetOrientation(short orientation)
{PRINTDLG pd;pd.lStructSize = (DWORD)sizeof(PRINTDLG);BOOL bRet = AfxGetApp()->GetPrinterDeviceDefaults(&pd);if (bRet){LPDEVMODE lpDevMode = (LPDEVMODE) ::GlobalLock(pd.hDevMode);if (lpDevMode != NULL)lpDevMode->dmOrientation = orientation;::GlobalUnlock(pd.hDevMode);}
}BOOL CPrintFrame::PreCreateWindow(CREATESTRUCT& cs)
{// TODO: 在此添加专用代码和/或调用基类if (!CFrameWnd::PreCreateWindow(cs))return FALSE;// TODO: Modify the Window class or styles here by modifying// the CREATESTRUCT cscs.dwExStyle &= ~WS_EX_CLIENTEDGE;cs.lpszClass = AfxRegisterWndClass(0);return TRUE;//return CFrameWnd::PreCreateWindow(cs);
}BOOL CPrintFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{// TODO: 在此添加专用代码和/或调用基类if (m_pCPrintView && m_pCPrintView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))return TRUE;return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
CPrintView.h
#pragma once
#include <afxpriv.h>// CPrintView 视图class CPrintView : public CScrollView
{DECLARE_DYNCREATE(CPrintView)protected:CPrintView(); // 动态创建所使用的受保护的构造函数virtual ~CPrintView();public:
#ifdef _DEBUGvirtual void AssertValid() const;
#ifndef _WIN32_WCEvirtual void Dump(CDumpContext& dc) const;
#endif
#endifprotected:virtual void OnDraw(CDC* pDC); // 重写以绘制该视图virtual void OnInitialUpdate(); // 构造后的第一次DECLARE_MESSAGE_MAP()
public:void SetPaper(short dmOrientation, short dmPaperSize);void OnFilePrintPreview();afx_msg void OnFilePrint();void DrawCertification(CDC* pDC, CPrintInfo* pInfo);virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);CFrameWnd* m_pCPrintFrame;virtual void OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);void DrawCardData(CDC* pDC, CPrintInfo* pInfo);afx_msg void OnClose();BOOL DoPrintPreview(UINT nIDResource, CView* pPrintView, CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState);
};
CPrintView.cpp
// CPrintView.cpp: 实现文件
//#include "stdafx.h"
#include "DemarManage.h"
#include "CPrintView.h"
#include "DemarManageDlg.h"
#include "CPrintFrame.h"
#include "CPrintPreviewView.h"
// CPrintViewIMPLEMENT_DYNCREATE(CPrintView, CScrollView)CPrintView::CPrintView():m_pCPrintFrame(NULL)
{m_nMapMode = MM_TEXT;}CPrintView::~CPrintView()
{
}BOOL CALLBACK _AfxMyPreviewCloseProc(CFrameWnd* pFrameWnd)
{ASSERT_VALID(pFrameWnd);CPrintPreviewView* pView = (CPrintPreviewView*)pFrameWnd->GetDlgItem(AFX_IDW_PANE_FIRST);ASSERT_KINDOF(CPrintPreviewView, pView);pView->OnPreviewClose();return FALSE;
}BEGIN_MESSAGE_MAP(CPrintView, CScrollView)ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CPrintView::OnFilePrintPreview)ON_COMMAND(ID_FILE_PRINT, &CPrintView::OnFilePrint)ON_WM_CLOSE()
END_MESSAGE_MAP()// CPrintView 诊断#ifdef _DEBUG
void CPrintView::AssertValid() const
{CScrollView::AssertValid();
}#ifndef _WIN32_WCE
void CPrintView::Dump(CDumpContext& dc) const
{CScrollView::Dump(dc);
}
#endif
#endif //_DEBUG// CPrintView 绘图void CPrintView::OnInitialUpdate()
{CScrollView::OnInitialUpdate();CSize sizeTotal;// TODO: 计算此视图的合计大小sizeTotal.cx = sizeTotal.cy = 100;SetScrollSizes(MM_TEXT, sizeTotal);
}void CPrintView::OnDraw(CDC* pDC)
{CDocument* pDoc = GetDocument();// TODO: 在此添加绘制代码}/************************************************************************/
/* 设置纸张 */
/************************************************************************/
void CPrintView::SetPaper(short dmOrientation, short dmPaperSize)
{PRINTDLG pd;pd.lStructSize = (DWORD)sizeof(PRINTDLG);BOOL bRet = AfxGetApp()->GetPrinterDeviceDefaults(&pd);if (bRet){LPDEVMODE lpDevMode = (LPDEVMODE) ::GlobalLock(pd.hDevMode);if (lpDevMode != NULL){lpDevMode->dmOrientation = dmOrientation;lpDevMode->dmPaperSize = dmPaperSize;}::GlobalUnlock(pd.hDevMode);}
}void CPrintView::OnFilePrintPreview()
{CPrintFrame* pCPrintFrame = (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame->m_pCCertEditPage)return;switch (pCPrintFrame->m_pCCertEditPage->m_nPrintMode){case 1:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 2:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 4:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;}//CView::OnFilePrintPreview();CPrintPreviewState* pState = new CPrintPreviewState;pState->lpfnCloseProc = _AfxMyPreviewCloseProc;if (!DoPrintPreview(AFX_IDD_PREVIEW_TOOLBAR, this, RUNTIME_CLASS(CPrintPreviewView), pState)){TRACE0("Error: DoPrintPreview failed.\n");AfxMessageBox(AFX_IDP_COMMAND_FAILURE);delete pState;}
}
BOOL CPrintView::DoPrintPreview(UINT nIDResource, CView* pPrintView, CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState)
{ASSERT_VALID_IDR(nIDResource);if (!m_pCPrintFrame || !pPrintView || !pPreviewViewClass)return FALSE;ASSERT(pPreviewViewClass->IsDerivedFrom(RUNTIME_CLASS(CPreviewView)));if(!pState)return FALSE;CCreateContext context;context.m_pCurrentFrame = m_pCPrintFrame;context.m_pCurrentDoc = GetDocument();context.m_pLastView = this;// Create the preview view objectCPrintPreviewView* pView = (CPrintPreviewView*)pPreviewViewClass->CreateObject();if (!pView){TRACE0("Error: Failed to create preview view.\n");return FALSE;}ASSERT_KINDOF(CPreviewView, pView);pView->m_pPreviewState = pState; // save pointerm_pCPrintFrame->OnSetPreviewMode(TRUE, pState); // Take over Frame Window//Create the toolbar from the dialog resourcepView->m_pToolBar = new CDialogBar;if (!pView->m_pToolBar->Create(m_pCPrintFrame, MAKEINTRESOURCE(nIDResource),CBRS_TOP, AFX_IDW_PREVIEW_BAR)){TRACE0("Error: Preview could not create toolbar dialog.\n");m_pCPrintFrame->OnSetPreviewMode(FALSE, pState); // restore Frame Windowdelete pView->m_pToolBar; // not autodestruct yetpView->m_pToolBar = NULL;pView->m_pPreviewState = NULL; // do not delete state structuredelete pView;return FALSE;}pView->m_pToolBar->m_bAutoDelete = TRUE; // automatic cleanupif (!pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,CRect(0, 0, 0, 0), m_pCPrintFrame, AFX_IDW_PANE_FIRST, &context)){TRACE0("Error: couldn't create preview view for frame.\n");m_pCPrintFrame->OnSetPreviewMode(FALSE, pState); // restore Frame WindowpView->m_pPreviewState = NULL; // do not delete state structuredelete pView;return FALSE;}pState->pViewActiveOld = m_pCPrintFrame->GetActiveView();CPrintView* pActiveView = (CPrintView*)m_pCPrintFrame->GetActiveFrame()->GetActiveView();if (pActiveView != NULL)pActiveView->OnActivateView(FALSE, pActiveView, pActiveView);if (!pView->SetPrintView(pPrintView)){pView->OnPreviewClose();return TRUE; // signal that OnEndPrintPreview was called}m_pCPrintFrame->SetActiveView(pView); // set active view - even for MDI// update toolbar and redraw everythingpView->m_pToolBar->SendMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE);m_pCPrintFrame->RecalcLayout(); // position and size everythingm_pCPrintFrame->UpdateWindow();return TRUE;
}void CPrintView::OnFilePrint()
{// TODO: 在此添加命令处理程序代码CPrintFrame* pCPrintFrame = (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame->m_pCCertEditPage)return;if (!pCPrintFrame->m_bPreview)pCPrintFrame->ShowWindow(SW_HIDE);switch (pCPrintFrame->m_pCCertEditPage->m_nPrintMode){case 1:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 2:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;case 4:SetPaper(DMORIENT_PORTRAIT, DMPAPER_A5);break;}CView::OnFilePrint();if (!pCPrintFrame->m_bPreview){CWinApp* pApp = AfxGetApp();pApp->m_pMainWnd = pCPrintFrame->m_pDemarManageDlg;pCPrintFrame->DestroyWindow();}
}void CPrintView::DrawCertification(CDC* pDC, CPrintInfo* pInfo)
{if (!pDC)return;CPrintFrame* pCPrintFrame = (CPrintFrame*)m_pCPrintFrame;if(!pCPrintFrame || !pCPrintFrame->m_pDemarManageDlg)return;POINT point = { 0, 0 };SIZE size = { pDC->GetDeviceCaps(HORZRES),pDC->GetDeviceCaps(VERTRES) };CRect clientRect(point, size);double nLeftSpace(0.8), nTopSpace(0.8), nRightSpace(0.8), nBottomSpace(0.8);int iLeftSpace(0), iTopSpace(0), iRightSpace(0), iBottomSpace(0);iLeftSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nLeftSpace);iTopSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nTopSpace);iRightSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nRightSpace);iBottomSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nBottomSpace);//这里添加打印代码,打印自己想要的
}BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{CPrintFrame* pCPrintFrame = (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame->m_pCCertEditPage)return FALSE;// TODO: 调用 DoPreparePrinting 以调用“打印”对话框switch (pCPrintFrame->m_pCCertEditPage->m_nPrintMode){case 1:pInfo->SetMaxPage(1);pInfo->m_bDirect = FALSE;break;case 2:pInfo->SetMaxPage(1);pInfo->m_bDirect = FALSE;break;case 4:pInfo->SetMaxPage(2);pInfo->m_bDirect = FALSE;break;default:break;}return DoPreparePrinting(pInfo);
}void CPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{// TODO: 在此添加专用代码和/或调用基类CPrintFrame* pCPrintFrame = (CPrintFrame*)m_pCPrintFrame;if (!pCPrintFrame || !pCPrintFrame->m_pCCertEditPage)return;switch (pCPrintFrame->m_pCCertEditPage->m_nPrintMode){case 1:DrawCertification(pDC, pInfo);break;case 2:DrawCardData(pDC, pInfo);break;case 4:if (pInfo->m_nCurPage == 1)DrawCertification(pDC, pInfo);else if (pInfo->m_nCurPage == 2)DrawCardData(pDC, pInfo);break;default:break;}//CScrollView::OnPrint(pDC, pInfo);
}void CPrintView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView)
{// TODO: 在此添加专用代码和/或调用基类if (!m_pCPrintFrame || !pView || !pDC)return;//pInfo->m_nCurPage = 1;//CScrollView::OnEndPrintPreview(pDC, pInfo, point, pView);CPrintPreviewView* pCPrintPreviewView = (CPrintPreviewView*)pView;if (!pCPrintPreviewView->m_pPrintView)OnEndPrinting(pDC, pInfo);// restore the old main windowm_pCPrintFrame->OnSetPreviewMode(FALSE, pCPrintPreviewView->m_pPreviewState);// Force active view back to old onem_pCPrintFrame->SetActiveView(pCPrintPreviewView->m_pPreviewState->pViewActiveOld);if (m_pCPrintFrame != GetParentFrame())OnActivateView(TRUE, this, this);pView->DestroyWindow();m_pCPrintFrame->RecalcLayout();m_pCPrintFrame->SendMessage(WM_SETMESSAGESTRING, (WPARAM)AFX_IDS_IDLEMESSAGE, 0L);m_pCPrintFrame->UpdateWindow();
}void CPrintView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{// TODO: 在此添加专用代码和/或调用基类CScrollView::OnEndPrinting(pDC, pInfo);//CPrintFrame* pCPrintFrame = (CPrintFrame*)m_pCPrintFrame;//if (!pCPrintFrame || !pCPrintFrame->m_pDemarManageDlg)// return;//if(pInfo->m_bPreview == 0)// pCPrintFrame->PostMessageW(WM_CLOSE);
}
void CPrintView::DrawCardData(CDC* pDC, CPrintInfo* pInfo)
{if (!pDC || !pInfo) return;CPrintFrame* pMainFrm = (CPrintFrame*)m_pCPrintFrame;if (!pMainFrm) return;POINT point = { 0, 0 };SIZE size = { pDC->GetDeviceCaps(HORZRES),pDC->GetDeviceCaps(VERTRES) };CRect clientRect(point, size);chartParam.m_showRect = clientRect;double nLeftSpace(0.8), nTopSpace(0.8), nRightSpace(0.8), nBottomSpace(0.8);int iLeftSpace(0), iTopSpace(0), iRightSpace(0), iBottomSpace(0);iLeftSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nLeftSpace);iTopSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nTopSpace);iRightSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSX),nRightSpace);iBottomSpace = (int)Transfer::Cm2Unit(Transfer::GetScale(pDC, LOGPIXELSY),nBottomSpace);//这里添加打印代码,打印自己想要的}void CPrintView::OnClose()
{// TODO: 在此添加消息处理程序代码和/或调用默认值CScrollView::OnClose();
}
CPrintPreviewView.h
#pragma once// CPrintPreviewView 视图class CPrintPreviewView : public CPreviewView
{DECLARE_DYNCREATE(CPrintPreviewView)protected:CPrintPreviewView(); // 动态创建所使用的受保护的构造函数virtual ~CPrintPreviewView();public:
#ifdef _DEBUGvirtual void AssertValid() const;
#ifndef _WIN32_WCEvirtual void Dump(CDumpContext& dc) const;
#endif
#endiffriend class CPrintView;
protected:DECLARE_MESSAGE_MAP()afx_msg void OnPreviewClose();afx_msg void OnPreviewPrint();friend BOOL CALLBACK _AfxMyPreviewCloseProc(CFrameWnd* pFrameWnd);virtual void OnDraw(CDC* pDC);
};
CPrintPreviewView.cpp
// CPrintPreviewView.cpp: 实现文件
//#include "stdafx.h"
#include "DemarManage.h"
#include "CPrintPreviewView.h"// CPrintPreviewViewIMPLEMENT_DYNCREATE(CPrintPreviewView, CPreviewView)CPrintPreviewView::CPrintPreviewView()
{}CPrintPreviewView::~CPrintPreviewView()
{
}BEGIN_MESSAGE_MAP(CPrintPreviewView, CPreviewView)ON_COMMAND(AFX_ID_PREVIEW_CLOSE, OnPreviewClose)ON_COMMAND(AFX_ID_PREVIEW_PRINT, OnPreviewPrint)
END_MESSAGE_MAP()// CPrintPreviewView 诊断#ifdef _DEBUG
void CPrintPreviewView::AssertValid() const
{CPreviewView::AssertValid();
}#ifndef _WIN32_WCE
void CPrintPreviewView::Dump(CDumpContext& dc) const
{CPreviewView::Dump(dc);
}
#endif
#endif //_DEBUG// CPrintPreviewView 消息处理程序
#include "CPrintFrame.h"
void CPrintPreviewView::OnPreviewClose()
{CPrintFrame* pf = (CPrintFrame*)::AfxGetMainWnd();CWinApp * pApp = AfxGetApp();pApp->m_pMainWnd = pf->m_pDemarManageDlg;pf->DestroyWindow();
}void CPrintPreviewView::OnPreviewPrint()
{m_pPrintView->SendMessage(WM_COMMAND, ID_FILE_PRINT);OnPreviewClose();
}void CPrintPreviewView::OnDraw(CDC* pDC)
{// TODO: 在此添加专用代码和/或调用基类CPreviewView::OnDraw(pDC);m_pToolBar->PostMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE);// 控制条的命令状态更新
}
相关文章:
MFC在对话框中实现打印和打印预览
首先在这里感谢互联网的大哥们!同时我讨厌动不动就是要vip才能查看!所以我写的不需要vip就能看。只求点个赞。 直接上代码,新建6个文件CPrintFrame.cpp;CPrintFrame.h;CPrintPreviewView.cpp;CPrintPrevie…...
移动端页面出现闪屏
v-cloak 的作用和用法 用法: 这个指令保持在元素上直到关联实例结束编译。和 CSS 规则如 [v-cloak] { display: none } 一起用时,这个指令可以隐藏未编译的 Mustache 标签直到实例准备完毕。官方API {{msg}} HTML 绑定 Vue实例,在页面加载时…...
elasticsearch的高亮查询三种模式查询及可能存在的问题
目录 高亮查询使用介绍 高亮参数 三种分析器 可能存在的查询问题 fvh查询时出现StringIndexOutOfBoundsException越界 检索高亮不正确 参考文档 高亮查询使用介绍 Elasticsearch 的高亮(highlight)可以从搜索结果中的一个或多个字段中获取突出显…...
【精品实战项目】深度学习预测、深度强化学习优化、附源码数据手把手教学
目录 前言 一、预测算法数据与代码介绍(torch和mxnet都有) 1.1 数据介绍 1.2 代码介绍 1.3 优化介绍 二、深度强化学习算法优化 2.1 DDPG 介绍 DPG--deterministic policy gradient DQN--deep Q-network DDPG--deep deterministic policy gradient 三、其他算法 总结…...
JavaScript 手写仿深拷贝
实现对象参数的深拷贝并返回拷贝之后的新对象,因为参数对象和参数对象的每个数据项的数据类型范围仅在数组、普通对象({})、基本数据类型中且无需考虑循环引用问题,所以不需要做过多的数据类型判断,核心步骤有…...
spring低版本设置cookie的samesite属性
场景:比较古老的项目了,ssh架子,Chrome 51 开始,浏览器的 Cookie 新增加了一个SameSite属性,可用于防止 CSRF 攻击和用户追踪。因此需要给其字段赋值。 网上找了很多资源,由于jar版本比较低,没有…...
GPT4o编写步进电机控制代码
我给出的要求如下: 基于STM32F407 HAL库,写一个步进电机控制程序,需要控制8个步进电机,我会给出描述步进电机的结构体变量,基于这些变量需要你做出以下功能,电机脉冲通过定时器中断翻转脉冲引脚的电平实现…...
关于Spring Boot的自动配置
目录 1.EnableAutoConfiguration注解 2.SpringBootConfiguration注解 3.Import注解 4.spring.factories 5.总结 (1)EnableAutoConfiguration (2)AutoConfigurationImportSelector (3) SpringFactoriesLoade…...
## 已解决:`java.sql.SQLSyntaxErrorException: SQL语法错误` 异常的正确解决方法,亲测有效!!! ###
1. 问题描述 java.sql.SQLSyntaxErrorException 是 Java 程序在执行 SQL 查询时,因 SQL 语法错误而抛出的异常。通常情况下,错误信息会指示出错的 SQL 语句及错误原因,如拼写错误、关键字遗漏、字段名称错误等。 典型的错误信息如下&#x…...
备战秋招60天算法挑战,Day22
题目链接: https://leetcode.cn/problems/missing-number/ 视频题解: https://www.bilibili.com/video/BV1HS42197Hc/ LeetCode 268.丢失的数字 题目描述 给定一个包含 [0, n] 中 n 个数的数组 nums ,找出 [0, n] 这个范围内没有出现在数组…...
在Linux下搭建go环境
下载go go官网:All releases - The Go Programming Language 我们可以吧压缩包下载到Windows上再传到Linux上,也可以直接web下载: wget https://golang.google.cn/dl/go1.23.0.linux-amd64.tar.gz 解压 使用命令解压: tar -x…...
738.单调递增的数字
738.单调递增的数字 当且仅当每个相邻位数上的数字 x 和 y 满足 x < y 时,我们称这个整数是单调递增的。 给定一个整数 n ,返回 小于或等于 n 的最大数字,且数字呈 单调递增 。 示例 1: 输入: n 10 输出: 9示例 2: 输入: n 1234 输…...
近年国际重大网络安全事件深度剖析:安全之路任重道远
引言 在当今数字化时代,网络安全已成为全球关注的焦点。随着信息技术的飞速发展,网络攻击的手段和规模也在不断升级,给个人、企业和国家带来了巨大的威胁。本文将盘点近年来国际上发生的重大网络安全事件,分析其影响和教训&#…...
Windows C++控制台菜单库开发与源码展示
Windows C控制台菜单库 声明:演示视频:一、前言二、具体框架三、源码展示console_screen_set.hframeconsole_screen_frame_base.hconsole_screen_frame_char.hconsole_screen_frame_wchar_t.hconsole_screen_frame.h menuconsole_screen_menu_base.hcons…...
ARM——驱动——Linux启动流程和Linux启动
一、flash存储器 lash存储器,全称为Flash EEPROM Memory,又名闪存,是一种长寿命的非易失性存储器。它能够在断电情况下保持所存储的数据信息,因此非常适合用于存储需要持久保存的数据。Flash存储器的数据删除不是以单个的字节为单…...
Docker和虚拟机的区别详细讲解
Docker 和虚拟机(VM)是现代 IT 基础设施中常见的技术,它们都用于在单一硬件上运行多个操作环境,但它们的工作原理、性能、资源利用和使用场景存在显著差异。以下是对 Docker 和虚拟机区别的详细讲解。 一、基础概念 1. Docker …...
leetcode_68. 文本左右对齐
68. 文本左右对齐 题目描述:给定一个单词数组 words 和一个长度 maxWidth ,重新排版单词,使其成为每行恰好有 maxWidth 个字符,且左右两端对齐的文本。 你应该使用 “贪心算法” 来放置给定的单词;也就是说,…...
python探索分形和混沌
简单产生复杂,混沌孕育秩序 0. 引言 a. 分形 fractal 【也叫碎形】 分形是一种具有自相似性和复杂结构的几何图形。在分形结构中,无论放大多少次,局部的结构特征都与整体结构相似。这种特性在自然界中广泛存在,比如树木枝干、山…...
LeetCode77 组合
前言 题目: 77. 组合 文档: 代码随想录——组合 编程语言: C 解题状态: 没尝试出来 思路 经典的组合问题,可以考虑使用回溯法。使用回溯法时可以根据回溯法的模板来考虑如何解决。 代码 回溯法 class Solution { p…...
C#:Bitmap类使用方法—第1讲
首先看一下Bitmap定义:封装 GDI 位图,此位图由图形图像及其属性的像素数据组成。 Bitmap 是用于处理由像素数据定义的图像的对象。 下面介绍一下使用的例子: Bitmap image1; private void Button1_Click(System.Object sender, System.Eve…...
无法与IP建立连接,未能下载VSCode服务器
如题,在远程连接服务器的时候突然遇到了这个提示。 查阅了一圈,发现是VSCode版本自动更新惹的祸!!! 在VSCode的帮助->关于这里发现前几天VSCode自动更新了,我的版本号变成了1.100.3 才导致了远程连接出…...
可靠性+灵活性:电力载波技术在楼宇自控中的核心价值
可靠性灵活性:电力载波技术在楼宇自控中的核心价值 在智能楼宇的自动化控制中,电力载波技术(PLC)凭借其独特的优势,正成为构建高效、稳定、灵活系统的核心解决方案。它利用现有电力线路传输数据,无需额外布…...
转转集团旗下首家二手多品类循环仓店“超级转转”开业
6月9日,国内领先的循环经济企业转转集团旗下首家二手多品类循环仓店“超级转转”正式开业。 转转集团创始人兼CEO黄炜、转转循环时尚发起人朱珠、转转集团COO兼红布林CEO胡伟琨、王府井集团副总裁祝捷等出席了开业剪彩仪式。 据「TMT星球」了解,“超级…...
GC1808高性能24位立体声音频ADC芯片解析
1. 芯片概述 GC1808是一款24位立体声音频模数转换器(ADC),支持8kHz~96kHz采样率,集成Δ-Σ调制器、数字抗混叠滤波器和高通滤波器,适用于高保真音频采集场景。 2. 核心特性 高精度:24位分辨率,…...
基于matlab策略迭代和值迭代法的动态规划
经典的基于策略迭代和值迭代法的动态规划matlab代码,实现机器人的最优运输 Dynamic-Programming-master/Environment.pdf , 104724 Dynamic-Programming-master/README.md , 506 Dynamic-Programming-master/generalizedPolicyIteration.m , 1970 Dynamic-Programm…...
MySQL账号权限管理指南:安全创建账户与精细授权技巧
在MySQL数据库管理中,合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号? 最小权限原则…...
深度学习水论文:mamba+图像增强
🧀当前视觉领域对高效长序列建模需求激增,对Mamba图像增强这方向的研究自然也逐渐火热。原因在于其高效长程建模,以及动态计算优势,在图像质量提升和细节恢复方面有难以替代的作用。 🧀因此短时间内,就有不…...
2025年渗透测试面试题总结-腾讯[实习]科恩实验室-安全工程师(题目+回答)
安全领域各种资源,学习文档,以及工具分享、前沿信息分享、POC、EXP分享。不定期分享各种好玩的项目及好用的工具,欢迎关注。 目录 腾讯[实习]科恩实验室-安全工程师 一、网络与协议 1. TCP三次握手 2. SYN扫描原理 3. HTTPS证书机制 二…...
基于Springboot+Vue的办公管理系统
角色: 管理员、员工 技术: 后端: SpringBoot, Vue2, MySQL, Mybatis-Plus 前端: Vue2, Element-UI, Axios, Echarts, Vue-Router 核心功能: 该办公管理系统是一个综合性的企业内部管理平台,旨在提升企业运营效率和员工管理水…...
comfyui 工作流中 图生视频 如何增加视频的长度到5秒
comfyUI 工作流怎么可以生成更长的视频。除了硬件显存要求之外还有别的方法吗? 在ComfyUI中实现图生视频并延长到5秒,需要结合多个扩展和技巧。以下是完整解决方案: 核心工作流配置(24fps下5秒120帧) #mermaid-svg-yP…...
