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

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

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

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

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

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

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

这个问题。。最好保证自己的服务是在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)
《MySQL 性能优化》之理解 MySQL 体系结构
本文介绍 MySQL 的体系结构,包括物理结构、逻辑结构以及插件式存储引擎。
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
C语言荣获2019年度最佳编程语言
关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang近日,TIOBE官方发布了2020年1月编程语言排行榜单。我在前面给过一篇文章《2019年11月C语言接近Ja...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
应届生/社招面试最爱问的几道Java基础问题
本文已经收录自笔者开源的 JavaGuide: https://github.com/Snailclimb (【Java学习 面试指南】 一份涵盖大部分Java程序员所需要掌握的核心知识)如果觉得不错的还,不妨去点个Star,鼓励一下! 一 为什么 Java 中只有值传递? 首先回顾一下在程序设计语言中有关将参数传递给方法(或函数)的一些专业术语。按值调用(call by value)表...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
最全最强!世界大学计算机专业排名总结!
我正在参与CSDN200进20,希望得到您的支持,扫码续投票5次。感谢您! (为表示感谢,您投票后私信我,我把我总结的人工智能手推笔记和思维导图发送给您,感谢!) 目录 泰晤士高等教育世界大学排名 QS 世界大学排名 US News 世界大学排名 世界大学学术排名(Academic Ranking of World Universities) 泰晤士高等教育世界大学排名 中国共...
一份王者荣耀的英雄数据报告
咪哥杂谈本篇阅读时间约为 6 分钟。1前言前一阵写了关于王者的一些系列文章,从数据的获取到数据清洗,数据落地,都是为了本篇的铺垫。今天来实现一下,看看不同维度得到的结论。2环境准备本次实...
作为一名大学生,如何在B站上快乐的学习?
B站是个宝,谁用谁知道???? 作为一名大学生,你必须掌握的一项能力就是自学能力,很多看起来很牛X的人,你可以了解下,人家私底下一定是花大量的时间自学的,你可能会说,我也想学习啊,可是嘞,该学习啥嘞,不怕告诉你,互联网时代,最不缺的就是学习资源,最宝贵的是啥? 你可能会说是时间,不,不是时间,而是你的注意力,懂了吧! 那么,你说学习资源多,我咋不知道,那今天我就告诉你一个你必须知道的学习的地方,人称...
那些年,我们信了课本里的那些鬼话
教材永远都是有错误的,从小学到大学,我们不断的学习了很多错误知识。 斑羚飞渡 在我们学习的很多小学课文里,有很多是错误文章,或者说是假课文。像《斑羚飞渡》: 随着镰刀头羊的那声吼叫,整个斑羚群迅速分成两拨,老年斑羚为一拨,年轻斑羚为一拨。 就在这时,我看见,从那拨老斑羚里走出一只公斑羚来。公斑羚朝那拨年轻斑羚示意性地咩了一声,一只半大的斑羚应声走了出来。一老一少走到伤心崖,后退了几步,突...
一个程序在计算机中是如何运行的?超级干货!!!
强烈声明:本文很干,请自备茶水!???? 开门见山,咱不说废话! 你有没有想过,你写的程序,是如何在计算机中运行的吗?比如我们搞Java的,肯定写过这段代码 public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } ...
【蘑菇街技术部年会】程序员与女神共舞,鼻血再次没止住。(文末内推)
蘑菇街技术部的年会,别开生面,一样全是美女。
那个在阿里养猪的工程师,5年了……
简介: 在阿里,走过1825天,没有趴下,依旧斗志满满,被称为“五年陈”。他们会被授予一枚戒指,过程就叫做“授戒仪式”。今天,咱们听听阿里的那些“五年陈”们的故事。 下一个五年,猪圈见! 我就是那个在养猪场里敲代码的工程师,一年多前我和20位工程师去了四川的猪场,出发前总架构师慷慨激昂的说:同学们,中国的养猪产业将因为我们而改变。但到了猪场,发现根本不是那么回事:要个WIFI,没有;...
立即提问