• <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[貓貓愛吃魚]

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

            [C/C++] vole使用的簡單例子

            Posted on 2010-12-07 11:02 jacky_zz 閱讀(416) 評論(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}
            久久久午夜精品福利内容| 久久国产成人| 久久久www免费人成精品| 国产一区二区精品久久岳| 91久久精品国产91性色也| 精品国产一区二区三区久久| 亚洲精品乱码久久久久久| 亚洲精品国精品久久99热一| 亚洲国产精品久久久天堂| 狼狼综合久久久久综合网| 久久亚洲美女精品国产精品| 国产精品美女久久久m| 久久青青草原精品影院| 国产成人无码精品久久久免费 | 国产巨作麻豆欧美亚洲综合久久| 国产精品久久一区二区三区| 国产精品gz久久久| 亚洲第一永久AV网站久久精品男人的天堂AV | 久久久无码人妻精品无码| 久久国产精品成人片免费| 色成年激情久久综合| 色99久久久久高潮综合影院| 伊人久久大香线蕉亚洲五月天| 久久久久99精品成人片试看| 久久精品水蜜桃av综合天堂 | 久久久久亚洲av毛片大| 麻豆av久久av盛宴av| 2022年国产精品久久久久| 国产免费久久精品丫丫| 久久久久久久久久久久久久| 波多野结衣中文字幕久久| 国产激情久久久久影院| 亚洲精品乱码久久久久久蜜桃不卡| 久久99国产精品99久久| 人人妻久久人人澡人人爽人人精品| 麻豆亚洲AV永久无码精品久久 | 国产美女久久精品香蕉69| 久久久久国产一级毛片高清板| 久久久久亚洲av无码专区喷水 | 天天做夜夜做久久做狠狠| 久久er国产精品免费观看2|