返回> 网站首页 

一些技巧(10)

yoours2007-04-20 20:05:57 阅读 1085

简介一边听听音乐,一边写写文章。

CString GetForegroundWndFocusWndText(void) 

    CWnd*mainwnd,*subwnd; 
    DWORD dwthreadforeground,dwthreadthis;//获得当前活动窗口 
    mainwnd=GetForegroundWindow();//获得活动窗口的线程号 
    dwthreadforeground=::GetWindowThreadProcessId(mainwnd->m_hWnd,NULL);//获得与自己程序的窗口相关的线程号 
    dwthreadthis=::GetWindowThreadProcessId(m_hWnd,NULL);//将两个线程联系起来,只有这样,GetFocus函数才能获得其他线程中的焦点窗口 
    ::AttachThreadInput(dwthreadthis,dwthreadforeground,TRUE);//得到当前的具有输入焦点的子窗口 
    subwnd=GetFocus(); 
    char lpszText[MAX_PATH]; 
    ::SendMessage(subwnd->m_hWnd,WM_GETTEXT,WPARAM(MAX_PATH),LPARAM(lpszText));//获得窗口中的文字信息 
    ::AttachThreadInput(dwthreadthis,dwthreadforeground,FALSE);//将联到一起的两个线程的输入分离 
    return lpszText; 
    //同理可以得到一切窗口的具有当前焦点的子窗口的句柄 

========================================================================================== 
Office Word程序的开发 
加入MSWORD9.OLB文件 
方法:添加类—》欢迎使用从类型库添加类向导 
选择接口 
_Application 
Documents 
_Document 
到右边 
程序如下: 
    CApplication app; 
    app.CreateDispatch("Word.application"); 
    //app.SetVisible(false); 
    CDocuments docs; 
    CDocument0 doc; 
    //docs=app.GetDocuments(); 
        app.get_Documents(); 
    CComVariant var; 
    var.vt=VT_ERROR; 
    var.scode=DISP_E_PARAMNOTFOUND; 
    doc=docs.Open(&CComVariant(FileNameStr),&var,&var,&var,&var,&var,&var,&var,&var,&var,&var,&var); 
未完 
========================================================================================== 
位图文件头54字节 
UINT iW=672,iH=480;位图大小 
CFile fbmp; 
fbmp.Open("C:\\b.bmp",CFile::modeRead|CFile::typeBinary|CFile::shareExclusive);//打开文件 
fbmp.Seek(54,CFile::begin);//位图文件头为54字节 
fbmp.ReadHuge(pBitsSrc,(long)(iw*iH*3));//读文件 
fbmp.Close(); 
========================================================================================== 
::Sleep(2000);//休眠2s 
========================================================================================== 
LONG cch; 
cch = SendMessage(predoc->hwndRE, WM_GETTEXTLENGTH, 0, 0); 
微信小程序扫码登陆

文章评论

1085人参与,0条评论