• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            JACKY_ZZ[貓貓愛吃魚]

            春風(fēng)拂面兩頰紅,秋葉灑地一片金。 夏荷搖曳一身輕,冬雪覆蓋大地銀。
            posts - 30, comments - 123, trackbacks - 0, articles - 0

            [C/C++] vole使用的簡(jiǎn)單例子

            Posted on 2010-12-07 11:02 jacky_zz 閱讀(416) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C/C++
            stdafx.h
             1 #pragma once
             2 
             3 #include "targetver.h"
             4 
             5 #include <stdio.h>
             6 #include <tchar.h>
             7 #include <windows.h>
             8 #include <string>
             9 
            10 #include <vole/vole.hpp>
            11 #include <comstl/util/initialisers.hpp>
            12 
            13 using vole::object;
            14 using vole::collection;
            vword.cpp
              1#include "stdafx.h"
              2
              3#define HINT _T("please provide a xml file first.\n") \
              4    _T("format is:\n") \
              5    _T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n") \
              6    _T("<bookmarks>\n") \
              7    _T("\t<bookmark name=\"\" value=\"\"/>\n") \
              8    _T("\t\n") \
              9    _T("\t<bookmark name=\"\" value=\"\"/>\n") \
             10    _T("</bookmarks>") \
             11
             12int _tmain(int argc, _TCHAR* argv[])
             13{
             14    if(argc != 2)
             15    {
             16        MessageBox(GetActiveWindow(), HINT, _T("Error"), MB_OK | MB_ICONERROR);
             17        return 0;
             18    }

             19
             20    wchar_t filename[MAX_PATH];
             21
             22#ifdef _UNICODE
             23    // wcscpy_s(filename, MAX_PATH, _T("./1.xml"));
             24    wcscpy_s(filename, MAX_PATH, argv[1]);
             25#else
             26    MultiByteToWideChar(CP_ACP, 0, argv[1], strlen(argv[1]), filename, MAX_PATH);
             27#endif
             28
             29    // initialization vole
             30    comstl::com_init init;
             31
             32    // create xml DOM object
             33    object xml = object::create("Msxml2.DOMDocument");
             34    bool success = xml.invoke_method<bool>(L"load", filename);
             35    if(!success)
             36        return 0;
             37
             38    // get root element
             39    object documentElement = xml.get_property<object>(L"documentElement");
             40
             41    // get child nodes of root element
             42    object childNodes = documentElement.get_property<object>(L"childNodes");
             43    long length = childNodes.get_property<long>(L"length");
             44
             45    // create word automation object
             46    object word = object::create("Word.Application", CLSCTX_LOCAL_SERVER, vole::coercion_level::naturalPromotion);
             47    word.put_property(L"Visible"false);
             48
             49    // open local word file
             50    collection documents = word.get_property<collection>(L"Documents");
             51    object document = documents.invoke_method<object>(L"Open", L"C:\\1.doc");
             52
             53    // retrieve bookmarks in opened document
             54    collection bookmarks = document.get_property<collection>(L"Bookmarks");
             55    int count = bookmarks.get_property<int>(L"Count");
             56
             57    // starting find bookmark, insert value after bookmark if found
             58    for(long i = 0; i < length; i++)
             59    {
             60        object node = childNodes.get_property<object>(L"item", i);
             61        object attributes = node.get_property<object>(L"attributes");
             62        long attribute_length = attributes.get_property<long>(L"length");
             63
             64        object node1 = attributes.invoke_method<object>(L"getNamedItem", L"name");
             65        object node2 = attributes.invoke_method<object>(L"getNamedItem", L"value");
             66
             67        std::string value1 = node1.get_property<std::string>(L"nodeValue");
             68        std::string value2 = node2.get_property<std::string>(L"nodeValue");
             69
             70        for(int j = 1; j <= count; j++)
             71        {
             72            object bookmark = bookmarks.invoke_method<object>(L"Item", j);
             73            std::string name = bookmark.get_property<std::string>(L"Name");
             74
             75            char* name1 = const_cast<char*>(name.c_str());
             76            char* name2 = const_cast<char*>(value1.c_str());
             77
             78            if(strcmp(name1, name2) == 0)
             79            {
             80                char* value = const_cast<char*>(value2.c_str());
             81                size_t len = strlen(value);
             82
             83                wchar_t* w_value = (wchar_t*)malloc(len * 2 + 1);
             84                MultiByteToWideChar(CP_ACP, 0, value, len, w_value, len);
             85
             86                object range = bookmark.get_property<object>(L"Range");
             87                range.invoke_method_v(L"InsertAfter", (LPCWSTR)w_value);
             88
             89                free(w_value);
             90                w_value = NULL;
             91                value = NULL;
             92
             93                break;
             94            }

             95
             96            name1 = NULL;
             97            name2 = NULL;
             98        }

             99    }

            100
            101    document.invoke_method_v(L"Save");
            102    document.invoke_method_v(L"Close"false);
            103    word.invoke_method_v(L"Quit");
            104
            105    system("pause");
            106    return 0;
            107}
            国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产精品久久99| 99久久国产综合精品网成人影院| 97精品国产97久久久久久免费| 开心久久婷婷综合中文字幕| 亚洲日本va中文字幕久久| 久久综合九色综合精品| 久久国内免费视频| 91精品国产色综久久 | 久久亚洲精精品中文字幕| 999久久久免费国产精品播放| 综合久久国产九一剧情麻豆| 99久久99久久精品国产片果冻| 伊人久久大香线蕉av不卡| 久久久久噜噜噜亚洲熟女综合| 亚洲精品国产美女久久久| 久久综合伊人77777| 97久久精品人人做人人爽| 久久久久久国产精品免费无码| 久久综合成人网| 久久综合狠狠综合久久激情 | 久久国产亚洲高清观看| 一本色综合网久久| 天天综合久久一二三区| 国产免费久久精品丫丫| 色综合久久天天综合| 国产精品久久一区二区三区| 久久人人爽人人爽人人AV东京热| 无码任你躁久久久久久老妇App| 久久高清一级毛片| 99久久www免费人成精品| 欧美久久精品一级c片片| 久久人爽人人爽人人片AV| 99久久国产综合精品女同图片 | 国产一级持黄大片99久久| 精品久久久久久无码中文字幕一区| 久久人妻AV中文字幕| 亚洲狠狠婷婷综合久久久久| 亚洲成色WWW久久网站| 亚洲精品国精品久久99热一| 狼狼综合久久久久综合网|