MFC向其他程序发送wm_command消息失败

MFC 点击按钮向其他程序发送wm_command消息,
_点击按钮发送后,要移动一下鼠标或键盘按一下键,才会发出消息,目标窗口才会做出响应,
请问是怎么回事,要怎么解决.
如果鼠标不动,消息发不出来.目标窗口没反应

    HWND hwnd_sj = ::FindWindow(NULL,L"数据下载");
    SendMessage(hwnd_sj,WM_COMMAND,0x0abe1, 0);

    return;

用网上下载的消息调试器发送成功

5个回答

是移动鼠标后才发出WM_COMMAND,还是已经发送了可是移动鼠标后目标才响应?

qq_28638587
qq_28638587 回复纵横车: 晚上回家试了一下,是前面的循环出了问题,谢谢.
4 年多之前 回复
a1193561652
纵横车 回复qq_28638587: 那是不是你发送消息的部分有什么问题?要移动鼠标才发出,下个断点看看。
4 年多之前 回复
qq_28638587
qq_28638587 移动鼠标后才发出,如果不移动鼠标,spy++检测不到目标窗口消息
4 年多之前 回复

具体检查handle wparam lparam是否正确。
0x0abe1这是怎么得来的。看下控件的id

qq_28638587
qq_28638587 spy++,查的
4 年多之前 回复
qq_28638587
qq_28638587 控件id是0000abe1,spy+用网上下载的工具发送这个是成功的。
4 年多之前 回复

发送 WM_COMMAND 消息后,再模拟发送一个或多个鼠标按下/移动/抬起的消息试试

91program
91program 最简单的是只发鼠标移动的消息,因为这个不会产生什么误动作。
4 年多之前 回复

用SPY++检测下那个程序是否真的有收到了这个消息

charlsom
charlsom 是这样的,鼠标不动,消息貌似就没发出来。
4 年多之前 回复
lx624909677
lx624909677 回复charlsom: 那就说明那个界面就没有接收成功消息啊
4 年多之前 回复
charlsom
charlsom 鼠标一移动,马上就有消息,不移动就没有
4 年多之前 回复

这个问题。。最好保证自己的服务是在idle状态。如果在堵塞状态是接收不到消息的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
MFC自定义消息运行第二遍时获取窗口失败
//按钮事件 void CircleDialog::OnBnClickedOk() { UpdateData(TRUE); MsgParam param; param.radius=r; param.colorref1=color1.GetColor(); param.colorref2=color2.GetColor(); CMainFrame *pMainFrm=(CMainFrame*)AfxGetMainWnd(); CView *pView=pMainFrm->GetActiveView(); pView->SendMessage(WM_MYMSG,(WPARAM)&param,NULL); CDialogEx::OnOK(); } //消息响应函数 LRESULT CSimplePaintView::OnMyMessage(WPARAM wParam,LPARAM lParam){ MsgParam *myParam=(MsgParam*)wParam; cr=myParam->radius; lineColor=myParam->colorref1; bgColor=myParam->colorref2; m_rect.left=100; m_rect.top=100; m_rect.right=100+2*cr; m_rect.bottom=100+2*cr; m_pen.CreatePen(PS_SOLID,5,lineColor); m_brush.CreateSolidBrush(bgColor); UpdateData(FALSE); Invalidate(); return 0; } //声明消息响应函数 protected: afx_msg void OnFilePrintPreview(); afx_msg void OnRBut afx_msg void OnRButtonUp(UINT nFlags, CPoint point); afx_msg void OnContextMenu(CWnd* pWnd, CPoint point); **afx_msg LRESULT OnMyMessage(WPARAM wParam,LPARAM lParam);** DECLARE_MESSAGE_MAP() //消息映射 BEGIN_MESSAGE_MAP(CSimplePaintView, CView) // 标准打印命令 ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CSimplePaintView::OnFilePrintPreview) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_COMMAND(ID_CIRCLE, &CSimplePaintView::OnCircle) ON_COMMAND(ID_RECT, &CSimplePaintView::OnRect) **ON_MESSAGE(WM_MYMSG,OnMyMessage)** END_MESSAGE_MAP() //定义宏 **#define WM_MYMSG WM_USER+100** // **运行到第二遍时,pView下的指针(m_hWnd之类的)无法读取内存,但是点忽略后能继续运行。。**
关于MFC静态切分窗口的问题
问题描述: 我新建了一个单文档工程,然后对窗口进行了静态切分,分成了两部分。我在左边的部分创建了两个按钮,想实现点击按钮在右边显示对应的视图。 我的代码如下: 一共有三个视图: View1, view2, view3; 首先我继承了OnCreateClient函数 BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { CRect cr; GetWindowRect(&cr); if(m_wndSplitter.CreateStatic(this, 1, 2) == NULL) { return FALSE; } m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CMyView1), CSize(cr.Width()/4, cr.Height()), pContext); m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMyView2), CSize(3*cr.Width()/4, cr.Height()), pContext); return TRUE; } 然后我在左边的视图上创建了两个Button: 希望能够控制右面的视图。 然后我自定义了消息。 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) ON_COMMAND(ID_FIRST_VIEW, OnSwitchToFirst) // ID_FIRST_VIEW 是自己定义的 On_COMMAND(ID_SECOND_VIEW, OnSwitchToSecond) END_MESSAGE_MAP() Button 在 CView1 类中添加了通知处理 void CMyTreeBar::OnButton1() { AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND, ID_FIRST_VIEW); } void CMyTreeBar::OnButton2() { AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND, ID_SECOND_VIEW); } 然后在CMainFrame中添加了响应函数 void CMainFrame::OnSwitchToFirst() { m_wndSplitter.DeleteView(0, 1); m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMyView2), CSize(0, 0), NULL); m_wndSplitter.RecalcLayout(); } void CMainFrame::OnSwitchToSecond() { m_wndSplitter.DeleteView(0, 1); m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMyView2), CSize(0, 0), NULL); m_wndSplitter.RecalcLayout(); } 但是运行结果 点击Button2, View2 消失了,但是没有吧 View3 显示出来。 点击Button1, View2 又显示出来了。 // 程序运行都是正确的 总之就是没有实现了切换。我是新手,很着急,请各位好心大哥给点建议和帮助。 急急急!!!!
MFC IPM_GETADDRESS 标志无效是怎么回事啊?
``` #include "resource.h" #include <windows.h> #include <iostream> using namespace std; HWND hdlg = NULL; LRESULT CALLBACK DlgProc(HWND hDlgMain, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WINMAIN(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nShowCmd) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)DlgProc); return 0; } LRESULT CALLBACK DlgProc(HWND hDlgMain, UINT uMsg, WPARAM wParam, LPARAM lParam) { hdlg = hDlgMain; DWORD StartIP; DWORD EndIP; DWORD StartPort; DWORD EndPort; static BOOL Flag = TRUE; switch (uMsg) { case WM_INITDIALOG: break; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_BUTTON_START: { if (Flag) { // clear list //GetDlgItem get handle SendMessage(GetDlgItem(hdlg, IDC_LIST_RES), LB_RESETCONTENT, NULL, NULL); //get ip SendMessage(GetDlgItem(hdlg, IDC_IP_START), IPM_GETADDRESS, 0, (LPARAM)&StartIP); } }break; } }break; } } IPM_GETADDRESS这个一直报错 not defined 求大神们解释啊,IDC_IP_START对应的是IP Address控件~ ```
MFC怎么实现编辑框回车输入数据
因为现在要交课程设计,暂时没时间系统学习mfc,不太理解其中的工作原理。 做的是一个成绩统计系统,输入8个成绩,输出个分数段人数。界面如下: ![图片说明](https://img-ask.csdn.net/upload/201512/31/1451577480_428097.png) 现在在就是想实现在输入框输入成绩后按回车,可以完成本次输入、清空编辑框再进行下一次输入。网上说是重写PreTranslateMessage: ``` BOOL CGradeStatisticDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN) { p[i] = m_score; //m_score 为编辑框对应的cstring类型变量 m_score="0x0D"; i++; UpdateData(true); return true; } return CDialog::PreTranslateMessage(pMsg); } ``` 然后请问重写完后要怎么在主程序中加入它呢? 主程序为 ``` #include <windows.h> #include <string.h> #include "stdafx.h" #include "resource.h" HINSTANCE hInstance; LRESULT CALLBACK _ProcDlgMain(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { BOOL szBuffer; int a1; short a2; int i, b[8]; int q[6]; HICON hc; if(uMsg == WM_CLOSE) EndDialog(hwnd,NULL); else if(uMsg == WM_COMMAND) { a1=wParam; a2=a1; if(a2 == B2) EndDialog(hwnd,NULL); else if (a2 == B1) { for (int j=0; j<8; j++) b[j]=89; //b为输入成绩,q为统计成绩 for(i=0;i<6;i++) q[i]=0; __asm{ mov ecx, 8 mov edi, 0 again: mov edx, b[edi*4] cmp edx, 60 jb below60 cmp edx, 70 jb below70 cmp edx, 80 jb below80 cmp edx, 90 jb below90 cmp edx, 100 jb below100 equal100: inc q[5*4] jmp done below60: inc q[0*4] jmp done below70: inc q[1*4] jmp done below80: inc q[2*4] jmp done below90: inc q[3*4] jmp done below100: inc q[4*4] done: inc edi loop again } SetDlgItemInt(hwnd,E1,q[0],TRUE); SetDlgItemInt(hwnd,E2,q[1],TRUE); SetDlgItemInt(hwnd,E3,q[2],TRUE); SetDlgItemInt(hwnd,E4,q[3],TRUE); SetDlgItemInt(hwnd,E5,q[4],TRUE); SetDlgItemInt(hwnd,E6,q[5],TRUE); } } else return FALSE; return TRUE; } int _stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { hInstance=GetModuleHandle(NULL); DialogBoxParam(hInstance,(LPCTSTR)D1,NULL,(DLGPROC)_ProcDlgMain,NULL); ExitProcess(NULL); } ```
mfc中遇到: 'afxdialogex.h': No such file or directory
#include "stdafx.h" #include "calculater.h" #include "calculaterDlg.h" #include "afxdialogex.h"//如果注释掉有会有其他错 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCalculaterDlg dialog CCalculaterDlg::CCalculaterDlg(CWnd* pParent /*=NULL*/) : CDialog(CCalculaterDlg::IDD, pParent) { m_num = 0; i = 0; t = 0; num2 = 0; num1 = 0; point = 0; //{{AFX_DATA_INIT(CCalculaterDlg) m_EDIT2_NUM = 0.0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCalculaterDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCalculaterDlg) DDX_Text(pDX, IDC_EDIT2, m_EDIT2_NUM); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCalculaterDlg, CDialog) //{{AFX_MSG_MAP(CCalculaterDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON0, OnButton0) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_BN_CLICKED(IDC_BUTTON6, OnButton6) ON_BN_CLICKED(IDC_BUTTON7, OnButton7) ON_BN_CLICKED(IDC_BUTTON8, OnButton8) ON_BN_CLICKED(IDC_BUTTON9, OnButton9) ON_BN_CLICKED(IDC_BUTTONpoint, OnBUTTONpoint) ON_BN_CLICKED(IDC_BUTTONjia, OnBUTTONjia) ON_BN_CLICKED(IDC_BUTTONjian, OnBUTTONjian) ON_BN_CLICKED(IDC_BUTTONcheng, OnBUTTONcheng) ON_BN_CLICKED(IDC_BUTTONchu, OnBUTTONchu) ON_BN_CLICKED(IDC_BUTTONac, OnBUTTONac) ON_BN_CLICKED(IDC_BUTTONdel, OnBUTTONdel) ON_BN_CLICKED(IDC_BUTTONequal, OnBUTTONequal) ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCalculaterDlg message handlers BOOL CCalculaterDlg::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); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CCalculaterDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CCalculaterDlg::OnPaint() { if (IsIconic()) { 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 CCalculaterDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCalculaterDlg::OnButton0() { if(t) { m_num = m_num*10+0; Updatedata(FALSE); } else { m_num = m_num=0.0/i; i = i*10; Updatedata(FALSE); }
mfc通过ado连接access 老是无效指针,求高手指点
// Snake.cpp : 定义应用程序的类行为。 // #include "stdafx.h" #include "afxwinappex.h" #include "afxdialogex.h" #include "Snake.h" #include "MainFrm.h" #include "winsock2.h" #include "SnakeDoc.h" #include "SnakeView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CSnakeApp BEGIN_MESSAGE_MAP(CSnakeApp, CWinAppEx) ON_COMMAND(ID_APP_ABOUT, &CSnakeApp::OnAppAbout) // 基于文件的标准文档命令 ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen) END_MESSAGE_MAP() // CSnakeApp 构造 CSnakeApp::CSnakeApp() { m_bHiColorIcons = TRUE; // 支持重新启动管理器 m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS; #ifdef _MANAGED // 如果应用程序是利用公共语言运行时支持(/clr)构建的,则: // 1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。 // 2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。 System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException); #endif // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式 //为 CompanyName.ProductName.SubProduct.VersionInformation SetAppID(_T("Snake.AppID.NoVersion")); // TODO: 在此处添加构造代码, // 将所有重要的初始化放置在 InitInstance 中 } // 唯一的一个 CSnakeApp 对象 CSnakeApp theApp; // CSnakeApp 初始化 BOOL CSnakeApp::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinAppEx::InitInstance(); AfxEnableControlContainer(); AfxOleInit(); m_pConnection.CreateInstance(__uuidof(Connection)); // 在ADO操作中建议语句中要常用try...catch()来捕获错误信息, // 因为它有时会经常出现一些想不到的错误。 try { // 打开本地Access库Demo.mdb m_pConnection->Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=test.accdb", "", "", adModeUnknown); } catch (_com_error& e) { //调用在CAdoRWAccessDlg中打印错误信息的静态函数 //CAboutDlg::dump_com_error(e); return FALSE; } // 初始化 OLE 库 /*if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; }*/ AfxEnableControlContainer(); EnableTaskbarInteraction(FALSE); // 使用 RichEdit 控件需要 AfxInitRichEdit2() // AfxInitRichEdit2(); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, SetRegistryKey(_T("应用程序向导生成的本地应用程序")); LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU) InitContextMenuManager(); InitKeyboardManager(); InitTooltipManager(); CMFCToolTipInfo ttParams; ttParams.m_bVislManagerTheme = TRUE; theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL, RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams); // 注册应用程序的文档模板。文档模板 // 将用作文档、框架窗口和视图之间的连接 CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CSnakeDoc), RUNTIME_CLASS(CMainFrame), // 主 SDI 框架窗口 RUNTIME_CLASS(CSnakeView)); if (!pDocTemplate) return FALSE; AddDocTemplate(pDocTemplate); // 分析标准 shell 命令、DDE、打开文件操作的命令行 CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 调度在命令行中指定的命令。如果 // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。 if (!ProcessShellCommand(cmdInfo)) return FALSE; // 唯一的一个窗口已初始化,因此显示它并对其进行更新 m_pMainWnd->MoveWindow(0,0,645,645,1); m_pMainWnd->CenterWindow(); m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); // 仅当具有后缀时才调用 DragAcceptFiles // 在 SDI 应用程序中,这应在 ProcessShellCommand 之后发生 return TRUE; } int CSnakeApp::ExitInstance() { //TODO: 处理可能已添加的附加资源 AfxOleTerm(FALSE); return CWinAppEx::ExitInstance(); } // CSnakeApp 消息处理程序 // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; public: void dump_com_error(_com_error &e); _RecordsetPtr m_pRecordset; //_RecordsetPtr m_pRecordset1; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() public: afx_msg void OnBnClickedButton1(); CListBox m_AccessList; }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_AccessList); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CAboutDlg::OnBnClickedButton1) END_MESSAGE_MAP() // 用于运行对话框的应用程序命令 void CSnakeApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } void CAboutDlg::dump_com_error(_com_error &e) { CString ErrorStr; _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); ErrorStr.Format(L"\n\tADO Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n\n", e.Error(), e.ErrorMessage(), (LPCTSTR)bstrSource, (LPCTSTR)bstrDescription); //在调试窗口中打印错误信息,在Release版中可用DBGView查看错误信息 ::OutputDebugString((LPCTSTR)ErrorStr); #ifdef _DEBUG AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR); #endif } void CAboutDlg::OnBnClickedButton1() { _variant_t var; CString strName, strAge; m_AccessList.ResetContent(); strName = strAge = ""; try { if (!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { AfxMessageBox(L"表内数据为空"); return; } while (!m_pRecordset->adoEOF) { var = m_pRecordset->GetCollect("time"); if (var.vt != VT_NULL) strName = (LPCSTR)_bstr_t(var); var = m_pRecordset->GetCollect("score"); if (var.vt != VT_NULL) strAge = (LPCSTR)_bstr_t(var); m_AccessList.AddString(strName + " --> " + strAge); m_pRecordset->MoveNext(); } m_AccessList.SetCurSel(0); } catch (_com_error& e) { dump_com_error(e); } } // CSnakeApp 自定义加载/保存方法 void CSnakeApp::PreLoadState() { BOOL bNameValid; CString strName; bNameValid = strName.LoadString(IDS_EDIT_MENU); ASSERT(bNameValid); GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT); } void CSnakeApp::LoadCustomState() { } void CSnakeApp::SaveCustomState() { } // CSnakeApp 消息处理程序
这个程序0error 0warning,但是在执行的时候出现**dlg.exe已停止工作
// GT3Dlg.cpp : implementation file // #include "stdafx.h" #include "GT3.h" #include "GT3Dlg.h" #include "GT400.H" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGT3Dlg dialog CGT3Dlg::CGT3Dlg(CWnd* pParent /*=NULL*/) : CDialog(CGT3Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CGT3Dlg) m_Axis_One_Check = TRUE; m_Axis_Two_Check = FALSE; m_One_Jerk = 0.00000002; m_One_MaxAcc = 0.004; m_One_Pos = -20000; m_One_Vel = 5; m_Two_Jerk = 0.00000002; m_Two_MaxTwo = 0.004; m_Two_Pos = -20000; m_Two_Vel = 5; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CGT3Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CGT3Dlg) DDX_Check(pDX, IDC_AXIS_ONE_CHECK, m_Axis_One_Check); DDX_Check(pDX, IDC_AXIS_TWO_CHECK, m_Axis_Two_Check); DDX_Text(pDX, IDC_S_ONE_JERK, m_One_Jerk); DDV_MinMaxDouble(pDX, m_One_Jerk, 0., 1.e-002); DDX_Text(pDX, IDC_S_ONE_MAXACC, m_One_MaxAcc); DDV_MinMaxDouble(pDX, m_One_MaxAcc, 0., 0.5); DDX_Text(pDX, IDC_S_ONE_POS, m_One_Pos); DDX_Text(pDX, IDC_S_ONE_VEL, m_One_Vel); DDV_MinMaxDouble(pDX, m_One_Vel, 0., 50.); DDX_Text(pDX, IDC_S_TWO_JERK, m_Two_Jerk); DDV_MinMaxDouble(pDX, m_Two_Jerk, 0., 1.e-002); DDX_Text(pDX, IDC_S_TWO_MAXACC, m_Two_MaxTwo); DDV_MinMaxDouble(pDX, m_Two_MaxTwo, 0., 0.5); DDX_Text(pDX, IDC_S_TWO_POS, m_Two_Pos); DDX_Text(pDX, IDC_S_TWO_VEL, m_Two_Vel); DDV_MinMaxDouble(pDX, m_Two_Vel, 0., 50.); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CGT3Dlg, CDialog) //{{AFX_MSG_MAP(CGT3Dlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_AXIS_OPEN, OnAxisOpen) ON_BN_CLICKED(IDC_AXIS_SMOTION, OnAxisSmotion) ON_BN_CLICKED(IDC_AXIS_STOP, OnAxisStop) ON_BN_CLICKED(IDC_AXIS_CLOSE, OnAxisClose) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGT3Dlg message handlers BOOL CGT3Dlg::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); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CGT3Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CGT3Dlg::OnPaint() { if (IsIconic()) { 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 CGT3Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CGT3Dlg::OnAxisOpen() { // TODO: Add your control notification handler code here ////运动卡初始化函数//////////////////////////////////////////// short rtn; rtn=GT_Open(); if (rtn!=0) { MessageBox("打开运动控制器设备失败!\n 程序结束!","系统提示",MB_OK|MB_ICONERROR); } rtn=GT_Reset(); if (rtn!=0) { MessageBox("复位运动控制器失败!\n 程序结束!","系统提示",MB_OK|MB_ICONERROR); } rtn=GT_SetSmplTm(200); error(rtn); for (int i=1;i<5;++i) { rtn=GT_Axis(i); rtn=GT_SetIntrMsk(0); } ////专用输入信号参数设置////////////////////////////////////////// rtn=GT_LmtSns(0xff); rtn=GT_EncSns(0); ////控制轴初始化函数////////////////////////////////////////////// rtn=GT_Axis(1); error(rtn); //1号轴 rtn=GT_ClrSts(); error(rtn); rtn = GT_CtrlMode(0); error(rtn); //设置为输出模拟量 rtn=GT_CloseLp(); error(rtn); rtn = GT_SetKp(1); error(rtn); rtn = GT_SetKi(0); error(rtn); rtn = GT_SetKd(0); error(rtn); rtn=GT_SetKvff(0); error(rtn); rtn=GT_SetKaff(0); error(rtn); rtn=GT_Update(); error(rtn); rtn=GT_AxisOn(); error(rtn); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// rtn=GT_Axis(2); error(rtn); //2号轴初始化 rtn=GT_ClrSts(); error(rtn); rtn = GT_CtrlMode(0); error(rtn); rtn=GT_CloseLp(); error(rtn); rtn = GT_SetKp(1); error(rtn); rtn = GT_SetKi(0); error(rtn); rtn = GT_SetKd(0); error(rtn); rtn=GT_SetKvff(0); error(rtn); rtn=GT_SetKaff(0); error(rtn); rtn=GT_Update(); error(rtn); rtn=GT_AxisOn(); error(rtn); } void CGT3Dlg::OnAxisSmotion() { // TODO: Add your control notification handler code here UpdateData(); if (m_Axis_One_Check&m_Axis_Two_Check) { short rtn; UpdateData(); for(int i=1;i<3;i++) { rtn=GT_Axis(i); rtn=GT_ZeroPos(); rtn=GT_Update(); } rtn=GT_Axis(1); error(rtn); rtn=GT_PrflS(); error(rtn); rtn=GT_SetJerk(m_One_Jerk); error(rtn); rtn=GT_SetMAcc(m_One_MaxAcc); error(rtn); rtn=GT_SetVel(m_One_Vel); error(rtn); rtn=GT_SetPos(m_One_Pos); error(rtn); rtn=GT_Axis(2); error(rtn); rtn=GT_PrflS(); error(rtn); rtn=GT_SetJerk(m_Two_Jerk); error(rtn); rtn=GT_SetMAcc(m_Two_MaxTwo); error(rtn); rtn=GT_SetVel(m_Two_Vel); error(rtn); rtn=GT_SetPos(m_Two_Pos); error(rtn); rtn=GT_MltiUpdt(0x3); error(rtn); } else { if (m_Axis_One_Check) { short rtn; UpdateData(); for(int i=1;i<3;i++) { rtn=GT_Axis(i); rtn=GT_ZeroPos(); rtn=GT_Update(); } rtn=GT_Axis(1); error(rtn); rtn=GT_PrflS(); error(rtn); rtn=GT_SetJerk(m_One_Jerk); error(rtn); rtn=GT_SetMAcc(m_One_MaxAcc); error(rtn); rtn=GT_SetVel(m_One_Vel); error(rtn); rtn=GT_SetPos(m_One_Pos); error(rtn); rtn=GT_Update(); error(rtn); } else { if (m_Axis_Two_Check) { short rtn; UpdateData(); for(int i=1;i<3;i++) { rtn=GT_Axis(i); rtn=GT_ZeroPos(); rtn=GT_Update(); } rtn=GT_Axis(2); error(rtn); rtn=GT_PrflS(); error(rtn); rtn=GT_SetJerk(m_Two_Jerk); error(rtn); rtn=GT_SetMAcc(m_Two_MaxTwo); error(rtn); rtn=GT_SetVel(m_Two_Vel); error(rtn); rtn=GT_SetPos(m_Two_Pos); error(rtn); rtn=GT_Update(); error(rtn); } else { MessageBox("您一根轴都没有选择!","系统提示"); } } } } void CGT3Dlg::OnAxisStop() { // TODO: Add your control notification handler code here short rtn; if (m_Axis_One_Check&m_Axis_Two_Check) { rtn=GT_Axis(1); error(rtn); rtn=GT_SmthStp(); error(rtn); rtn=GT_Axis(2); error(rtn); rtn=GT_SmthStp(); error(rtn); rtn=GT_MltiUpdt(0x3); error(rtn); } else { if (m_Axis_One_Check) { rtn=GT_Axis(1); error(rtn); rtn=GT_SmthStp(); error(rtn); rtn=GT_Update(); error(rtn); } else { if (m_Axis_Two_Check) { rtn=GT_Axis(2); error(rtn); rtn=GT_SmthStp(); error(rtn); rtn=GT_Update(); error(rtn); } else { MessageBox("您一根轴都没有选择!","系统提示"); } } } } void CGT3Dlg::OnAxisClose() { // TODO: Add your control notification handler code here short rtn; for(int i=1;i<3;i++) { rtn=GT_Axis(i); error(rtn); rtn=GT_AxisOff(); error(rtn); } rtn=GT_Close(); error(rtn); } void CGT3Dlg::OnOK() { // TODO: Add extra validation here if (MessageBox("确定已关闭控制器了吗?","系统提示",MB_YESNO|MB_ICONQUESTION)==IDYES) { CDialog::OnOK(); } } void CGT3Dlg::error(short rtn) { switch (rtn) { case -1: MessageBox("error:commuciation error!","系统提示",MB_ICONEXCLAMATION|MB_OK); break; case 0: break; case 1: MessageBox("error:command error!","系统提示",MB_ICONEXCLAMATION|MB_OK); break; case 2: case 3: case 4: case 5: case 7: MessageBox("error:parameter error!","系统提示",MB_ICONEXCLAMATION|MB_OK); break; case 6: MessageBox("error:map error!","系统提示",MB_ICONEXCLAMATION|MB_OK); default: break; } }
求大神给该段代码详细注解(MFC 俄罗斯方块)
// TetrisDlg.cpp : 实现文件 // #include "stdafx.h" #include "myself.h" #include "Tetris.h" #include "TetrisDlg.h" #include <iostream> #include <math.h> // #include<windows.h> // #include <mmsystem.h>//导入声音头文件 // #pragma comment(lib,"winmm.lib")//导入声音头文件库 using namespace std; #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialog { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CTetrisDlg 对话框 CTetrisDlg::CTetrisDlg(CWnd* pParent /*=NULL*/) : CDialog(CTetrisDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTetrisDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CTetrisDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_LBUTTONDOWN() ON_WM_TIMER() ON_WM_KEYDOWN() ON_COMMAND(ID_32771, &CTetrisDlg::On32771) ON_COMMAND(ID_32772, &CTetrisDlg::On32772) ON_COMMAND(ID_32773, &CTetrisDlg::On32773) ON_COMMAND(ID_32775, &CTetrisDlg::On32775) ON_COMMAND(ID_32776, &CTetrisDlg::On32776) ON_COMMAND(ID_32777, &CTetrisDlg::On32777) ON_COMMAND(ID_32779, &CTetrisDlg::On32779) ON_COMMAND(ID_32778, &CTetrisDlg::On32778) END_MESSAGE_MAP() // CTetrisDlg 消息处理程序 BOOL CTetrisDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); 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); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 srand((unsigned)time(NULL)); my_brush.CreateSolidBrush(RGB(0,0,0)); speed=1; score=0; gamestate=STOP; return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CTetrisDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CTetrisDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 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; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CRect rect; CPaintDC dc(this); GetClientRect(rect); dc.FillSolidRect(rect,RGB(0,0,0)); CPen pen(PS_SOLID,1,RGB(255,255,255)); pDC=GetDC(); pDC->SelectObject(&pen); //绘制方框区 pDC->MoveTo(MAINFRAME_X-1,MAINFRAME_Y-1); pDC->LineTo(MAINFRAME_X+MAX_COL*SIZE+1,MAINFRAME_Y-1); pDC->LineTo(MAINFRAME_X+MAX_COL*SIZE+1,MAINFRAME_Y+MAX_ROW*SIZE+1); pDC->LineTo(MAINFRAME_X-1,MAINFRAME_Y+MAX_ROW*SIZE+1); pDC->LineTo(MAINFRAME_X-1,MAINFRAME_Y-1); //绘制预览区 pDC->MoveTo(LOOK_X,LOOK_Y); pDC->LineTo(LOOK_X+6*SIZE,LOOK_Y); pDC->LineTo(LOOK_X+6*SIZE,LOOK_Y+6*SIZE); pDC->LineTo(LOOK_X,LOOK_Y+6*SIZE); pDC->LineTo(LOOK_X,LOOK_Y); //绘制文字 pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); pDC->TextOut(LOOK_X,LOOK_Y+SIZE*6+20,_T("Score:"),6); pDC->SetTextColor(RGB(0,255,0)); pDC->TextOut(LOOK_X,LOOK_Y+SIZE*6+55,_T("Speed:"),6); //绘制图标 BITMAP bm1; CDC MemDC1; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_PAUSE); my_bitmap.GetObject(sizeof(BITMAP),&bm1); MemDC1.CreateCompatibleDC(pDC); MemDC1.SelectObject(&my_bitmap); pDC->StretchBlt(LOOK_X+45,LOOK_Y+SIZE*6+175,bm1.bmWidth,bm1.bmHeight,&MemDC1,0,0,40,40,SRCCOPY); my_bitmap.DeleteObject(); BITMAP bm2; CDC MemDC2; my_bitmap.LoadBitmap(IDB_START); my_bitmap.GetObject(sizeof(BITMAP),&bm2); MemDC2.CreateCompatibleDC(pDC); MemDC2.SelectObject(&my_bitmap); pDC->StretchBlt(LOOK_X+45,LOOK_Y+SIZE*6+100,bm2.bmWidth,bm2.bmHeight,&MemDC2,0,0,40,40,SRCCOPY); my_bitmap.DeleteObject(); BITMAP bm3; CDC MemDC3; my_bitmap.LoadBitmap(IDB_STOP); my_bitmap.GetObject(sizeof(BITMAP),&bm3); MemDC3.CreateCompatibleDC(pDC); MemDC3.SelectObject(&my_bitmap); pDC->StretchBlt(LOOK_X+45,LOOK_Y+SIZE*6+250,bm3.bmWidth,bm3.bmHeight,&MemDC3,0,0,40,40,SRCCOPY); my_bitmap.DeleteObject(); DrawNextState(LOOK_X,LOOK_Y); for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_STATE_NOT_EMPTY) { BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); pDC->StretchBlt(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,SIZE,SIZE,&MemDC,0,0,SIZE,SIZE,SRCCOPY); my_bitmap.DeleteObject(); } else if (stateMap[i][j]==MAP_FALLING) { BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); pDC->StretchBlt(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); my_bitmap.DeleteObject(); } else { CRect my(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,MAINFRAME_X+j*SIZE+SIZE,MAINFRAME_Y+i*SIZE+SIZE); pDC=GetDC(); pDC->FillRect(my,&my_brush); } } } pDC=GetDC(); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+20,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); pDC=GetDC(); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); CString Cscore; Cscore.Format(_T("%d"),score); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+20,Cscore,Cscore.GetLength()); CString Cspeed; switch(speed) { case 1: Cspeed.Format(_T("简单")); break; case 2: Cspeed.Format(_T("一般")); break; case 3: Cspeed.Format(_T("困难")); break; } pDC->SetTextColor(RGB(0,255,0)); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+55,Cspeed,Cspeed.GetLength()); CDialog::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CTetrisDlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); } void CTetrisDlg::start() { score=0; InitMap(); Produce_NextState(); NexttoActive(); Produce_NextState(); ActivetoMap(); pDC=GetDC(); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); CString Cscore; Cscore.Format(_T("%d"),score); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+20,Cscore,Cscore.GetLength()); CString Cspeed; switch(speed) { case 1: Cspeed.Format(_T("简单")); break; case 2: Cspeed.Format(_T("一般")); break; case 3: Cspeed.Format(_T("困难")); break; } pDC->SetTextColor(RGB(0,255,0)); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+55,Cspeed,Cspeed.GetLength()); if (gamestate==OVER) gameover(); } void CTetrisDlg::Produce_NextState() { int Shape=rand()%7; NextColor=rand()%4+1; switch(Shape) //调试中 { case 0: { switch(rand()%4) { case 0: //山条,完成 { NextState[0][0]=2; NextState[0][1]=0; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=1; NextState[3][0]=2; NextState[3][1]=2; break; } case 1: { NextState[0][0]=2; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=2; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=3; NextState[3][1]=2; break; } case 2: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=2; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=1; NextState[3][1]=3; break; } case 3: { NextState[0][0]=0; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=1; NextState[3][0]=1; NextState[3][1]=2; break; } default:break; } break; } case 1: //长条,完成 { switch(rand()%4) { case 0: { NextState[0][0]=0; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=1; NextState[3][0]=3; NextState[3][1]=1; break; } case 1: { NextState[0][0]=2; NextState[0][1]=0; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=3; break; } case 2: { NextState[0][0]=0; NextState[0][1]=2; NextState[1][0]=1; NextState[1][1]=2; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=3; NextState[3][1]=2; break; } case 3: { NextState[0][0]=1; NextState[0][1]=0; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=1; NextState[3][1]=3; break; } default:break; } break; } case 2: //L,完成 { switch(rand()%4) { case 0: { NextState[0][0]=2; NextState[0][1]=0; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=2; break; } case 1: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=2; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=3; NextState[3][1]=2; break; } case 2: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=1; NextState[3][1]=3; break; } case 3: { NextState[0][0]=0; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=1; NextState[3][0]=2; NextState[3][1]=2; break; } default:break; } break; } case 3: //倒L,完成 { switch(rand()%4) { case 0: { NextState[0][0]=1; NextState[0][1]=0; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=2; break; } case 1: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=3; NextState[2][1]=1; NextState[3][0]=1; NextState[3][1]=2; break; } case 2: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=3; break; } case 3: { NextState[0][0]=2; NextState[0][1]=1; NextState[1][0]=0; NextState[1][1]=2; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=2; break; } default:break; } break; } case 4: //正Z { switch(rand()%4) { case 0: { NextState[0][0]=1; NextState[0][1]=0; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=1; NextState[3][0]=2; NextState[3][1]=2; break; } case 1: { NextState[0][0]=2; NextState[0][1]=1; NextState[1][0]=3; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=2; break; } case 2: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=2; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=3; break; } case 3: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=0; NextState[2][1]=2; NextState[3][0]=1; NextState[3][1]=2; break; } default:break; } break; } case 5: //倒Z { switch(rand()%4) { case 0: { NextState[0][0]=2; NextState[0][1]=0; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=1; NextState[3][0]=1; NextState[3][1]=2; break; } case 1: { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=3; NextState[3][1]=2; break; } case 2: { NextState[0][0]=2; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=2; NextState[2][0]=2; NextState[2][1]=2; NextState[3][0]=1; NextState[3][1]=3; break; } case 3: { NextState[0][0]=0; NextState[0][1]=1; NextState[1][0]=1; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=2; break; } default:break; } break; } case 6: //方格,完成 { NextState[0][0]=1; NextState[0][1]=1; NextState[1][0]=2; NextState[1][1]=1; NextState[2][0]=1; NextState[2][1]=2; NextState[3][0]=2; NextState[3][1]=2; break; } default:break; } } void CTetrisDlg::NexttoActive() { for (int i=0;i<4;i++) for (int j=0;j<2;j++) ActiveState[i][j]=NextState[i][j]; ActiveColor=NextColor; } void CTetrisDlg::DrawNextState(int x,int y) { BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); for (int i=0;i<4;i++) { if (NextState[i][1]>=0&&NextState[i][0]>=0) pDC->StretchBlt(x+SIZE+NextState[i][1]*SIZE,y+SIZE+NextState[i][0]*SIZE,bm.bmWidth,SIZE,&MemDC,0,SIZE*NextColor,SIZE,SIZE,SRCCOPY); } my_bitmap.DeleteObject(); } void CTetrisDlg::ActivetoMap() { int min_row; int min_col; min_row=ActiveState[0][0]; if (ActiveState[1][0]<min_row) min_row=ActiveState[1][0]; if (ActiveState[2][0]<min_row) min_row=ActiveState[2][0]; if (ActiveState[3][0]<min_row) min_row=ActiveState[3][0]; min_col=ActiveState[0][1]; if (ActiveState[1][1]<min_col) min_col=ActiveState[1][1]; if (ActiveState[2][1]<min_col) min_col=ActiveState[2][1]; if (ActiveState[3][1]<min_col) min_col=ActiveState[3][1]; for (int i=0;i<4;i++) { if (stateMap[ActiveState[i][0]-min_row][MAX_COL/2-1+ActiveState[i][1]-min_col]==MAP_STATE_NOT_EMPTY) { gamestate=OVER; break; } else stateMap[ActiveState[i][0]-min_row][MAX_COL/2-1+ActiveState[i][1]-min_col]=MAP_FALLING; } } void CTetrisDlg::OnLButtonDown(UINT nFlags, CPoint point) { if ((point.x>=LOOK_X+45)&&(point.x<=LOOK_X+85)&&(point.y>=(LOOK_Y+SIZE*6+100))&&(point.y<=(LOOK_Y+SIZE*6+140))&&gamestate>=STOP) { SetTimer(1,600/speed,NULL); start(); gamestate=PLAY; OnPaint(); } if ((point.x>=LOOK_X+45)&&(point.x<=LOOK_X+85)&&(point.y>=(LOOK_Y+SIZE*6+100))&&(point.y<=(LOOK_Y+SIZE*6+140))&&gamestate==PAUSE) { SetTimer(1,600/speed,NULL); gamestate=PLAY; } if ((point.x>=LOOK_X+45)&&(point.x<=LOOK_X+85)&&(point.y>=(LOOK_Y+SIZE*6+175))&&(point.y<=(LOOK_Y+SIZE*6+215))&&gamestate==PLAY) { KillTimer(1); gamestate=PAUSE; } if ((point.x>=LOOK_X+45)&&(point.x<=LOOK_X+85)&&(point.y>=(LOOK_Y+SIZE*6+250))&&(point.y<=(LOOK_Y+SIZE*6+290))&&gamestate<=PAUSE) { KillTimer(1); pDC=GetDC(); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+20,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); InitMap(); InitNextAndActive(); gamestate=STOP; DrawMapBlack(); DrawLookBlack(); } CDialog::OnLButtonDown(nFlags, point); } void CTetrisDlg::OnTimer(UINT_PTR nIDEvent) { if (nIDEvent==1) { if (IsBottom()==1) { for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { stateMap[i][j]=MAP_STATE_NOT_EMPTY; BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); pDC->StretchBlt(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,SIZE,SIZE,&MemDC,0,0,SIZE,SIZE,SRCCOPY); my_bitmap.DeleteObject(); } } } Sweep(); NexttoActive(); Produce_NextState(); DrawLookBlack(); DrawNextState(LOOK_X,LOOK_Y); ActivetoMap(); if (gamestate==OVER) gameover(); else { BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); for (int i=0;i<4;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { pDC->StretchBlt(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); } } } my_bitmap.DeleteObject(); } } else { BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); for (int i=MAX_ROW-1;i>=0;i--) { for (int j=MAX_COL-1;j>=0;j--) { if (stateMap[i][j]==MAP_FALLING) { stateMap[i][j]=MAP_STATE_EMPTY; stateMap[i+1][j]=MAP_FALLING; pDC->StretchBlt(MAINFRAME_X+j*SIZE,MAINFRAME_Y+(i+1)*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); CRect my(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,MAINFRAME_X+j*SIZE+SIZE,MAINFRAME_Y+i*SIZE+SIZE); pDC=GetDC(); pDC->FillRect(my,&my_brush); } } } my_bitmap.DeleteObject(); } } KillTimer(1); SetTimer(1,600/speed,NULL); CDialog::OnTimer(nIDEvent); } int CTetrisDlg::IsLeftLimit() //1代表不能左移 { for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { if ((j==0)||stateMap[i][j-1]==MAP_STATE_NOT_EMPTY) return 1; } } } return 0; } int CTetrisDlg::IsRightLimit() { for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { if ((j==MAX_COL-1)||stateMap[i][j+1]==MAP_STATE_NOT_EMPTY) return 1; } } } return 0; } int CTetrisDlg::IsBottom() { for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { if ((i==MAX_ROW-1)||stateMap[i+1][j]==MAP_STATE_NOT_EMPTY) { return 1; } } } } return 0; } void CTetrisDlg::InitMap() { for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { stateMap[i][j]=MAP_STATE_EMPTY; } } } void CTetrisDlg::InitNextAndActive() { for (int i=0;i<4;i++) { for (int j=0;j<2;j++) { NextState[i][j]=-1; ActiveState[i][j]=-1; } } } void CTetrisDlg::DrawMapBlack() { for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { CRect my(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,MAINFRAME_X+j*SIZE+SIZE,MAINFRAME_Y+i*SIZE+SIZE); pDC=GetDC(); pDC->FillRect(my,&my_brush); } } } void CTetrisDlg::DrawLookBlack() { CRect my(LOOK_X+1,LOOK_Y+1,LOOK_X+6*SIZE-1,LOOK_Y+6*SIZE-1); pDC=GetDC(); pDC->FillRect(my,&my_brush); } void CTetrisDlg::gameover() { KillTimer(1); CString notice; notice.Format(_T("GAME IS OVER!\nYOUR SCORE IS %d"),score); AfxMessageBox(notice); /////////////////////////////////////////清除记录的数字 pDC=GetDC(); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+20,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); InitMap(); InitNextAndActive(); gamestate=STOP; DrawMapBlack(); DrawLookBlack(); } void CTetrisDlg::RectLeft() { //PlaySound(_T("sounds\\rotateANDmove.WAV"),NULL,SND_FILENAME|SND_ASYNC); if (IsLeftLimit()==0) { int temp[4][2]; int count=0; for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { stateMap[i][j-1]=MAP_FALLING; stateMap[i][j]=MAP_STATE_EMPTY; temp [count][0]=i; temp [count][1]=j-1; count++; } } } BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); count--; for (;count>=0;count--) pDC->StretchBlt(MAINFRAME_X+temp[count][1]*SIZE,MAINFRAME_Y+temp[count][0]*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); my_bitmap.DeleteObject(); for (int i=0;i<4;i++) { if (stateMap[temp[i][0]][temp[i][1]+1]==MAP_STATE_EMPTY) { CRect my(MAINFRAME_X+(temp[i][1]+1)*SIZE,MAINFRAME_Y+temp[i][0]*SIZE,MAINFRAME_X+SIZE+(temp[i][1]+1)*SIZE,MAINFRAME_Y+SIZE+temp[i][0]*SIZE); pDC->FillRect(my,&my_brush); } } } } void CTetrisDlg::RectRight() { if (IsRightLimit()==0) { int temp[4][2]; int count=0; for (int i=0;i<MAX_ROW;i++) { for (int j=MAX_COL-1;j>=0;j--) { if (stateMap[i][j]==MAP_FALLING) { stateMap[i][j+1]=MAP_FALLING; stateMap[i][j]=MAP_STATE_EMPTY; temp [count][0]=i; temp [count][1]=j+1; count++; } } } BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); count--; for (;count>=0;count--) pDC->StretchBlt(MAINFRAME_X+temp[count][1]*SIZE,MAINFRAME_Y+temp[count][0]*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); my_bitmap.DeleteObject(); for (int i=0;i<4;i++) { if (stateMap[temp[i][0]][temp[i][1]-1]==MAP_STATE_EMPTY) { CRect my(MAINFRAME_X+(temp[i][1]-1)*SIZE,MAINFRAME_Y+temp[i][0]*SIZE,MAINFRAME_X+SIZE+(temp[i][1]-1)*SIZE,MAINFRAME_Y+SIZE+temp[i][0]*SIZE); pDC->FillRect(my,&my_brush); } } } } void CTetrisDlg::RectUp() //逆时针旋转 { bool choice; int temp[4][2]; for (int i=0;i<4;i++) { temp[i][1]=ActiveState[i][0]; temp[i][0]=3-ActiveState[i][1]; } int locate[4][2]; //将旋转前falling状态的方块记住 int count=0; for (int j=0;j<MAX_COL;j++) { for (int i=0;i<MAX_ROW;i++) { if (stateMap[i][j]==MAP_FALLING) { locate[count][0]=i; locate[count][1]=j; ++count; } } } --count; int travel[4][2]; //将旋转后的falling状态的方块记住 for (int i=0;i<4;i++) for (int j=0;j<2;j++) travel[i][j]=locate[i][j]+(temp[i][j]-ActiveState[i][j]); choice=TRUE; for (int i=0;i<4;i++) { if (!(travel[i][0]>=0&&travel[i][0]<MAX_ROW&&travel[i][1]>=0&&travel[i][1]<MAX_COL&&stateMap[travel[i][0]][travel[i][1]]!=MAP_STATE_NOT_EMPTY)) choice=FALSE; } if (choice==TRUE) { pDC=GetDC(); for (int i=0;i<4;i++) { stateMap[locate[i][0]][locate[i][1]]=MAP_STATE_EMPTY; //zuotu CRect my(MAINFRAME_X+locate[i][1]*SIZE,MAINFRAME_Y+locate[i][0]*SIZE,MAINFRAME_X+SIZE+locate[i][1]*SIZE,MAINFRAME_Y+SIZE+locate[i][0]*SIZE); pDC->FillRect(my,&my_brush); } BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); for (int i=0;i<4;i++) { stateMap[travel[i][0]][travel[i][1]]=MAP_FALLING; //zuotu pDC->StretchBlt(MAINFRAME_X+travel[i][1]*SIZE,MAINFRAME_Y+travel[i][0]*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); } my_bitmap.DeleteObject(); for (int i=0;i<4;i++) for (int j=0;j<2;j++) ActiveState[i][j]=temp[i][j]; for (int j=0;j<3;j++) { for (int i=2;i>=j;i--) if (ActiveState[i][1]>ActiveState[i+1][1]||(ActiveState[i][1]==ActiveState[i+1][1]&&ActiveState[i][0]>ActiveState[i+1][0])) { int x=ActiveState[i+1][0]; int y=ActiveState[i+1][1]; ActiveState[i+1][0]=ActiveState[i][0]; ActiveState[i+1][1]=ActiveState[i][1]; ActiveState[i][0]=x; ActiveState[i][1]=y; } } } } void CTetrisDlg::RectDown() { int temp[4][2]; int origin[4][2]; int count=0; for (int i=0;i<MAX_ROW;i++) { for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_FALLING) { origin[count][0]=temp [count][0]=i; origin[count][1]=temp [count][1]=j; count++; } } } if (!IsBottom()) { for (int i=3;i>=0;i--) { stateMap [temp[i][0]+1][temp[i][1]]=MAP_FALLING; stateMap [temp[i][0]][temp[i][1]]=MAP_STATE_EMPTY; temp[i][0]++; } } for (int i=0;i<4;i++) { if (stateMap[origin[i][0]][origin[i][1]]==MAP_STATE_EMPTY) { CRect my(MAINFRAME_X+(origin[i][1])*SIZE,MAINFRAME_Y+origin[i][0]*SIZE,MAINFRAME_X+(origin[i][1])*SIZE+SIZE,MAINFRAME_Y+origin[i][0]*SIZE+SIZE); pDC->FillRect(my,&my_brush); } } BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); for (int i=0;i<4;i++) pDC->StretchBlt(MAINFRAME_X+temp[i][1]*SIZE,MAINFRAME_Y+temp[i][0]*SIZE,SIZE,SIZE,&MemDC,0,SIZE*ActiveColor,SIZE,SIZE,SRCCOPY); my_bitmap.DeleteObject(); } BOOL CTetrisDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN&&gamestate==PLAY) { switch(pMsg->wParam) { case VK_LEFT: RectLeft(); break; case VK_RIGHT: RectRight(); break; case VK_UP: RectUp(); break; case VK_DOWN: RectDown(); break; } } return CDialog::PreTranslateMessage(pMsg); } void CTetrisDlg::Sweep() { bool m_sweep; int bottom; int judge=0; int ii=0; for (int i=MAX_ROW-1;i>=0;i--) { m_sweep=TRUE; for (int j=0;j<MAX_COL;j++) { if(stateMap[i][j]==MAP_STATE_EMPTY) { m_sweep=FALSE; break; } } if (m_sweep) { if (judge!=1) { bottom=i; judge=1; } for (int k=i;k>0;k--) { for (int l=0;l<MAX_COL;l++) { stateMap[k][l]=stateMap[k-1][l]; } } for (int l=0;l<MAX_COL;l++) stateMap[0][l]=MAP_STATE_EMPTY; i++; ii++; } } if (judge==1) { BITMAP bm; CDC MemDC; pDC=GetDC(); my_bitmap.LoadBitmap(IDB_SQUARE); my_bitmap.GetObject(sizeof(BITMAP),&bm); MemDC.CreateCompatibleDC(pDC); MemDC.SelectObject(&my_bitmap); for (int i=bottom;i>=0;i--) for (int j=0;j<MAX_COL;j++) { if (stateMap[i][j]==MAP_STATE_NOT_EMPTY) pDC->StretchBlt(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,SIZE,SIZE,&MemDC,0,0,SIZE,SIZE,SRCCOPY); else { CRect my(MAINFRAME_X+j*SIZE,MAINFRAME_Y+i*SIZE,MAINFRAME_X+j*SIZE+SIZE,MAINFRAME_Y+i*SIZE+SIZE); pDC->FillRect(my,&my_brush); } } my_bitmap.DeleteObject(); score+=ii*ii*100; CRect my(LOOK_X+50,LOOK_Y+SIZE*6+20,LOOK_X+100,LOOK_Y+SIZE*6+55); pDC=GetDC(); pDC->FillRect(my,&my_brush); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); CString Cscore; Cscore.Format(_T("%d"),score); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+20,Cscore,Cscore.GetLength()); // PlaySound(_T("sounds\\line.WAV"),NULL,SND_FILENAME|SND_ASYNC); } } void CTetrisDlg::On32771() { if (gamestate>=STOP) { SetTimer(1,600/speed,NULL); start(); gamestate=PLAY; OnPaint(); } if (gamestate==PAUSE) { SetTimer(1,600/speed,NULL); gamestate=PLAY; } } void CTetrisDlg::On32772() { if (gamestate==PLAY) { KillTimer(1); gamestate=PAUSE; } } void CTetrisDlg::On32773() { if (gamestate<=PAUSE) { KillTimer(1); pDC=GetDC(); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+20,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); InitMap(); InitNextAndActive(); gamestate=STOP; DrawMapBlack(); DrawLookBlack(); } } void CTetrisDlg::On32775() { speed=1; pDC=GetDC(); pDC->SetBkMode(TRANSPARENT); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+55,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); CString Cspeed; Cspeed.Format(_T("简单")); pDC->SetTextColor(RGB(0,255,0)); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+55,Cspeed,Cspeed.GetLength()); } void CTetrisDlg::On32776() { speed=2; pDC=GetDC(); pDC->SetBkMode(TRANSPARENT); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+55,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); CString Cspeed; Cspeed.Format(_T("一般")); pDC->SetTextColor(RGB(0,255,0)); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+55,Cspeed,Cspeed.GetLength()); } void CTetrisDlg::On32777() { speed=3; pDC=GetDC(); pDC->SetBkMode(TRANSPARENT); CRect my(LOOK_X+50,LOOK_Y+SIZE*6+55,LOOK_X+6*SIZE,LOOK_Y+SIZE*6+100); pDC->FillRect(my,&my_brush); CString Cspeed; Cspeed.Format(_T("困难")); pDC->SetTextColor(RGB(0,255,0)); pDC->TextOut(LOOK_X+50,LOOK_Y+SIZE*6+55,Cspeed,Cspeed.GetLength()); } void CTetrisDlg::On32779() { OnCancel(); } void CTetrisDlg::On32778() { AfxMessageBox(_T("通过键盘控制方块移动和旋转\n上:旋转物块\n下:加速下滑\n左、右:左右移动\n当一行全部填满可消去")); } void CTetrisDlg::OnOK() {} // PlaySound(_T("sounds\\question.wav"),NULL,SND_FILENAME|SND_ASYNC);
新人求教,我用mfc做了一个tcp fin的端口扫描器,死后得不出结果,求大神帮忙找出问题
cpp文件 // scanDlg.cpp : implementation file // #include "stdafx.h" #include "scan.h" #include "scanDlg.h" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialogEx { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // CscanDlg dialog CscanDlg::CscanDlg(CWnd* pParent /*=NULL*/) : CDialogEx(CscanDlg::IDD, pParent) , m_star_port(_T("")) , m_end_port(_T("")) , m_IP(_T("")) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CscanDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_list); DDX_Text(pDX, IDC_EDIT2, m_star_port); DDX_Text(pDX, IDC_EDIT3, m_end_port); DDX_Text(pDX, IDC_EDIT1, m_IP); } BEGIN_MESSAGE_MAP(CscanDlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, &CscanDlg::OnBnClickedButton1) END_MESSAGE_MAP() // CscanDlg message handlers BOOL CscanDlg::OnInitDialog() { CDialogEx::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); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } hostent* CscanDlg::g_pHost = 0; SOCKET CscanDlg::sock = 0; void CscanDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::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. void CscanDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 { CDialogEx::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CscanDlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); } void CscanDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here send_revc((LPSTR)(LPCTSTR)m_IP,(LPSTR)(LPCTSTR)m_star_port,(LPSTR)(LPCTSTR)m_end_port,&m_list);//char ch1[],char tr1[],char tr2[] } void CscanDlg ::send_revc(char ch1[],char tr1[],char tr2[],CListBox* m_list) { WSADATA WSAData; WSAStartup(MAKEWORD(2,2), &WSAData); sock=WSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED);//定义套接字 BOOL flag = true; setsockopt(sock,IPPROTO_IP, IP_HDRINCL,(char *)&flag,sizeof(flag)); char sLocalName[64]; gethostname((char*)sLocalName, sizeof(sLocalName)-1); g_pHost = gethostbyname(sLocalName); sockaddr_in addr_local; addr_local.sin_addr = *(in_addr *)g_pHost->h_addr_list[0]; //绑定到本地网卡,INADDR_ANY不行 addr_local.sin_family = AF_INET;// addr_local.sin_port = htons(SOURCE_PORT); bind(sock, (PSOCKADDR)&addr_local, sizeof(sockaddr_in));//绑套接字 DWORD dwValue = 1; SADDR sAddr; USHORT int1,int2; sAddr.m_destip=ch1; sAddr.m_starpost=atoi(tr1); sAddr.m_endpost=atoi(tr2); ioctlsocket(sock, SIO_RCVALL, &dwValue); int nTimeOut = 500;//设置超时 setsockopt(sock,SOL_SOCKET, SO_SNDTIMEO, (char*)&nTimeOut, sizeof(nTimeOut)); HANDLE threads[2];//开双线程 threads[0] = CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)revcfunc,(LPVOID)m_list,0,NULL); threads[1] = CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)sendfunc,(LPVOID)(&sAddr), 0,NULL); WaitForMultipleObjects(2,threads,FALSE,INFINITE); } USHORT CscanDlg ::checksumfunc(USHORT *buffer, int size)//检验和函数 { unsigned long cksum=0; while(size >1) { cksum+=*buffer++; size -=sizeof(USHORT); } if(size) { cksum += *(UCHAR*)buffer; } cksum = (cksum >> 16) + (cksum & 0xffff); cksum += (cksum >>16); return (USHORT)(~cksum); } void CscanDlg ::sendfunc(SADDR* sAddr ) { IP_HEADER ipHeader; TCP_HEADER tcpHeader; PSD_HEADER psdHeader; char Sendto_Buff[MAX_BUFF_LEN]; //发送缓冲区 unsigned short check_Buff[MAX_BUFF_LEN]; //检验和缓冲区 const char tcp_send_data[]={"This is my homework of networt,I am happy!"}; BOOL flag; int rect,nTimeOver; //先试一下在外面弄好套接字初始化行不行 flag=true; nTimeOver=1000; //填充IP首部 ipHeader.h_verlen=(IPVER<<4 | sizeof(ipHeader)/sizeof(unsigned long)); ipHeader.tos=(UCHAR)0; ipHeader.total_len=htons((unsigned short)sizeof(ipHeader)+sizeof(tcpHeader)+sizeof(tcp_send_data)); ipHeader.ident=0; //16位标识 ipHeader.frag_and_flags=0; //3位标志位 ipHeader.ttl=128; //8位生存时间 ipHeader.proto=IPPROTO_UDP; //协议类型 ipHeader.checksum=0; //检验和暂时为0 ipHeader.sourceIP=*(int*)g_pHost->h_addr_list[0]; //32位源IP地址可以直接获取 ipHeader.destIP=inet_addr(sAddr->m_destip); //32位目的IP地址 //计算IP头部检验和 memset(check_Buff,0,MAX_BUFF_LEN); memcpy(check_Buff,&ipHeader,sizeof(IP_HEADER)); ipHeader.checksum=checksumfunc(check_Buff,sizeof(IP_HEADER)); //构造TCP伪首部 psdHeader.saddr=ipHeader.sourceIP; psdHeader.daddr=ipHeader.destIP; psdHeader.mbz=0; psdHeader.ptcl=ipHeader.proto; psdHeader.tcpl=htons(sizeof(TCP_HEADER)+sizeof(tcp_send_data)); for(int i=sAddr->m_starpost;i<sAddr->m_endpost;i++) //填充TCP首部 { tcpHeader.th_dport=htons(i); //16位目的端口号 tcpHeader.th_sport=htons(SOURCE_PORT); //16位源端口号 tcpHeader.th_seq=0; //SYN序列号 tcpHeader.th_ack=0; //ACK序列号置为0 //TCP长度和保留位 tcpHeader.th_lenres=(sizeof(tcpHeader)/sizeof(unsigned long)<<4|0); tcpHeader.th_flag=1; //修改这里来实现不同的标志位探测,2是SYN,1是//FIN,16是ACK探测 等等 tcpHeader.th_win=htons((unsigned short)16384); //窗口大小 tcpHeader.th_urp=0; //偏移大小 tcpHeader.th_sum=0; //检验和暂时填为0 //计算TCP校验和 memset(check_Buff,0,MAX_BUFF_LEN); memcpy(check_Buff,&psdHeader,sizeof(psdHeader)); memcpy(check_Buff+sizeof(psdHeader),&tcpHeader,sizeof(tcpHeader)); memcpy(check_Buff+sizeof(PSD_HEADER)+sizeof(TCP_HEADER), tcp_send_data,sizeof(tcp_send_data)); tcpHeader.th_sum=checksumfunc(check_Buff,sizeof(PSD_HEADER)+ sizeof(TCP_HEADER)+sizeof(tcp_send_data)); //填充发送缓冲区 memset(Sendto_Buff,0,MAX_BUFF_LEN); memcpy(Sendto_Buff,&ipHeader,sizeof(IP_HEADER)); memcpy(Sendto_Buff+sizeof(IP_HEADER),&tcpHeader, sizeof(TCP_HEADER)); memcpy(Sendto_Buff+sizeof(IP_HEADER)+sizeof(TCP_HEADER), tcp_send_data,sizeof(tcp_send_data)); int datasize=sizeof(IP_HEADER)+sizeof(TCP_HEADER)+ sizeof(tcp_send_data); //发送数据报的目的地址 SOCKADDR_IN dest; memset(&dest,0,sizeof(dest)); dest.sin_family=AF_INET; dest.sin_addr.s_addr=inet_addr(sAddr->m_destip); dest.sin_port=htons(i); rect=sendto(sock,Sendto_Buff,datasize, 0,(struct sockaddr*)&dest, sizeof(dest)); } } void CscanDlg ::revcfunc(CListBox* m_list) { CString str; char RecvBuf[MAX_BUFF_LEN]; IP_HEADER* ip; TCP_HEADER* tcp; while(1) { int ret = recv(sock, RecvBuf, MAX_BUFF_LEN, 0); if (ret > 0) { ip = (IP_HEADER*)RecvBuf; tcp = (TCP_HEADER*)(RecvBuf + (ip->h_verlen&0x0f)*4); str.Format(_T("%hu"), tcp->th_sport); m_list->AddString(str); } else str.Format(_T("%d"),ret),m_list->AddString(str); } } 头文件// scanDlg.h : header file // #pragma once #include<winsock2.h> #include<ws2tcpip.h> #include<stdio.h> #pragma comment(lib,"ws2_32.lib") //#define SIO_RCVALL_WSAIOW(IOC_VENDOR,1) #include <stdlib.h> #include <windows.h> #include <time.h> #include "afxwin.h" #define IPVER 4 //IP协议预定 #define MAX_BUFF_LEN 65500 //发送缓冲区最大值 #define SIO_RCVALL _WSAIOW(IOC_VENDOR,1) #define SOURCE_PORT 8088 //local TCP segment source port // CscanDlg dialog class CscanDlg : public CDialogEx { // Construction public: CscanDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data enum { IDD = IDD_SCAN_DIALOG }; typedef struct ip_hdr //定义IP首部 { UCHAR h_verlen; //4位首部长度,4位IP版本号 UCHAR tos; //8位服务类型TOS USHORT total_len; //16位总长度(字节) USHORT ident; //16位标识 USHORT frag_and_flags; //3位标志位 UCHAR ttl; //8位生存时间 TTL UCHAR proto; //8位协议 (TCP, UDP 或其他) USHORT checksum; //16位IP首部校验和 ULONG sourceIP; //32位源IP地址 ULONG destIP; //32位目的IP地址 }IP_HEADER; typedef struct tsd_hdr //定义TCP伪首部 { ULONG saddr; //源地址 ULONG daddr; //目的地址 UCHAR mbz; //没用 UCHAR ptcl; //协议类型 USHORT tcpl; //TCP长度 }PSD_HEADER; typedef struct tcp_hdr //定义TCP首部 { USHORT th_sport; //16位源端口 USHORT th_dport; //16位目的端口 ULONG th_seq; //32位序列号 ULONG th_ack; //32位确认号 UCHAR th_lenres; //4位首部长度/6位保留字 UCHAR th_flag; //6位标志位 USHORT th_win; //16位窗口大小 USHORT th_sum; //16位校验和 USHORT th_urp; //16位紧急数据偏移量 }TCP_HEADER; typedef struct SADDR //定义TCP首部 { char* m_destip; USHORT m_starpost; USHORT m_endpost; }; USHORT static checksumfunc(USHORT *buffer, int size); void static sendfunc(SADDR* sAddr); void static revcfunc(CListBox* m_list); void send_revc(char ch1[],char tr1[],char tr2[],CListBox* m_list); SOCKET static sock; //用于收发TCP报文段的全局socket hostent static *g_pHost; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: HICON m_hIcon; // Generated message map functions virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() public: CListBox m_list; afx_msg void OnBnClickedButton1(); CString m_star_port; CString m_end_port; CString m_IP; };
程序编译出错 missing ';' before identifier 'm_ActiveMovie'
错误: c:\users\administrator.win-42esb6vovun\desktop\lilymp\lilympdlg.h(40) : error C2146: syntax error : missing ';' before identifier 'm_ActiveMovie' c:\users\administrator.win-42esb6vovun\desktop\lilymp\lilympdlg.h(40) : error C2501: 'CWMPPlayer4' : missing storage-class or type specifiers c:\users\administrator.win-42esb6vovun\desktop\lilymp\lilympdlg.h(40) : error C2501: 'm_ActiveMovie' : missing storage-class or type specifiers C:\Users\Administrator.WIN-42ESB6VOVUN\Desktop\LilyMP\LilyMPDlg.cpp(7) : fatal error C1083: Cannot open include file: 'activemovie3.h': No such file or directory 代码: // LilyMPDlg.cpp : implementation file // #pragma once #include "stdafx.h" #include "LilyMP.h" #include "LilyMPDlg.h" #include "activemovie3.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLilyMPDlg dialog CLilyMPDlg::CLilyMPDlg(CWnd* pParent /*=NULL*/) : CDialog(CLilyMPDlg::IDD, pParent) { //{{AFX_DATA_INIT(CLilyMPDlg) m_pathname = _T(""); m_player = 0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CLilyMPDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CLilyMPDlg) DDX_Control(pDX, IDC_BUTTON9, m_delvol); DDX_Control(pDX, IDC_LIST2, m_list); DDX_Control(pDX, IDC_BUTTON8, m_addvol); DDX_Control(pDX, IDC_BUTTON6, m_next); DDX_Control(pDX, IDC_BUTTON5, m_circle); DDX_Control(pDX, IDC_BUTTON4, m_pause); DDX_Control(pDX, IDC_BUTTON3, m_upper); DDX_Control(pDX, IDC_BUTTON2, m_play); DDX_Control(pDX, IDC_BUTTON10, m_mute); DDX_Control(pDX, IDC_BUTTON1, m_open); DDX_LBString(pDX, IDC_LIST2, m_pathname); DDX_Slider(pDX, IDC_SLIDER1, m_player); DDX_Control(pDX, IDC_OCX6, m_ActiveMovie); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CLilyMPDlg, CDialog) //{{AFX_MSG_MAP(CLilyMPDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnOpen) ON_BN_CLICKED(IDC_BUTTON2, OnPlay) ON_BN_CLICKED(IDC_BUTTON3, OnUpper) ON_BN_CLICKED(IDC_BUTTON4, OnPause) ON_BN_CLICKED(IDC_BUTTON6, OnNext) ON_BN_CLICKED(IDC_BUTTON5, OnCircle) ON_BN_CLICKED(IDC_BUTTON8, OnAddvol) ON_BN_CLICKED(IDC_BUTTON9, OnDelvol) ON_BN_CLICKED(IDC_BUTTON10, OnMute) ON_NOTIFY(NM_OUTOFMEMORY, IDC_SLIDER1, OnOutofmemorySlider1) ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLilyMPDlg message handlers BOOL CLilyMPDlg::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); 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 // TODO: Add extra initialization here /*this->m_pause.EnableWindow(FALSE); this->m_play.EnableWindow(FALSE); this->m_next.EnableWindow(FALSE); this->m_circle.EnableWindow(FALSE);*/ return TRUE; // return TRUE unless you set the focus to a control } void CLilyMPDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CLilyMPDlg::OnPaint() { if (IsIconic()) { 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 CLilyMPDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CLilyMPDlg::OnOpen() //添加文件到列表 { char szFileFilter[]= "所有文件(*.*)|*.*|" //可选择所有格式的媒体文件 "avi FILE(*.avi)|*.avi|" "mp3 FILE(*.mp3)|*.mp3|" "mpeg FILE(*.mpeg)|*.mpeg|" "mpga FILE(*.mpga)|*.mpga|" "wave FILE(*.wav)|*.wav|" "movie FILE(*.mov)|*.mov|" "mid FILE(*.mid;*.rmi)|*.mid;*.rmi|" "wma FILE(*.wma)|*.wma|" "media FILE(*.asf)|*.asf|"; CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter); POSITION pos=dlg.GetStartPosition(); if(dlg.DoModal()==IDOK) //消息响应 {while(pos!=NULL) {m_pathname=dlg.GetNextPathName(pos); m_list.AddString(m_pathname);} //将选中的文件加入到播放列表中 } } void CLilyMPDlg::OnPlay() //播放媒体文件 { CString str; if(m_list.GetCount()<=0)MessageBox("请先打开最少一个媒体文件!","Warning",MB_OK); else {if(m_list.GetCurSel()<0){m_list.SetCurSel(0);} int index=m_list.GetCurSel(); m_list.GetText(index,str);//获取当前选中文件信息 m_ActiveMovie.Run();//播放当前选中文件 SetTimer(0,50,0); } } void CLilyMPDlg::OnCircle() { int i; for(i=0;i<50;i++) OnNext(); } void CLilyMPDlg::OnUpper()//上一曲 {CString str; int index=m_list.GetCurSel(); if (index==0)index=m_list.GetCount(); m_list.GetText(index-1,str); m_ActiveMovie.SetUrl(str); m_list.SetCurSel(index-1); } void CLilyMPDlg::OnPause() //暂停/继续 {CString strtemp; if((m_player.GetPlayState()==2)|| (m_player.GetPlayState()==3)) { GetDlgItemText(IDC_BUTTON4,strtemp);//获取按钮上的字符 if(strtemp.Compare("暂停")==0)//若显示“暂停”,点击暂停,并显示 “继续” {m_ActiveMovie.Pause(); SetDlgItemText(IDC_BUTTON4,"继续");} if(strtemp.Compare("继续")==0)//实现从暂停点继续播放,并显示 “暂停” {m_ActiveMovie.Run(); SetDlgItemText(IDC_BUTTON4,"暂停");} } else; } void CLilyMPDlg::OnNext() //下一曲 {CString str; int index=m_List.GetCurSel(); if (index==m_List.GetCount()-1)index=-1; m_List.GetText(index+1,str); m_ActiveMovie.SetUrl(str); m_list.SetCurSel(index+1); } void CLilyMPDlg::OnAddvol() //增大音量 {long Volume=m_ActiveMovie.Getvolme(); m_ActiveMovie.Pause; m_ActiveMovie.SetVolume(Volume+5); m_ActiveMovie.Run; } void CLilyMPDlg::OnDelvol() //减小音量 {long Volume=m_ActiveMovie.Getvolme(); m_ActiveMovie.Pause; m_ActiveMovie.SetVolume(Volume-5); m_ActiveMovie.Run; } void CLilyMPDlg::OnMute() //静音 { m_ActiveMovie.Pause; m_ActiveMovie.SetVolume(0); m_ActiveMovie.Run; } void CLilyMPDlg::OnSelchangeList2() { // TODO: Add your control notification handler code here } BEGIN_EVENTSINK_MAP(CLilyMPDlg, CDialog) //{{AFX_EVENTSINK_MAP(CLilyMPDlg) ON_EVENT(CLilyMPDlg, IDC_OCX6, 5001 /* OpenStateChange */, OnOpenStateChangeOcx6, VTS_I4) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CLilyMPDlg::OnOpenStateChangeOcx6(long NewState) { // TODO: Add your control notification handler code here }
用VC的MFC如何实现图中的查找替换功能?(基本对话框)越简单越好,急!
用VC的MFC如何实现图中的查找替换功能!![图片说明](https://img-ask.csdn.net/upload/201607/05/1467713926_170555.png) 最好是用Replace函数的 // newDlg.cpp : implementation file // #include "stdafx.h" #include "new.h" #include "newDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNewDlg dialog CNewDlg::CNewDlg(CWnd* pParent /*=NULL*/) : CDialog(CNewDlg::IDD, pParent) { //{{AFX_DATA_INIT(CNewDlg) m_txt = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CNewDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CNewDlg) DDX_Text(pDX, IDC_EDIT1, m_txt); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CNewDlg, CDialog) //{{AFX_MSG_MAP(CNewDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_save, Onsave) ON_BN_CLICKED(IDC_resave, Onresave) ON_BN_CLICKED(IDC_FindReplace, OnFindReplace) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNewDlg message handlers BOOL CNewDlg::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); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CNewDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CNewDlg::OnPaint() { if (IsIconic()) { 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 CNewDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CNewDlg::Onsave() { // TODO: Add your control notification handler code here TCHAR szFilter[] = _T("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"); // 构造打开文件对话框 CFileDialog fileDlg(TRUE, _T("txt"), NULL, 0, szFilter, this); CString strFilePath; // 显示打开文件对话框 if (IDOK == fileDlg.DoModal()) { // 如果点击了文件对话框上的“打开”按钮,则将选择的文件路径显示到编辑框里 strFilePath = fileDlg.GetPathName(); // SetDlgItemText(IDC_BUTTON1, strFilePath); } AfxMessageBox("保存成功!"); } void CNewDlg::Onresave() { // TODO: Add your control notification handler code here TCHAR szFilter[] = _T("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"); // 构造打开文件对话框 CFileDialog fileDlg(TRUE, _T("txt"), NULL, 0, szFilter, this); CString strFilePath; // 显示打开文件对话框 if (IDOK == fileDlg.DoModal()) { // 如果点击了文件对话框上的“打开”按钮,则将选择的文件路径显示到编辑框里 strFilePath = fileDlg.GetPathName(); // SetDlgItemText(IDC_BUTTON1, strFilePath); } } void CNewDlg::OnFindReplace() { // TODO: Add your control notification handler code here } 该怎样添加函数
内存泄漏,在什么地方释放内存,真心求教啊!!!
// ServerDlg.cpp : implementation file // #include "stdafx.h" #include "Server.h" #include "ServerDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About #define MAX_BUFF 99999 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) virtual void OnOK(); //}}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() ///////////////////////////////////////////////////////////////////////////// // CServerDlg dialog CServerDlg::CServerDlg(CWnd* pParent /*=NULL*/) : CDialog(CServerDlg::IDD, pParent) { //{{AFX_DATA_INIT(CServerDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDI_MAIN); } void CServerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CServerDlg) DDX_Control(pDX, IDC_SYSSETTING, m_SysSetting); DDX_Control(pDX, IDC_QUIT, m_Quit); DDX_Control(pDX, IDC_OPERATORMGE, m_OperatorMge); DDX_Control(pDX, IDC_BTUP, m_BtUp); DDX_Control(pDX, IDC_BTRIGHT, m_BtRight); DDX_Control(pDX, IDC_BTRESTORE, m_BtRestore); DDX_Control(pDX, IDC_BTLEFT, m_BtLeft); DDX_Control(pDX, IDC_BTDOWN, m_BtDown); DDX_Control(pDX, IDC_BACKGROUND, m_BK); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CServerDlg, CDialog) //{{AFX_MSG_MAP(CServerDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_SYSSETTING, OnSyssetting) ON_BN_CLICKED(IDC_OPERATORMGE, OnOperatormge) ON_MESSAGE(CM_RECEIVED,OnReceived) ON_BN_CLICKED(IDC_QUIT, OnQuit) //}}AFX_MSG_MAP ON_COMMAND_RANGE(IDC_BTUP,IDC_BTRESTORE,OnButtonDown) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CServerDlg message handlers BOOL CServerDlg::OnInitDialog() { CDialog::OnInitDialog(); ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); 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); } } SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE); //获取本机IP hostent* phost = gethostbyname(""); char* localIP = inet_ntoa (*(struct in_addr *)*phost->h_addr_list); sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_addr.S_un.S_addr = inet_addr(localIP); addr.sin_port = htons(5002); //创建套接字 m_Socket = socket(AF_INET,SOCK_DGRAM,0); if (m_Socket == INVALID_SOCKET) { MessageBox("套接字创建失败!"); } //绑定套接字 if (bind(m_Socket,(sockaddr*)&addr,sizeof(addr))==SOCKET_ERROR) { MessageBox("套接字绑定失败!"); } m_BmpData = new char[1024*1024*2]; memset(m_BmpData,0,1024*1024*2); m_TempData = new char[1024*1024*2]; memset(m_TempData,0,1024*1024*2); m_Header = m_BmpData; WSAAsyncSelect(m_Socket,m_hWnd,CM_RECEIVED,FD_READ); m_ShowBmp = FALSE; m_BmpSize = 0; m_RecSize = 0; m_ClientPort = 0; CServerApp* pApp = (CServerApp*)AfxGetApp(); CString sql = "select * from tb_ClientInfo"; pApp->m_DataManage.m_pRecord->CursorLocation = adUseServer; pApp->m_DataManage.m_pRecord->Open((_bstr_t)sql,pApp->m_DataManage.m_pConnect.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText); m_ClientIP= ""; if (pApp->m_DataManage.m_pRecord->RecordCount>0) { m_ClientIP = (char*)(_bstr_t)pApp->m_DataManage.m_pRecord->GetFields()->GetItem(0L)->Value; } pApp->m_DataManage.m_pRecord->Close(); m_LeftTopX= 0; m_LeftTopY= 0; m_BK.SetWindowPos(NULL,0,0,305,305,SWP_NOMOVE); return TRUE; } void CServerDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CServerDlg::OnPaint() { if (IsIconic()) { 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 CServerDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CServerDlg::OnReceived() { //接收数据 char* buffer = new char[MAX_BUFF]; sockaddr_in addr; int factsize =sizeof(sockaddr); int ret = recvfrom(m_Socket,buffer,MAX_BUFF,0,(sockaddr*)&addr,&factsize); if (ret != -1) { CString revIP = inet_ntoa(addr.sin_addr); if (revIP != m_ClientIP) { delete [] buffer; return; } m_ClientPort = ntohs(addr.sin_port); //记录接收的数据报大小 m_RecSize += ret; //读取序号 WORD orderID = *(WORD*)&buffer[0]; WORD endID = *(WORD*)&buffer[2]; //读取位图大小 int bmpsize = *(int*)&buffer[ret-12]; //获取屏幕的X轴坐标 m_LeftTopX = *(WORD*)&buffer[ret-8]; //获取屏幕的Y轴坐标 m_LeftTopY = *(WORD*)&buffer[ret-6]; //读取结束标记 sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(m_ClientPort); addr.sin_addr.S_un.S_addr = inet_addr(m_ClientIP.GetBuffer(0)); int size = sizeof(addr); //发送确认信息 char* pData = "Confirm"; sendto(m_Socket,pData,8,0,(sockaddr*)&addr,size); if (orderID==0) { m_BmpSize = bmpsize; m_BmpData = m_Header; } else m_BmpSize +=bmpsize; memcpy(m_BmpData,&buffer[4],bmpsize); m_BmpData += bmpsize; m_ShowBmp = FALSE; if (endID==1) { m_ShowBmp = TRUE; m_BmpData = m_Header; memcpy(m_TempData,m_Header,1024*1024); ShowImage() ; m_RecSize = 0; } } delete [] buffer; } void CServerDlg::OnCancel() { m_BmpData = m_Header; delete [] m_BmpData; delete []m_TempData; CDialog::OnCancel(); } void CServerDlg::ShowImage() { if (m_ShowBmp) { BITMAPINFO bInfo; memcpy(&bInfo,m_TempData,sizeof(bInfo)); int x = bInfo.bmiHeader.biWidth; int y = bInfo.bmiHeader.biHeight; StretchDIBits(m_BK.GetDC()->m_hDC,0,0,x,y,0,0,x,y,&m_TempData[sizeof(BITMAPINFO)],&bInfo,DIB_RGB_COLORS,SRCCOPY); } } void CServerDlg::OnButtonDown(UINT nID) { if (!m_ClientIP.IsEmpty()) { WORD x = m_LeftTopX; WORD y = m_LeftTopY; char buffer[4]; sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(m_ClientPort); addr.sin_addr.S_un.S_addr = inet_addr(m_ClientIP.GetBuffer(0)); int size = sizeof(addr); switch(nID) { case IDC_BTDOWN: { y = m_LeftTopY+100; *(WORD*)&buffer[0] = x; *(WORD*)&buffer[2] = y; int ret = sendto(m_Socket,&buffer[0],4,0,(sockaddr*)&addr,size); break; } case IDC_BTUP: { y = m_LeftTopY-100; *(WORD*)&buffer[0] = x; *(WORD*)&buffer[2] = y; int ret = sendto(m_Socket,&buffer[0],4,0,(sockaddr*)&addr,size); break; } case IDC_BTLEFT: { x = m_LeftTopX-100; *(WORD*)&buffer[0] = x; *(WORD*)&buffer[2] = y; int ret = sendto(m_Socket,&buffer[0],4,0,(sockaddr*)&addr,size); break; } case IDC_BTRIGHT: { x = m_LeftTopX+100; *(WORD*)&buffer[0] = x; *(WORD*)&buffer[2] = y; int ret = sendto(m_Socket,&buffer[0],4,0,(sockaddr*)&addr,size); break; } case IDC_BTRESTORE: { *(WORD*)&buffer[0] = 0; *(WORD*)&buffer[2] = 0; int ret = sendto(m_Socket,&buffer[0],4,0,(sockaddr*)&addr,size); break; } } } } void CAboutDlg::OnOK() { // CDialog::OnOK(); } void CServerDlg::OnSyssetting() { CSysSetting sysSet; sysSet.DoModal(); } void CServerDlg::OnOperatormge() { COprManage OprMge; OprMge.DoModal(); } void CServerDlg::OnQuit() { OnCancel(); }
下面的代码怎么实现双缓存去闪
// 画图View.cpp : implementation of the CMyView class // #include "stdafx.h" #include "画图.h" #include "画图Doc.h" #include "画图View.h" #include "SettingDlg.h" #include<vector> #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMyView IMPLEMENT_DYNCREATE(CMyView, CView) BEGIN_MESSAGE_MAP(CMyView, CView) //{{AFX_MSG_MAP(CMyView) ON_COMMAND(IDM_LINE, OnLine) ON_COMMAND(IDM_RECTANGLE, OnRectangle) ON_COMMAND(IDM_Circle, OnCircle) ON_COMMAND(IDM_Random_Line, OnRandomLine) ON_COMMAND(IDM_POLYGON, OnPolygon) ON_WM_LBUTTONUP() ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() ON_WM_RBUTTONDOWN() ON_WM_RBUTTONUP() ON_COMMAND(IDM_SET_LINE_STYLE_WIDTH, OnSetLineStyleWidth) ON_COMMAND(IDM_SET_COLOR, OnSetColor) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyView construction/destruction CMyView::CMyView() { // TODO: add construction code here m_nDrawType=0; m_ptOrigin=0; m_nLineStyle=0; m_nLineWidth=1; m_ncolor=RGB(255,0,0); m_dcMetaFile.Create(); no1=0; no2=0; no3=0; no4=0; no5=0; k=0; } CMyView::~CMyView() { } BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMyView drawing void CMyView::OnDraw(CDC* pDC) { CMyDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CClientDC dc(this); CPen pen(m_nLineStyle,m_nLineWidth,m_color); CPen* pOldPen = pDC->SelectObject(&pen); CPoint point1,point2; int temp=k; //vector<CPoint>::const_iterator i=v.begin(); if(no1 ||no2 ||no3 ||no4|| no5){ switch(m_nDrawType) { case 1: pDC->MoveTo(pDoc->head); point1.x=pDoc->head.x+5; point1.y=pDoc->head.y+5; point2.x=pDoc->head.x-5; point2.y=pDoc->head.y-5; pDC->Ellipse(CRect(point1,point2)); pDC->LineTo(pDoc->tail); point1.x=pDoc->tail.x+5; point1.y=pDoc->tail.y+5; point2.x=pDoc->tail.x-5; point2.y=pDoc->tail.y-5; pDC->Ellipse(CRect(point1,point2)); break; case 2: point1.x=pDoc->m_Rect.left+5; point1.y=pDoc->m_Rect.top+5; point2.x=point1.x-10; point2.y=point1.y-10; pDC->Ellipse(CRect(point1,point2)); point1.x=pDoc->m_Rect.right+5; point2.x=point1.x-10; pDC->Ellipse(CRect(point1,point2)); point1.x=pDoc->m_Rect.left+5; point1.y=pDoc->m_Rect.bottom+5; point2.x=point1.x-10; point2.y=point1.y-10; pDC->Ellipse(CRect(point1,point2)); point1.x=pDoc->m_Rect.right+5; point2.x=point1.x-10; pDC->Ellipse(CRect(point1,point2)); pDC->Rectangle(pDoc->m_Rect); break; case 3: pDC->Ellipse(pDoc->m_Rect); break; case 4: for(temp=0;temp<k-1;temp++) { pDC->MoveTo(pDoc->pointduo[temp]); point1.x=pDoc->pointduo[temp].x+5; point1.y=pDoc->pointduo[temp].y+5; point2.x=pDoc->pointduo[temp].x-5; point2.y=pDoc->pointduo[temp].y-5; pDC->Ellipse(CRect(point1,point2)); pDC->LineTo(pDoc->pointduo[temp+1]); point1.x=pDoc->pointduo[temp+1].x+5; point1.y=pDoc->pointduo[temp+1].y+5; point2.x=pDoc->pointduo[temp+1].x-5; point2.y=pDoc->pointduo[temp+1].y-5; pDC->Ellipse(CRect(point1,point2)); } pDC->MoveTo(pDoc->pointduo[temp]); point1.x=pDoc->pointduo[temp].x+5; point1.y=pDoc->pointduo[temp].y+5; point2.x=pDoc->pointduo[temp].x-5; point2.y=pDoc->pointduo[temp].y-5; pDC->Ellipse(CRect(point1,point2)); pDC->LineTo(pDoc->tail); point1.x=pDoc->tail.x+5; point1.y=pDoc->tail.y+5; point2.x=pDoc->tail.x-5; point2.y=pDoc->tail.y-5; pDC->Ellipse(CRect(point1,point2)); break; case 5: for(temp=0;temp<k-1;temp++) { pDC->MoveTo(pDoc->pointp[temp]); point1.x=pDoc->pointp[temp].x+5; point1.y=pDoc->pointp[temp].y+5; point2.x=pDoc->pointp[temp].x-5; point2.y=pDoc->pointp[temp].y-5; pDC->Ellipse(CRect(point1,point2)); pDC->LineTo(pDoc->pointp[temp+1]); point1.x=pDoc->pointp[temp+1].x+5; point1.y=pDoc->pointp[temp+1].y+5; point2.x=pDoc->pointp[temp+1].x-5; point2.y=pDoc->pointp[temp+1].y-5; pDC->Ellipse(CRect(point1,point2)); } pDC->MoveTo(pDoc->pointp[temp]); point1.x=pDoc->pointp[temp].x+5; point1.y=pDoc->pointp[temp].y+5; point2.x=pDoc->pointp[temp].x-5; point2.y=pDoc->pointp[temp].y-5; pDC->Ellipse(CRect(point1,point2)); pDC->LineTo(pDoc->tail); point1.x=pDoc->tail.x+5; point1.y=pDoc->tail.y+5; point2.x=pDoc->tail.x-5; point2.y=pDoc->tail.y-5; pDC->Ellipse(CRect(point1,point2)); pDC->MoveTo(pDoc->tail); point1.x=pDoc->tail.x+5; point1.y=pDoc->tail.y+5; point2.x=pDoc->tail.x-5; point2.y=pDoc->tail.y-5; pDC->Ellipse(CRect(point1,point2)); pDC->LineTo(pDoc->pointp[0]); point1.x=pDoc->pointp[0].x+5; point1.y=pDoc->pointp[0].y+5; point2.x=pDoc->pointp[0].x-5; point2.y=pDoc->pointp[0].y-5; pDC->Ellipse(CRect(point1,point2)); } } } ///////////////////////////////////////////////////////////////////////////// // CMyView printing BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMyView diagnostics #ifdef _DEBUG void CMyView::AssertValid() const { CView::AssertValid(); } void CMyView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMyDoc* CMyView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc))); return (CMyDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMyView message handlers //DEL void CMyView::OnUpdateLine(CCmdUI* pCmdUI) //DEL { //DEL // TODO: Add your command update UI handler code here //DEL //DEL } void CMyView::OnLine() { // TODO: Add your command handler code here m_nDrawType=1; } void CMyView::OnRectangle() { // TODO: Add your command handler code here m_nDrawType=2; } void CMyView::OnCircle() { // TODO: Add your command handler code here m_nDrawType=3; } void CMyView::OnRandomLine() { // TODO: Add your command handler code here m_nDrawType=4; } void CMyView::OnPolygon() { // TODO: Add your command handler code here m_nDrawType=5; } void CMyView::OnLButtonUp(UINT nFlags, CPoint point) { CView::OnLButtonUp(nFlags, point); } void CMyView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); CPoint point1,point2; m_ptOrigin=point; CMyDoc* pDoc = GetDocument(); if(m_nDrawType==4) { pDoc->pointduo[k]=point; k++; } if(m_nDrawType==5) { pDoc->pointp[k]=point; k++; } if(no1||no2||no3) { switch(m_nDrawType) { case 1:if(no1==1)no1=0;break; case 2:if(no2==1)no2=0;break; case 3:if(no3==1)no3=0;break; } } else if(m_nDrawType!=0) { if(m_nDrawType!=3) { CPen pen(0,1,m_color); CPen* pOldPen = dc.SelectObject(&pen); point1.x=point.x+5; point1.y=point.y+5; point2.x=point.x-5; point2.y=point.y-5; dc.Ellipse(CRect(point1,point2)); } switch(m_nDrawType) { case 1:no1=1; break; case 2:no2=1; break; case 3:no3=1; break; case 4:no4=1; break; case 5:no5=1; break; } } CView::OnLButtonDown(nFlags, point); } void CMyView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CPoint m_ptEnd=point; CPoint point1,point2,point3,point4; CMyDoc* pDoc = GetDocument(); CClientDC dc(this); switch(m_nDrawType) { case 1: pDoc->head=m_ptOrigin; pDoc->tail=m_ptEnd; if(no1) Invalidate(); break; case 2:case 3: pDoc->m_Rect.left=m_ptOrigin.x; pDoc->m_Rect.top=m_ptOrigin.y; pDoc->m_Rect.right=m_ptEnd.x; pDoc->m_Rect.bottom=m_ptEnd.y; if(no2 || no3) Invalidate(); case 4:case 5: pDoc->tail=m_ptEnd; if(no5 || no4) Invalidate(); break; } CView::OnMouseMove(nFlags, point); } void CMyView::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CView::OnRButtonDown(nFlags, point); } void CMyView::OnRButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if(m_nDrawType==4) { no4=0; k=0; } if(m_nDrawType==5) { no5=0; k=0; } CView::OnRButtonUp(nFlags, point); } void CMyView::OnSetLineStyleWidth() { // TODO: Add your command handler code here CSettingDlg dlg; //dlg.DoModal(); dlg.m_nLineWidth=m_nLineWidth; dlg.m_nLineStyle=m_nLineStyle; if(IDOK==dlg.DoModal()) { m_nLineWidth=dlg.m_nLineWidth ; m_nLineStyle=dlg.m_nLineStyle ; } } void CMyView::OnSetColor() { // TODO: Add your command handler code here CColorDialog dlg; dlg.m_cc.Flags |=CC_RGBINIT | CC_FULLOPEN; dlg.m_cc.rgbResult=m_color; if(IDOK==dlg.DoModal()) { m_color=dlg.m_cc.rgbResult; } }
帮我解释一下错误,发现了,改不了!
BOOL CCalc_mfcDlg::OnInitDialog() { CDialog::OnInitDialog(); m_strNext =_T(' '); m_strCur =_T(' '); m_strPre =_T(' '); m_dNext=0; m_dCur=0; m_dPre=0; m_nDotSign=0; m_nDotNo=0; // 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); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CCalc_mfcDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CCalc_mfcDlg::OnPaint() { if (IsIconic()) { 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 CCalc_mfcDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCalc_mfcDlg::OnButton10() { // TODO: Add your control notification handler code here SetNum(0) } void CCalc_mfcDlg::OnButton2() { // TODO: Add your control notification handler code here SetNum(2) } void CCalc_mfcDlg::OnButton1() { // TODO: Add your control notification handler code here SetNum(1) } void CCalc_mfcDlg::OnButton3() { // TODO: Add your control notification handler code here SetNum(3) } void CCalc_mfcDlg::OnButton4() { // TODO: Add your control notification handler code here SetNum(4) } void CCalc_mfcDlg::OnButton5() { // TODO: Add your control notification handler code here SetNum(5) } void CCalc_mfcDlg::OnButton20() { // TODO: Add your control notification handler code here m_strNext=_T(""); CString m_strCur=_T(""); CString m_strPre=_T(""); double m_dNext=0; double m_dCur=0; double m_dPre=0; int m_nDotSign=0; int m_nDotNo=0; } void CCalc_mfcDlg::OnButton6() { // TODO: Add your control notification handler code here SetNum(6) } void CCalc_mfcDlg::OnButton7() { // TODO: Add your control notification handler code here SetNum(7) } void CCalc_mfcDlg::OnButton8() { // TODO: Add your control notification handler code here SetNum(8) } void CCalc_mfcDlg::OnButton9() { // TODO: Add your control notification handler code here SetNum(9) } void CCalc_mfcDlg::OnButton19() { // TODO: Add your control notification handler code here m-nDotSign==1; m-nDotNo=1; } void CCalc_mfcDlg::OnButton11() { // TODO: Add your control notification handler code here if(m_dPre==0) { m_dPre=m_dCur; m_strPre="+"; m_strCur=m_strPre; } else {process(); m_strPre="+"; m_strCur=m_strPre; } m_dNum=m_dPre; m_dCur=0; m_nDotSign=0; m_nDotNO=0; UpdataData(false); } void CCalc_mfcDlg::OnButton12() { // TODO: Add your control notification handler code here if(m_dPre==0) { m_dPre=m_dCur; m_strPre="-"; m_strCur=m_strPre; } else {process(); m_strPre="-"; m_strCur=m_strPre; } m_dNum=m_dPre; m_dCur=0; m_nDotSign=0; m_nDotNO=0; UpdataData(false); } void CCalc_mfcDlg::OnButton13() { // TODO: Add your control notification handler code here if(m_dPre==0) { m_dPre=m_dCur; m_strPre="*"; m_strCur=m_strPre; } else {process(); m_strPre="*"; m_strCur=m_strPre; } m_dNum=m_dPre; m_dCur=0; m_nDotSign=0; m_nDotNO=0; UpdataData(false); } void CCalc_mfcDlg::OnButton14() { // TODO: Add your control notification handler code here if(m_dPre==0) { m_dPre=m_dCur; m_strPre="/"; m_strCur=m_strPre; } else {process(); m_strPre="/"; m_strCur=m_strPre; } m_dNum=m_dPre; m_dCur=0; m_nDotSign=0; m_nDotNO=0; UpdataData(false); } void CCalc_mfcDlg::OnButton15() { // TODO: Add your control notification handler code here exp function } void CCalc_mfcDlg::OnButton16() { // TODO: Add your control notification handler code here mod function } void CCalc_mfcDlg::OnButton17() { // TODO: Add your control notification handler code here log function } void CCalc_mfcDlg::OnButton18() { // TODO: Add your control notification handler code here 10 function } void CCalcDlg::process() {if(m_strPre=="+")m_dPre+=m_dCur; if(m_strPre=="-")m_dPre-=m_dCur; if(m_strPre=="*")m_dPre*=m_dCur; if(m_strPre=="/") {if(m_dCur==0)m_dCur=1; m_strPre/=m_dCur; } }
请高手帮忙回答,在龚建伟老师的串口调试中遇到了Serial串口类的问题
![图片说明](https://img-ask.csdn.net/upload/201504/20/1429520800_230930.jpg) 点击打开串口按钮时,就会弹出以上图片的错误,![图片说明](https://img-ask.csdn.net/upload/201504/20/1429521315_903749.jpg) 代码如下 // SerialPortTestDlg.h : header file // #include"SerialPort.h" #if !defined(AFX_SERIALPORTTESTDLG_H__37F6643D_1905_4655_883E_24AD7F141ED0__INCLUDED_) #define AFX_SERIALPORTTESTDLG_H__37F6643D_1905_4655_883E_24AD7F141ED0__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ///////////////////////////////////////////////////////////////////////////// // CSerialPortTestDlg dialog class CSerialPortTestDlg : public CDialog { // Construction public: CSerialPortTestDlg(CWnd* pParent = NULL); // standard constructor CSerialPort m_SerialPort; //CSerailPort类对象 BOOL m_bSerialPortOpened; //标志串口是否打开 // Dialog Data //{{AFX_DATA(CSerialPortTestDlg) enum { IDD = IDD_SERIALPORTTEST_DIALOG }; CComboBox m_ctrlComboComPort; CString m_strEditReceiveMsg; CString m_strEditSendMsg; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSerialPortTestDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CSerialPortTestDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg LONG OnComm(WPARAM ch, LPARAM port); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnButtonOpen(); afx_msg void OnButtonClose(); afx_msg void OnButtonSend(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SERIALPORTTESTDLG_H__37F6643D_1905_4655_883E_24AD7F141ED0__INCLUDED_) // SerialPortTestDlg.cpp : implementation file // #include "stdafx.h" #include "SerialPortTest.h" #include "SerialPortTestDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSerialPortTestDlg dialog CSerialPortTestDlg::CSerialPortTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CSerialPortTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSerialPortTestDlg) m_strEditReceiveMsg = _T(""); m_strEditSendMsg = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_bSerialPortOpened=FALSE; //初始状态:串口没有打开 } void CSerialPortTestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSerialPortTestDlg) DDX_Control(pDX, IDC_COMBO_COMPORT, m_ctrlComboComPort); DDX_Text(pDX, IDC_EDIT_RECEIVEMSG, m_strEditReceiveMsg); DDX_Text(pDX, IDC_EDIT_SENDMSG, m_strEditSendMsg); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSerialPortTestDlg, CDialog) //{{AFX_MSG_MAP(CSerialPortTestDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen) ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose) ON_MESSAGE(WM_COMM_RXCHAR, OnComm) ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSerialPortTestDlg message handlers BOOL CSerialPortTestDlg::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); 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 // TODO: Add extra initialization here m_ctrlComboComPort.SetCurSel(0); //初始选择串口1 //以下两句分别设置“打开串口”、“关闭串口”两个按状态的使能状态 GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(!m_bSerialPortOpened); GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(m_bSerialPortOpened); return TRUE; // return TRUE unless you set the focus to a control } void CSerialPortTestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CSerialPortTestDlg::OnPaint() { if (IsIconic()) { 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 CSerialPortTestDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } LONG CSerialPortTestDlg::OnComm(WPARAM ch, LPARAM port) { m_strEditReceiveMsg += ch; UpdateData(FALSE); //将接收到的字符显示在接收编辑框中 return 0; } void CSerialPortTestDlg::OnButtonOpen() { // TODO: Add your control notification handler code here int nPort=m_ctrlComboComPort.GetCurSel()+1; //得到串口号,想想为什么要加1 if(m_SerialPort.InitPort(this, nPort, 9600,'N',8,1,EV_RXFLAG | EV_RXCHAR,512)) { m_SerialPort.StartMonitoring(); m_bSerialPortOpened=TRUE; } else { AfxMessageBox("没有发现此串口或被占用"); m_bSerialPortOpened=FALSE; } GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(!m_bSerialPortOpened); GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(m_bSerialPortOpened); } void CSerialPortTestDlg::OnButtonClose() { // TODO: Add your control notification handler code here m_SerialPort.ClosePort();//关闭串口 m_bSerialPortOpened=FALSE; GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(!m_bSerialPortOpened); GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(m_bSerialPortOpened); } void CSerialPortTestDlg::OnButtonSend() { // TODO: Add your control notification handler code here if(!m_bSerialPortOpened) return; //检查串口是否打开 UpdateData(TRUE); //读入编辑框中的数据 m_SerialPort.WriteToPort((LPCTSTR)m_strEditSendMsg);//发送数据 }
两个窗口穿参数,指针数据丢失
在头文件里面声明了一个 struct Param { BITMAPINFO *pinfo; BYTE *pbit; DWORD h; DWORD w; };结构体 程序绝大部分如下 #include "stdafx.h" #include <windows.h> #include <windowsx.h> #include "resource.h" #include "MainDlg.h" #include "SHOWDLG.h" #include <stdio.h> #include <commdlg.h> BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand); HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); } return FALSE; } BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { HWND chuli=GetDlgItem(hwnd,IDC_chuli); ComboBox_InsertString(chuli,-1,TEXT("傅里叶变换")); ComboBox_InsertString(chuli,-1,TEXT("什么二值化")); ComboBox_InsertString(chuli,-1,TEXT("获取边缘梯度图像")); ComboBox_InsertString(chuli,-1,TEXT("还有什么阈值")); return TRUE; } void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { HWND chuli=GetDlgItem(hwnd,IDC_chuli); int n; OPENFILENAME ofn; char szFile[MAX_PATH]; DWORD m_nHeight, m_nWidth; HWND h_static=GetDlgItem(hwnd,IDC_s); HDC hdc_static=GetDC(h_static); Param params; switch(id) { case IDC_OK://为什么不能开同一张图片两次? { ZeroMemory(&ofn,sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFilter = TEXT("ALL\0*.*\0Text\0*.TXT\0BMP\0*.bmp\0JPG\0*.jpg"); ofn.lpstrFile = szFile; ofn.lpstrFile[0] = TEXT('\0');//艹,不加这一句还打不开,不明所以 ofn.nFilterIndex = 3; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.hwndOwner = hwnd; ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) { if(3==ofn.nFilterIndex) { MessageBox(hwnd,ofn.lpstrFile,TEXT("问好"),MB_OK); HANDLE Hbmp=CreateFile(ofn.lpstrFile,GENERIC_READ |GENERIC_WRITE, 0, NULL,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE m_Hbmp=CreateFileMapping(Hbmp,NULL,PAGE_READWRITE,0,0x1400000,TEXT("maptest")); if( INVALID_HANDLE_VALUE==m_Hbmp) { MessageBox(hwnd,TEXT("映像创建失败"),TEXT("error"),MB_OK); return; } LPVOID lpBase = MapViewOfFile(m_Hbmp, FILE_MAP_ALL_ACCESS, 0, 0, 0); //params = lpBase; BITMAPFILEHEADER *pFileHeader; BITMAPINFO *pInfoHeader; pFileHeader = (BITMAPFILEHEADER*)lpBase; BYTE *pBits = (BYTE*)lpBase + pFileHeader->bfOffBits; pInfoHeader = (BITMAPINFO*)((BYTE*)lpBase + sizeof(BITMAPFILEHEADER)); m_nHeight = pInfoHeader->bmiHeader.biHeight; m_nWidth = pInfoHeader->bmiHeader.biWidth; HBITMAP hBitmap = CreateCompatibleBitmap(hdc_static, m_nWidth, m_nHeight); SelectObject(hdc_static, hBitmap); params.w = m_nWidth; params.h = m_nHeight; params.pinfo = pInfoHeader;//结构体指针的赋值有问题 params.pbit = pBits; int nRet = SetDIBitsToDevice(hdc_static,0,0,m_nWidth,m_nHeight,0,0,0,m_nHeight,pBits,pInfoHeader,DIB_RGB_COLORS); InvalidateRect((HWND)Hbmp, NULL, TRUE); DeleteObject(hBitmap); ReleaseDC(hwnd,hdc_static); //UnmapViewOfFile(lpBase); CloseHandle(m_Hbmp); } } } break; case IDC_DOIT: { n=ComboBox_GetCurSel(chuli); HINSTANCE hinstance=(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE); while(n<0) { MessageBox(hwnd,TEXT("请选择处理方式"),TEXT("提示"),MB_OKCANCEL); break; } if(n<0) { break; } switch(n) { //LPARAM *par; //par=(long*)&params; case 0: { DialogBoxParam(hinstance,MAKEINTRESOURCE(IDD_SHOWDLG),NULL,SHOWDLG_Proc,(long)&params); MessageBox(NULL,TEXT("傅里叶变换"),TEXT("你选择了"),MB_OK); } break; case 1: { MessageBox(NULL,TEXT("什么二值化"),TEXT("你选择了"),MB_OK); DialogBoxParam(hinstance,MAKEINTRESOURCE(IDD_SHOWDLG),NULL,SHOWDLG_Proc,300); } break; case 2: { MessageBox(NULL,TEXT("获取边缘梯度图像"),TEXT("你选择了"),MB_OK); DialogBoxParam(hinstance,MAKEINTRESOURCE(IDD_SHOWDLG),NULL,SHOWDLG_Proc,300); } break; case 3: { MessageBox(NULL,TEXT("还有什么阈值"),TEXT("你选择了"),MB_OK); DialogBoxParam(hinstance,MAKEINTRESOURCE(IDD_SHOWDLG),NULL,SHOWDLG_Proc,300); } break; default: break; } } break; default: break; } } void Main_OnClose(HWND hwnd) { EndDialog(hwnd, 0); } 然后在另一个窗口函数里面 BOOL SHOWDLG_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { Param * pa = (Param*)lParam ;//DC没有问题,传进来的指针指的地方不对 SetDIBitsToDevice(h_sdc,0,0,pa->w,pa->h,0,0,0,pa->h,pa->pbit,pa->pinfo,DIB_RGB_COLORS); return TRUE; } 调试发现在红色标记语句执行后params里面的数据丢失(之前调试看的数据都正常),这句UnmapViewOfFile(lpBase);不释放就好了,但是传递给另一个窗口的时候结构体里面的数据就全没了,定义全局变量也没用,现在想做的就是在两个窗口里面都显示同一个图片,以后再做图像处理,小弟都是自学的,MFC不太熟悉,想请各位大神指教一下,感激不尽!
is not a class or namespace name
初学MFC,使用VC++6.0,出现'CopyFoldersDlg' : is not a class or namespace name报错。但头文件都没什么问题呀。 ``` // CopyFoldersDlg.cpp : implementation file // #include "stdafx.h" #include "CopyFolders.h" #include "CopyFoldersDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCopyFoldersDlg dialog CCopyFoldersDlg::CCopyFoldersDlg(CWnd* pParent /*=NULL*/) : CDialog(CCopyFoldersDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCopyFoldersDlg) m_SrcPath = _T(""); m_DesPath = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCopyFoldersDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCopyFoldersDlg) DDX_Control(pDX, IDC_STOP, m_StopBn); DDX_Control(pDX, IDC_START, m_StartBn); DDX_Control(pDX, IDC_PROGRESS, m_ProgressCtrl); DDX_Text(pDX, IDC_EDIT1, m_SrcPath); DDX_Text(pDX, IDC_EDIT2, m_DesPath); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCopyFoldersDlg, CDialog) //{{AFX_MSG_MAP(CCopyFoldersDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_START, OnStart) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCopyFoldersDlg message handlers BOOL CCopyFoldersDlg::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); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CCopyFoldersDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CCopyFoldersDlg::OnPaint() { if (IsIconic()) { 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 CCopyFoldersDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCopyFoldersDlg::OnStart() { UpdateData(TRUE); CFileFind find; if ((m_SrcPath.IsEmpty() && m_DesPath.IsEmpty())) { MessageBox("路径不能为空!"); return; } else { //设置停止按钮enable m_StopBn.EnableWindow(TRUE); m_StartBn.EnableWindow(FALSE); //开始线程 //hThread = CreateThread(NULL, 0, ThreadCopy, this, 0, NULL); //hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); //AfxBeginThread(hThread, this); //ExitThread } } DWORD WINAPI CopyFoldersDlg::ThreadCopy(LPVOID pParam) { return 0; } ``` ``` // CopyFoldersDlg.h : header file // #if !defined(AFX_COPYFOLDERSDLG_H__7920B5E0_63E8_415A_9E3A_8DEC5C7A8FA6__INCLUDED_) #define AFX_COPYFOLDERSDLG_H__7920B5E0_63E8_415A_9E3A_8DEC5C7A8FA6__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ///////////////////////////////////////////////////////////////////////////// // CCopyFoldersDlg dialog class CCopyFoldersDlg : public CDialog { // Construction public: CCopyFoldersDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CCopyFoldersDlg) enum { IDD = IDD_COPYFOLDERS_DIALOG }; CButton m_StopBn; CButton m_StartBn; CProgressCtrl m_ProgressCtrl; CString m_SrcPath; CString m_DesPath; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CCopyFoldersDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; public: HANDLE hThread; static DWORD WINAPI ThreadCopy(LPVOID pParam); // Generated message map functions //{{AFX_MSG(CCopyFoldersDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg void OnStart(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_COPYFOLDERSDLG_H__7920B5E0_63E8_415A_9E3A_8DEC5C7A8FA6__INCLUDED_) ``` 谢谢各位!
关于c++ 数据库的问题
求大神帮忙看一下程序 初学数据库,东拼西凑了这么个程序,用的是vs2010 按条件查找,现在正在编按名称查找,结果总是运行过程中有错退出, 调试时发现是在m_pRecordset->Open处出错, 是这个open的参数写的有错吗? 麻烦大神帮忙改一下,感激不尽!!!! ``` // DemoDlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "Demo.h" #include "DemoDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDemoDlg dialog CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/) : CDialog(CDemoDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDemoDlg) /* */ //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); if (!SUCCEEDED(m_pConnection.CreateInstance(__uuidof(Connection)))) { m_pConnection = NULL; TRACE(_T("Database CreateInstance failed")); } if (!SUCCEEDED(m_pRecordset.CreateInstance(__uuidof(Recordset)))) { m_pRecordset = NULL; TRACE(_T("Recordset CreateInstance Failed!")); } //打开数据库 CString strConnect = _T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= DataBase.mdb"); // if (!OpenDatabase(strConnect)) { AfxMessageBox(_T("数据库打开失败。")); return; } //打开记录集 if (!OpenRecordset(_T("SELECT * FROM file_info"))) // { AfxMessageBox(_T("记录集打开失败。")); return; } } CDemoDlg::~CDemoDlg() { m_pRecordset->Close(); m_pConnection->Close(); } void CDemoDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDemoDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDemoDlg, CDialog) //{{AFX_MSG_MAP(CDemoDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_FIND, OnFind) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDemoDlg message handlers BOOL CDemoDlg::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); 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 //初始化ListCtrl ///// CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST); pListCtrl->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); pListCtrl->InsertColumn(1, _T("序号"), LVCFMT_CENTER, 60); pListCtrl->InsertColumn(2, _T("文件名"), LVCFMT_CENTER, 60); pListCtrl->InsertColumn(3, _T("类型"), LVCFMT_CENTER, 40); pListCtrl->InsertColumn(4, _T("时间"), LVCFMT_CENTER, 80); pListCtrl->InsertColumn(5, _T("保存路径"), LVCFMT_CENTER, 200); return TRUE; } void CDemoDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CDemoDlg::OnPaint() { if (IsIconic()) { 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 CDemoDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } BOOL CDemoDlg::OpenDatabase(LPCTSTR lpszConnect, long nOptions) { ASSERT(m_pConnection != NULL); ASSERT(lpszConnect != NULL); ASSERT(AfxIsValidString(lpszConnect)); //打开数据库连接 try { return SUCCEEDED(m_pConnection->Open(_bstr_t(lpszConnect), _T(""), _T(""), nOptions)); //////////////// } catch (_com_error& e) { TRACE(_T("%s\n"), e.ErrorMessage()); return FALSE; } } BOOL CDemoDlg::CloseDatabase() { ASSERT(m_pConnection != NULL); //关闭数据库连接 try { if (m_pConnection->State & adStateOpen) { return SUCCEEDED(m_pConnection->Close()); } else { return TRUE; } } catch (_com_error& e) { TRACE(_T("%s\n"), e.ErrorMessage()); return FALSE; } } BOOL CDemoDlg::OpenRecordset(LPCTSTR lpszSource, long nCursorType, long nLockType, long nOptions) { ASSERT(m_pConnection != NULL); ASSERT(m_pRecordset != NULL); ASSERT(lpszSource != NULL); ASSERT(AfxIsValidString(lpszSource)); //打开记录集 try { return (SUCCEEDED(m_pRecordset->Open(_variant_t(lpszSource), m_pConnection.GetInterfacePtr(), (CursorTypeEnum)nCursorType, (LockTypeEnum)nLockType, nOptions))); } catch(_com_error e) { TRACE(_T("%s\n"), e.ErrorMessage()); return FALSE; } } BOOL CDemoDlg::CloseRecorset() { ASSERT(m_pRecordset != NULL); //关闭记录集 try { if (m_pRecordset->State & adStateOpen) { return SUCCEEDED(m_pRecordset->Close()); } else { return TRUE; } } catch (_com_error e) { TRACE(_T("%s\n"), e.ErrorMessage()); return FALSE; } } void CDemoDlg::OnFind() { if (!(m_pRecordset->State & adStateOpen)) { AfxMessageBox((_T("记录集未打开。"))); return; } //查找条件 CString strCriteria = _T(""); CString strName = _T(""); CString strtype = _T(""); CString strtime = _T(""); GetDlgItemText(IDC_NAME, strName); GetDlgItemText(IDC_TYPE, strtype); GetDlgItemText(IDC_TIME, strtime); if(strName != _T("")) strCriteria.Format(_T("NAME like '*%s*'"),strName); else return; //查找记录集 CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(IDC_LIST); pListCtrl->DeleteAllItems(); if (m_pRecordset->BOF && m_pRecordset->adoEOF) { return; } m_pRecordset->MoveFirst(); /////////// m_pRecordset->Open(_bstr_t(strCriteria),m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockBatchOptimistic,adCmdText); ////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int n = 0; while (!m_pRecordset->adoEOF) { _variant_t varValue; CString strName = _T(""); CString strtime = _T(""); CString strtype = _T(""); CString strpath = _T(""); varValue = m_pRecordset->GetCollect(_variant_t(_T("NAME"))); if (varValue.vt != VT_NULL) { strName = varValue.bstrVal; } else { strName = _T(""); } varValue = m_pRecordset->GetCollect(_variant_t(_T("TYPE"))); if (varValue.vt != VT_NULL) { strtype = varValue.bstrVal; } else { strtype = _T(""); } varValue = m_pRecordset->GetCollect(_variant_t(_T("TIME"))); if (varValue.vt != VT_NULL) { strtime = varValue.bstrVal; } else { strtime = _T(""); } varValue = m_pRecordset->GetCollect(_variant_t(_T("PATH"))); if (varValue.vt != VT_NULL) { strpath = varValue.bstrVal; } else { strpath = _T(""); } //刷新ListCtrl CString strText = _T(""); strText.Format(_T("%d"), n + 1); pListCtrl->InsertItem(n, strText); strText.Format(_T("%s"), strName); pListCtrl->SetItemText(n, 1, strText); strText.Format(_T("%s"), strtype); pListCtrl->SetItemText(n, 2, strText); strText.Format(_T("%s"),strtime); pListCtrl->SetItemText(n, 3, strText); strText.Format(_T("%s"), strpath); pListCtrl->SetItemText(n, 4, strText); n++; //////////////////////////// m_pRecordset->MoveNext(); //////////////////////////// } if(n==0) { pListCtrl->InsertItem(n,"NULL!"); } } ```
我的模态对话框不能显示
我按照《VisualC++从入门到精通》一书的第六章6。2。2的显示对话框的视频所讲进行操作,可是我的模态对话框却怎么也不能显示,这是什么原因呢?代码如下: // kljDlg.cpp : implementation file // #include "stdafx.h" #include "klj.h" #include "kljDlg.h" #include"NEWDLg,h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About 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) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CKljDlg dialog CKljDlg::CKljDlg(CWnd* pParent /*=NULL*/) : CDialog(CKljDlg::IDD, pParent) { //{{AFX_DATA_INIT(CKljDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CKljDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CKljDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CKljDlg, CDialog) //{{AFX_MSG_MAP(CKljDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CKljDlg message handlers BOOL CKljDlg::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); 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 // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CKljDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } 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. void CKljDlg::OnPaint() { if (IsIconic()) { 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 CKljDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CKljDlg::OnButton1() { // TODO: Add your control notification handler code here CSHowDLg dlg; dlg.DoModal() } 所显示的错误信息如下: --------------------Configuration: jhDlg - Win32 Debug-------------------- Compiling... jhDlg.cpp D:\安装软件\VC6。0\VC6\新建文件夹\jh\jhDlg.cpp(176) : error C2065: 'CShowDLg' : undeclared identifier D:\安装软件\VC6。0\VC6\新建文件夹\jh\jhDlg.cpp(176) : error C2146: syntax error : missing ';' before identifier 'dlg' D:\安装软件\VC6。0\VC6\新建文件夹\jh\jhDlg.cpp(176) : error C2065: 'dlg' : undeclared identifier D:\安装软件\VC6。0\VC6\新建文件夹\jh\jhDlg.cpp(177) : error C2228: left of '.DoModal' must have class/struct/union type 执行 cl.exe 时出错. jhDlg.exe - 1 error(s), 0 warning(s)
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私有的数
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
此博客仅为我业余记录文章所用,发布到此,仅供网友阅读参考,如有侵权,请通知我,我会删掉。 补充 有不少读者留言说本文章没有用,因为天气预报直接打开手机就可以收到了,为何要多此一举发送到邮箱呢!!!那我在这里只能说:因为你没用,所以你没用!!! 这里主要介绍的是思路,不是天气预报!不是天气预报!!不是天气预报!!!天气预报只是用于举例。请各位不要再刚了!!! 下面是我会用到的两个场景: 每日下
面试官问我:什么是消息队列?什么场景需要他?用了会出现什么问题?
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图、个人联系方式,欢迎Star和完善 前言 消息队列在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在消息队列的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸,打败了无数
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
究竟你适不适合买Mac?
我清晰的记得,刚买的macbook pro回到家,开机后第一件事情,就是上了淘宝网,花了500元钱,找了一个上门维修电脑的师傅,上门给我装了一个windows系统。。。。。。 表砍我。。。 当时买mac的初衷,只是想要个固态硬盘的笔记本,用来运行一些复杂的扑克软件。而看了当时所有的SSD笔记本后,最终决定,还是买个好(xiong)看(da)的。 已经有好几个朋友问我mba怎么样了,所以今天尽量客观
程序员一般通过什么途径接私活?
二哥,你好,我想知道一般程序猿都如何接私活,我也想接,能告诉我一些方法吗? 上面是一个读者“烦不烦”问我的一个问题。其实不止是“烦不烦”,还有很多读者问过我类似这样的问题。 我接的私活不算多,挣到的钱也没有多少,加起来不到 20W。说实话,这个数目说出来我是有点心虚的,毕竟太少了,大家轻喷。但我想,恰好配得上“一般程序员”这个称号啊。毕竟苍蝇再小也是肉,我也算是有经验的人了。 唾弃接私活、做外
大学四年自学走来,这些珍藏的「实用工具/学习网站」我全贡献出来了
知乎高赞:文中列举了互联网一线大厂程序员都在用的工具集合,涉及面非常广,小白和老手都可以进来看看,或许有新收获。
《阿里巴巴开发手册》读书笔记-编程规约
Java编程规约命名风格 命名风格 类名使用UpperCamelCase风格 方法名,参数名,成员变量,局部变量都统一使用lowerCamelcase风格 常量命名全部大写,单词间用下划线隔开, 力求语义表达完整清楚,不要嫌名字长 ...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple/ 
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
你知道的越多,你不知道的越多 点赞再看,养成习惯 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试点思维导图,也整理了很多我的文档,欢迎Star和完善,大家面试可以参照考点复习,希望我们一起有点东西。 前前言 为啥今天有个前前言呢? 因为你们的丙丙啊,昨天有牌面了哟,直接被微信官方推荐,知乎推荐,也就仅仅是还行吧(心里乐开花)
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca
Python爬虫精简步骤1 获取数据
爬虫的工作分为四步: 1.获取数据。爬虫程序会根据我们提供的网址,向服务器发起请求,然后返回数据。 2.解析数据。爬虫程序会把服务器返回的数据解析成我们能读懂的格式。 3.提取数据。爬虫程序再从中提取出我们需要的数据。 4.储存数据。爬虫程序把这些有用的数据保存起来,便于你日后的使用和分析。 这一篇的内容就是:获取数据。 首先,我们将会利用一个强大的库——requests来获取数据。 在电脑上安装
Python绘图,圣诞树,花,爱心 | Turtle篇
1.画圣诞树 import turtle screen = turtle.Screen() screen.setup(800,600) circle = turtle.Turtle() circle.shape('circle') circle.color('red') circle.speed('fastest') circle.up() square = turtle.Turtle()
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东
破14亿,Python分析我国存在哪些人口危机!
2020年1月17日,国家统计局发布了2019年国民经济报告,报告中指出我国人口突破14亿。 猪哥的朋友圈被14亿人口刷屏,但是很多人并没有看到我国复杂的人口问题:老龄化、男女比例失衡、生育率下降、人口红利下降等。 今天我们就来分析一下我们国家的人口数据吧! 更多有趣分析教程,扫描下方二维码关注vx公号「裸睡的猪」 即可查看! 一、背景 1.人口突破14亿 2020年1月17日,国家统计局发布
听说想当黑客的都玩过这个Monyer游戏(1~14攻略)
第零关 进入传送门开始第0关(游戏链接) 请点击链接进入第1关: 连接在左边→ ←连接在右边 看不到啊。。。。(只能看到一堆大佬做完的留名,也能看到菜鸡的我,在后面~~) 直接fn+f12吧 &lt;span&gt;连接在左边→&lt;/span&gt; &lt;a href="first.php"&gt;&lt;/a&gt; &lt;span&gt;←连接在右边&lt;/span&gt; o
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ......
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!
别低估自己的直觉,也别高估自己的智商
所有群全部吵翻天,朋友圈全部沦陷,公众号疯狂转发。这两周没怎么发原创,只发新闻,可能有人注意到了。我不是懒,是文章写了却没发,因为大家的关注力始终在这次的疫情上面,发了也没人看。当然,我...
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。   再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。   下文是原回答,希望能对你能有所启发。   如果我说,这个世界上人真的分三六九等,
为什么听过很多道理,依然过不好这一生?
记录学习笔记是一个重要的习惯,不希望学习过的东西成为过眼云烟。做总结的同时也是一次复盘思考的过程。 本文是根据阅读得到 App上《万维钢·精英日课》部分文章后所做的一点笔记和思考。学习是一个系统的过程,思维模型的建立需要相对完整的学习和思考过程。以下观点是在碎片化阅读后总结的一点心得总结。
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合
如何优雅地打印一个Java对象?
你好呀,我是沉默王二,一个和黄家驹一样身高,和刘德华一样颜值的程序员。虽然已经写了十多年的 Java 代码,但仍然觉得自己是个菜鸟(请允许我惭愧一下)。 在一个月黑风高的夜晚,我思前想后,觉得再也不能这么蹉跎下去了。于是痛下决心,准备通过输出的方式倒逼输入,以此来修炼自己的内功,从而进阶成为一名真正意义上的大神。与此同时,希望这些文章能够帮助到更多的读者,让大家在学习的路上不再寂寞、空虚和冷。 ...
雷火神山直播超两亿,Web播放器事件监听是怎么实现的?
Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题,让视音频内容可以不依赖用户安装App,就能进行播放以及在社交平台进行传播。在视频业务大数据平台中,播放数据的统计分析非常重要,所以Web播放器在使用过程中,需要对其内部的数据进行收集并上报至服务端,此时,就需要对发生在其内部的一些播放行为进行事件监听。 那么Web播放器事件监听是怎么实现的呢? 01 监听事件明细表 名
3万字总结,Mysql优化之精髓
本文知识点较多,篇幅较长,请耐心学习 MySQL已经成为时下关系型数据库产品的中坚力量,备受互联网大厂的青睐,出门面试想进BAT,想拿高工资,不会点MySQL优化知识,拿offer的成功率会大大下降。 为什么要优化 系统的吞吐量瓶颈往往出现在数据库的访问速度上 随着应用程序的运行,数据库的中的数据会越来越多,处理时间会相应变慢 数据是存放在磁盘上的,读写速度无法和内存相比 如何优化 设计
Linux 命令(122)—— watch 命令
1.命令简介 2.命令格式 3.选项说明 4.常用示例 参考文献 [1] watch(1) manual
Linux 命令(121)—— cal 命令
1.命令简介 2.命令格式 3.选项说明 4.常用示例 参考文献 [1] cal(1) manual
记jsp+servlet+jdbc实现的新闻管理系统
1.工具:eclipse+SQLyog 2.介绍:实现的内容就是显示新闻的基本信息,然后一个增删改查的操作。 3.数据库表设计 列名 中文名称 数据类型 长度 非空 newsId 文章ID int 11 √ newsTitle 文章标题 varchar 20 √ newsContent 文章内容 text newsStatus 是否审核 varchar 10 news...
Python新型冠状病毒疫情数据自动爬取+统计+发送报告+数据屏幕(三)发送篇
今天介绍的项目是使用 Itchat 发送统计报告 项目功能设计: 定时爬取疫情数据存入Mysql 进行数据分析制作疫情报告 使用itchat给亲人朋友发送分析报告(本文) 基于Django做数据屏幕 使用Tableau做数据分析 来看看最终效果 目前已经完成,预计2月12日前更新 使用 itchat 发送数据统计报告 itchat 是一个基于 web微信的一个框架,但微信官方并不允
相关热词 c# 识别回车 c#生成条形码ean13 c#子控制器调用父控制器 c# 写大文件 c# 浏览pdf c#获取桌面图标的句柄 c# list反射 c# 句柄 进程 c# 倒计时 线程 c# 窗体背景色
立即提问