mfc小技巧_0104

来源:互联网 发布:java数组约瑟夫环问题 编辑:程序博客网 时间:2024/06/07 08:19

>>>清理vs項目的BAT文件:
    del /q/s *.o *.hex *.bin *.idb *.pdb *.pch *.obj *.lst *.opt *.m51 *.bak *.lnp *.plg *.ncb *.pfi *.po *.rr *.pri *.psc *.__i *.a51 *.IAB *.IAD *.IMB *.IMD *.PR *.PS *.WK3 *.DBG *.ilk

>>>抓取屏蔽任意一点的坐标
    HDC hdcDeskTop = ::GetDC(0); //获取屏幕DC
    DWORD color = GetPixel(hdcDeskTop,7,802); //结果是  BBGGRR 低位是Red
    
>>>执行外部程序WinExec
    WinExec("notepad.exe a.txt", SW_SHOW); //正常运行
    WinExec("notepad.exe a.txt", 0); //后台运行

>>>获取程序当前运行目录
    CString strCurDir;
    GetCurrentDirectory(MAX_PATH,strCurDir.GetBuffer(MAX_PATH));
    CString s1;
    s1.Append(strCurDir.GetBuffer());
    s1.Append("/conf.ini");
    ::WinExec(s1,SW_SHOW);

>>>在对话框按回车会退出
    重载onOK()
    
>>>改变控件的tab的顺序:
    格式->tab键顺序  (或CTRL+D)
    
>>>在对话框嵌入网页
    右键->插入activeX -> Microsoft Web 浏览器  (webBrowser)
    使用:web.Navigate("http://www.google.cn",NULL,NULL,NULL,NULL);
    
>>>FindWindow("窗口类","我的窗口标题");
     如果有多个相同的窗口,则用   FindWindowEx(NULL,hWndBefore,NULL,"我的窗口")

>>>定时器
    setTimer(9999,1000,NULL) ;
    //三个参数分别为:timer标识,时间,回调函数
    //如果第3个参数设置为NULL,则会调用WM_TIMER响应


>>>获取/设置 控件的文本
    GetDlgItem(2000)->GetWindowText(x);
    GetDlgItem(2000)->SetWindowText(x);


>>>MFC默认的HWND:
    m_hWnd


>>>CString转char*
    CString cStr;
    char* c = cStr.getBuffer();
    
>>> int和char*转换
    atoi和itoa
    
>>> string 转 char*
    #include <string>
    using namespace std;
    string str = "aaa";
    char* c = str.c_str();

    
>>>获取系统时间
    SYSTEMTIME  time;
    ::GetSystemTime(&time);
    或
    CTime t = CTime::GetCurrentTime();   
    CString t2 = t.Format("%Y-%m-%d %H:%M:%S");
    
>>>遍历一个程序的所有控件(子类)
    CWnd* wnd = FindWindow("EmEditorMainFrame3",NULL);
    EnumChildWindows(wnd->m_hWnd,enumChildProc, NULL); //调用函数
    BOOL __stdcall enumChildProc(HWND hWnd,LPARAM lParam){  //遍历回调函数
        char   szClassName[20]   =   {0};  
        GetClassName(hWnd,   szClassName,   20);  
        if   (!strcmp(szClassName, "Edit"))   {//如果类名为某值
            AfxMessageBox(szClassName);
            SetWindowText(hWnd,"设置");
            ::PostMessage(hWnd,WM_CHAR,'A',NULL);
        }  
        return TRUE;
    }   


原创粉丝点击