标签: vc

  • 用CHtmlView接口获取HTML源文件

    用CHtmlView接口获取HTML源文件:

    支持在UNICODE工程下获取HTML代码,无乱码。。。。发了两年多了才知道,害得我找了一晚上,没想到自己的博客里就有。。。

    BOOL CWeb::GetSource(CString& strString) 
    { 
        IHTMLDocument2* pHtmlDoc2 = (IHTMLDocument2*)GetHtmlDocument(); 
        // check if HtmlDocument initialized 
        if( pHtmlDoc2 != NULL) 
        { 
            IHTMLDocument3* pHTMLDoc3 = NULL; 
            HRESULT hr = pHtmlDoc2->QueryInterface(IID_IHTMLDocument3, (LPVOID*)&pHTMLDoc3); 
            ASSERT(SUCCEEDED(hr)); 
            if(pHTMLDoc3) 
            { 
                IHTMLElement* pDocElem=NULL; 
                hr = pHTMLDoc3->get_documentElement(&pDocElem); 
                ASSERT(SUCCEEDED(hr)); 
                if(pDocElem) 
                { 
                    BSTR bstrHTML; 
                    pDocElem->get_outerHTML(&bstrHTML); 
                    pDocElem->Release(); 
                    USES_CONVERSION; 
                    //MessageBox(OLE2T(bstrHTML), _T("源文件")); 
                    strString = OLE2T(bstrHTML); 
                    SysFreeString(bstrHTML); 
                } 
                pHTMLDoc3->Release(); 
            } 
            pHtmlDoc2->Release(); 
            pHtmlDoc2=NULL; 
        }
        return TRUE; 
    }
  • VC中, 关于UNICODE的L和_T()

    1.  UNICODE项目下,字符串用L是可以的,但项目再转成 多字节编码时, L就不能编译通过

    2.  如果用_T() 或 _TEXT()则可以在UINCODE和多字节编码项目下 都 可以无修改编译通过

  • 关于gethostname函数失败的问题

    调用gethostname函数失败。

    解决办法:调用gethostname之前, 要先调用WSAStartup才可以, 否则gethostname会失败!

    下面是正确的代码

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <Winsock2.h>
    #include <windows.h>
    #pragma comment(lib, "Ws2_32")
    int main()
    {
    	WSADATA wsData;
    	::WSAStartup(MAKEWORD(2,2), &wsData);
    	char szIP[32] = {0};
    	char szHostName[32] = {0};
    	int iResult = ::gethostname(szHostName, sizeof(szHostName));
    	if (iResult != 0)
    	{
    		printf("error/n");
    		return -1;
    	}
    	printf("%s/n", szHostName);
    	hostent *pHost = ::gethostbyname(szHostName);
    	::WSACleanup();
    	return 0;
    } 
  • 配置VC++使用PROC

    假定ORACLE安装目录为D:/oracle/

    工具–>选项–>项目和解决方案–>VC++目录

    可执行文件 D:/oracle/ora90/BIN
    包含文件 D:/oracle/ora90/precomp/public
    库文件 D:/oracle/ora90/precomp/lib/msvc

    确定–>重启VS–>OK

  • 关于VC++预处理指令#和##

    #不管传入什么参数,都会转换成字符串

    ##不管是什么类型,都会连接到一起,但要求传入的参数应该是同一种类型

    eg.

    //language:c
    #include <stdio.h>
    int main()
    {
    #define PASTE(a,b,c) (#a#b#c)
        printf("%s/n", PASTE(7,8,9));
    #define NUM(a,b,c) (a##b##c)
        printf("%d/n", NUM(1,2,3));
    #define STR(a,b,c) (a##b##c)
        printf("%s/n", STR("a","b","c"));
        return 0;
    }

  • 关于VC里触发断点的另一种方法

     在需要加断点的地方添加: __asm int 3 

  • Win32编程,让DC不重画某个区域的API函数

    Win32编程,让DC不重画某个区域的API函数:ExcludeClipRect

    描述:这个函数将创建一个新的区域,这个新的区域 由 现有的区域 去掉 指定区域 后 组成。

    功能:可以让DC不刷新某个指定区域。

    说明:这个函数在MFC中的CDC类里有封装。

    int ExcludeClipRect(
        HDC hdc, // handle to DC
        int nLeftRect, // x-coord of upper-left corner
        int nTopRect, // y-coord of upper-left corner
        int nRightRect, // x-coord of lower-right corner
        int nBottomRect // y-coord of lower-right corner
    );