当前位置: 首页 > news >正文

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在对话框中实现打印和打印预览

首先在这里感谢互联网的大哥们&#xff01;同时我讨厌动不动就是要vip才能查看&#xff01;所以我写的不需要vip就能看。只求点个赞。 直接上代码&#xff0c;新建6个文件CPrintFrame.cpp&#xff1b;CPrintFrame.h&#xff1b;CPrintPreviewView.cpp&#xff1b;CPrintPrevie…...

移动端页面出现闪屏

v-cloak 的作用和用法 用法&#xff1a; 这个指令保持在元素上直到关联实例结束编译。和 CSS 规则如 [v-cloak] { display: none } 一起用时&#xff0c;这个指令可以隐藏未编译的 Mustache 标签直到实例准备完毕。官方API {{msg}} HTML 绑定 Vue实例&#xff0c;在页面加载时…...

elasticsearch的高亮查询三种模式查询及可能存在的问题

目录 高亮查询使用介绍 高亮参数 三种分析器 可能存在的查询问题 fvh查询时出现StringIndexOutOfBoundsException越界 检索高亮不正确 参考文档 高亮查询使用介绍 Elasticsearch 的高亮&#xff08;highlight&#xff09;可以从搜索结果中的一个或多个字段中获取突出显…...

【精品实战项目】深度学习预测、深度强化学习优化、附源码数据手把手教学

目录 前言 一、预测算法数据与代码介绍(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 手写仿深拷贝

实现对象参数的深拷贝并返回拷贝之后的新对象&#xff0c;因为参数对象和参数对象的每个数据项的数据类型范围仅在数组、普通对象&#xff08;{}&#xff09;、基本数据类型中且无需考虑循环引用问题&#xff0c;所以不需要做过多的数据类型判断&#xff0c;核心步骤有&#xf…...

spring低版本设置cookie的samesite属性

场景&#xff1a;比较古老的项目了&#xff0c;ssh架子&#xff0c;Chrome 51 开始&#xff0c;浏览器的 Cookie 新增加了一个SameSite属性&#xff0c;可用于防止 CSRF 攻击和用户追踪。因此需要给其字段赋值。 网上找了很多资源&#xff0c;由于jar版本比较低&#xff0c;没有…...

GPT4o编写步进电机控制代码

我给出的要求如下&#xff1a; 基于STM32F407 HAL库&#xff0c;写一个步进电机控制程序&#xff0c;需要控制8个步进电机&#xff0c;我会给出描述步进电机的结构体变量&#xff0c;基于这些变量需要你做出以下功能&#xff0c;电机脉冲通过定时器中断翻转脉冲引脚的电平实现…...

关于Spring Boot的自动配置

目录 1.EnableAutoConfiguration注解 2.SpringBootConfiguration注解 3.Import注解 4.spring.factories 5.总结 &#xff08;1&#xff09;EnableAutoConfiguration &#xff08;2&#xff09;AutoConfigurationImportSelector &#xff08;3&#xff09; SpringFactoriesLoade…...

## 已解决:`java.sql.SQLSyntaxErrorException: SQL语法错误` 异常的正确解决方法,亲测有效!!! ###

1. 问题描述 java.sql.SQLSyntaxErrorException 是 Java 程序在执行 SQL 查询时&#xff0c;因 SQL 语法错误而抛出的异常。通常情况下&#xff0c;错误信息会指示出错的 SQL 语句及错误原因&#xff0c;如拼写错误、关键字遗漏、字段名称错误等。 典型的错误信息如下&#x…...

备战秋招60天算法挑战,Day22

题目链接&#xff1a; https://leetcode.cn/problems/missing-number/ 视频题解&#xff1a; https://www.bilibili.com/video/BV1HS42197Hc/ LeetCode 268.丢失的数字 题目描述 给定一个包含 [0, n] 中 n 个数的数组 nums &#xff0c;找出 [0, n] 这个范围内没有出现在数组…...

在Linux下搭建go环境

下载go go官网&#xff1a;All releases - The Go Programming Language 我们可以吧压缩包下载到Windows上再传到Linux上&#xff0c;也可以直接web下载&#xff1a; wget https://golang.google.cn/dl/go1.23.0.linux-amd64.tar.gz 解压 使用命令解压&#xff1a; tar -x…...

738.单调递增的数字

738.单调递增的数字 当且仅当每个相邻位数上的数字 x 和 y 满足 x < y 时&#xff0c;我们称这个整数是单调递增的。 给定一个整数 n &#xff0c;返回 小于或等于 n 的最大数字&#xff0c;且数字呈 单调递增 。 示例 1: 输入: n 10 输出: 9示例 2: 输入: n 1234 输…...

近年国际重大网络安全事件深度剖析:安全之路任重道远

引言 在当今数字化时代&#xff0c;网络安全已成为全球关注的焦点。随着信息技术的飞速发展&#xff0c;网络攻击的手段和规模也在不断升级&#xff0c;给个人、企业和国家带来了巨大的威胁。本文将盘点近年来国际上发生的重大网络安全事件&#xff0c;分析其影响和教训&#…...

Windows C++控制台菜单库开发与源码展示

Windows C控制台菜单库 声明&#xff1a;演示视频&#xff1a;一、前言二、具体框架三、源码展示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存储器&#xff0c;全称为Flash EEPROM Memory&#xff0c;又名闪存&#xff0c;是一种长寿命的非易失性存储器。它能够在断电情况下保持所存储的数据信息&#xff0c;因此非常适合用于存储需要持久保存的数据。Flash存储器的数据删除不是以单个的字节为单…...

Docker和虚拟机的区别详细讲解

Docker 和虚拟机&#xff08;VM&#xff09;是现代 IT 基础设施中常见的技术&#xff0c;它们都用于在单一硬件上运行多个操作环境&#xff0c;但它们的工作原理、性能、资源利用和使用场景存在显著差异。以下是对 Docker 和虚拟机区别的详细讲解。 一、基础概念 1. Docker …...

leetcode_68. 文本左右对齐

68. 文本左右对齐 题目描述&#xff1a;给定一个单词数组 words 和一个长度 maxWidth &#xff0c;重新排版单词&#xff0c;使其成为每行恰好有 maxWidth 个字符&#xff0c;且左右两端对齐的文本。 你应该使用 “贪心算法” 来放置给定的单词&#xff1b;也就是说&#xff0c…...

python探索分形和混沌

简单产生复杂&#xff0c;混沌孕育秩序 0. 引言 a. 分形 fractal 【也叫碎形】 分形是一种具有自相似性和复杂结构的几何图形。在分形结构中&#xff0c;无论放大多少次&#xff0c;局部的结构特征都与整体结构相似。这种特性在自然界中广泛存在&#xff0c;比如树木枝干、山…...

LeetCode77 组合

前言 题目&#xff1a; 77. 组合 文档&#xff1a; 代码随想录——组合 编程语言&#xff1a; C 解题状态&#xff1a; 没尝试出来 思路 经典的组合问题&#xff0c;可以考虑使用回溯法。使用回溯法时可以根据回溯法的模板来考虑如何解决。 代码 回溯法 class Solution { p…...

C#:Bitmap类使用方法—第1讲

首先看一下Bitmap定义&#xff1a;封装 GDI 位图&#xff0c;此位图由图形图像及其属性的像素数据组成。 Bitmap 是用于处理由像素数据定义的图像的对象。 下面介绍一下使用的例子&#xff1a; Bitmap image1; private void Button1_Click(System.Object sender, System.Eve…...

MongoDB学习和应用(高效的非关系型数据库)

一丶 MongoDB简介 对于社交类软件的功能&#xff0c;我们需要对它的功能特点进行分析&#xff1a; 数据量会随着用户数增大而增大读多写少价值较低非好友看不到其动态信息地理位置的查询… 针对以上特点进行分析各大存储工具&#xff1a; mysql&#xff1a;关系型数据库&am…...

从零开始打造 OpenSTLinux 6.6 Yocto 系统(基于STM32CubeMX)(九)

设备树移植 和uboot设备树修改的内容同步到kernel将设备树stm32mp157d-stm32mp157daa1-mx.dts复制到内核源码目录下 源码修改及编译 修改arch/arm/boot/dts/st/Makefile&#xff0c;新增设备树编译 stm32mp157f-ev1-m4-examples.dtb \stm32mp157d-stm32mp157daa1-mx.dtb修改…...

现代密码学 | 椭圆曲线密码学—附py代码

Elliptic Curve Cryptography 椭圆曲线密码学&#xff08;ECC&#xff09;是一种基于有限域上椭圆曲线数学特性的公钥加密技术。其核心原理涉及椭圆曲线的代数性质、离散对数问题以及有限域上的运算。 椭圆曲线密码学是多种数字签名算法的基础&#xff0c;例如椭圆曲线数字签…...

Java 二维码

Java 二维码 **技术&#xff1a;**谷歌 ZXing 实现 首先添加依赖 <!-- 二维码依赖 --><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.5.1</version></dependency><de…...

go 里面的指针

指针 在 Go 中&#xff0c;指针&#xff08;pointer&#xff09;是一个变量的内存地址&#xff0c;就像 C 语言那样&#xff1a; a : 10 p : &a // p 是一个指向 a 的指针 fmt.Println(*p) // 输出 10&#xff0c;通过指针解引用• &a 表示获取变量 a 的地址 p 表示…...

软件工程 期末复习

瀑布模型&#xff1a;计划 螺旋模型&#xff1a;风险低 原型模型: 用户反馈 喷泉模型:代码复用 高内聚 低耦合&#xff1a;模块内部功能紧密 模块之间依赖程度小 高内聚&#xff1a;指的是一个模块内部的功能应该紧密相关。换句话说&#xff0c;一个模块应当只实现单一的功能…...

图解JavaScript原型:原型链及其分析 | JavaScript图解

​​ 忽略该图的细节&#xff08;如内存地址值没有用二进制&#xff09; 以下是对该图进一步的理解和总结 1. JS 对象概念的辨析 对象是什么&#xff1a;保存在堆中一块区域&#xff0c;同时在栈中有一块区域保存其在堆中的地址&#xff08;也就是我们通常说的该变量指向谁&…...

boost::filesystem::path文件路径使用详解和示例

boost::filesystem::path 是 Boost 库中用于跨平台操作文件路径的类&#xff0c;封装了路径的拼接、分割、提取、判断等常用功能。下面是对它的使用详解&#xff0c;包括常用接口与完整示例。 1. 引入头文件与命名空间 #include <boost/filesystem.hpp> namespace fs b…...

【R语言编程——数据调用】

这里写自定义目录标题 可用库及数据集外部数据导入方法查看数据集信息 在R语言中&#xff0c;有多个库支持调用内置数据集或外部数据&#xff0c;包括studentdata等教学或示例数据集。以下是常见的库和方法&#xff1a; 可用库及数据集 openintro库 该库包含多个教学数据集&a…...

2025-06-08-深度学习网络介绍(语义分割,实例分割,目标检测)

深度学习网络介绍(语义分割,实例分割,目标检测) 前言 在开始这篇文章之前&#xff0c;我们得首先弄明白&#xff0c;什么是图像分割&#xff1f; 我们知道一个图像只不过是许多像素的集合。图像分割分类是对图像中属于特定类别的像素进行分类的过程&#xff0c;即像素级别的…...