goo blog サービス終了のお知らせ 

コード関係のストック

仕事や趣味で作ったコードを溜めておく場所

blogタイトルどおりのを久しぶりに その2

2005-11-22 | Weblog
長すぎると怒られたのでパート2

Sub GetXDWDocInfo()
If Cells(1, 1).Value = "" Then Exit Sub

Dim API_result As Long
API_result = 0

Dim h As Long 'XDW_DOCUMENT_HANDLE
h = 0& 'h.dummy = 0

Dim mode As XDW_OPEN_MODE
mode.nSize = 8 'Marshal.SizeOf(typeof(XDW_OPEN_MODE));//8
mode.nOption = XDW_OPEN_UPDATE

API_result = XDW_OpenDocumentHandle(Cells(1, 1).Value, h, mode)
Debug.Print API_result; "h = "; h

Dim DocInfo As XDW_DOCUMENT_INFO
DocInfo.nPages = 0
DocInfo.nSize = 40 'Marshal.SizeOf(typeof(XDW_DOCUMENT_docinfo))
DocInfo.nBinderColor = 0
DocInfo.nBinderSize = 0
DocInfo.nDocType = 0
DocInfo.nDocuments = 0
DocInfo.nOriginalData = 0
DocInfo.nPermission = 0
DocInfo.nShowAnnotations = 0
DocInfo.nVersion = 0

API_result = XDW_GetDocumentInformation(h, DocInfo)
Debug.Print API_result; "Page = "; DocInfo.nPages

'テキストアノテーションを作成する
Dim annotation As Long 'XDW_ANNOTATION_HANDLE
annotation = 0 'annotation.dummy = 0
' XDW_AA_INITIAL_DATA InitData;
' InitData.nAnnotationType = 0;
' InitData.nReserved1 =0;
' InitData.nReserved2=0;
' InitData.nSize = Marshal.SizeOf(typeof(XDW_AA_INITIAL_DATA));
API_result = XDW_AddAnnotation(h, XDW_AID.XDW_AID_TEXT, 1, 500, 500, 0, annotation, 0)
Debug.Print "XDW_AddAnnotation : "; API_result; ""

'作成したアノテーションに文字列を設定する
API_result = XDW_SetAnnotationAttribute(h, annotation, "%Text", XDW_AnnotationType.XDW_ATYPE_STRING, _
"このアノテーションは,Excel VBAで作製しました。", 0, 0)
Debug.Print "XDW_SetAnnotationAttribute : "; API_result

API_result = XDW_SaveDocument(h, 0)
Debug.Print "XDW_SaveDocument : "; API_result

Cells(1, 2).Value = "ドキュメントに" & DocInfo.nPages & "ページあります。"
API_result = XDW_CloseDocumentHandle(h, 0&)
Debug.Print API_result
End Sub
Sub print_error(code As Long)
Select Case code
Case XDW_E_NOT_INSTALLED:
MsgBox "DocuWorksがインストールされていません。"

Case XDW_E_FILE_NOT_FOUND:
MsgBox "指定されたファイルが見つかりません。"

Case XDW_E_ACCESSDENIED, XDW_E_INVALID_NAME, XDW_E_BAD_NETPATH:
MsgBox "指定されたファイルを開くことができません。"

Case XDW_E_BAD_FORMAT:
MsgBox "指定されたファイルは正しいフォーマットではありません。"

Case XDW_E_INVALID_ACCESS:
MsgBox "指定された操作をする権利がありません。"

Case Else
MsgBox "エラーが発生しました。"
End Select
End Sub

'
' Public Form1()
' {
' //
' // Windows フォーム デザイナ サポートに必要です。
' //
' InitializeComponent();
'
' //
' // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
' //
' }
'
' /// <summary>
' /// 使用されているリソースに後処理を実行します。
' /// </summary>
' protected override void Dispose( bool disposing )
' {
' if( disposing )
' {
' if (components != null)
' {
' components.Dispose();
' }
' }
' base.Dispose( disposing );
' }
'
'
' /// <summary>
' /// アプリケーションのメイン エントリ ポイントです。
' /// </summary>
' [STAThread]
' static void Main()
' {
' Application.Run(new Form1());
' }
'

'
'/*
' private static int add_annotation(XDW_DOCUMENT_HANDLE h, int page, string str)
' {
' // テキストアノテーションを作成する
' XDW_ANNOTATION_HANDLE annotation;
' annotation.dummy = 0;
' XDW_AA_INITIAL_DATA InitData;
' InitData.nAnnotationType = 0;
' InitData.nReserved1 =0;
' InitData.nReserved2=0;
' InitData.nSize = 0;
' int api_result = XDW_AddAnnotation(
' h, XDW_AID.XDW_AID_TEXT, page, 500, 500, InitData, annotation, 0);
' if (api_result <0) return api_result; ' // 作成したアノテーションに文字列を設定する
' api_result = XDW_SetAnnotationAttribute(
' h, annotation, "%Text", XDW_AnnotationType.XDW_ATYPE_STRING, str, 0, 0);
'
' return api_result;
' }
'*/
'
'
' private void button2_Click(object sender, System.EventArgs e)
' {
'
' long api_result = 0;
' string fName = "C:serial.xdw";
' //char in_path[_MAX_PATH];
' //_fullpath(in_path, argv[1], _MAX_PATH);
'/*
' // 文書ハンドルを開く
'
'
'
' if (api_result <0) {
' print_error(api_result);
' return 0;
' }
'
' // XDW_GetDocumentInformationを用いて総ページ数を得る
' XDW_DOCUMENT_INFO info = { sizeof(XDW_DOCUMENT_INFO), 0 };
' XDW_GetDocumentInformation(h, &info);
' int last_page = info.nPages;
'
'*/
' // 文書ハンドルを開く
'
' //XDW_DOCUMENT_HANDLE h = NULL;
' XDW_DOCUMENT_HANDLE h;
' h.dummy=0;
'
' // XDW_OPEN_MODE_EX mode = {
' // sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
' XDW_OPEN_MODE_EX modeOrg;
' modeOrg.nSize = Marshal.SizeOf(typeof(XDW_OPEN_MODE_EX));//12
' modeOrg.nOption = XDW_OPEN_UPDATE;
' modeOrg.nAuthMode = XDW_AUTH_NODIALOGUE;
' //msgbox.Show(Marshal.SizeOf(typeof(XDW_OPEN_MODE_EX)).ToString());
'
' //api_result = XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode);
' XDW_OPEN_MODE mode;
' mode.nSize = Marshal.SizeOf(typeof(XDW_OPEN_MODE));//8
' mode.nOption = XDW_OPEN_UPDATE;
' //msgbox.Show(Marshal.SizeOf(typeof(XDW_OPEN_MODE)).ToString());
' api_result = XDW_OpenDocumentHandle(fName, h, mode);
'
' if (api_result <0)
' {
' print_error(api_result);
' //msgbox.Show(api_result.ToString());
' Application.Exit();
' //return 0;
' }
'
' // XDW_GetDocumentInformationを用いて総ページ数を得る
' XDW_DOCUMENT_INFO info;
' info.nPages = 0;
' info.nSize = Marshal.SizeOf(typeof(XDW_DOCUMENT_INFO));
' info.nBinderColor = 0;
' info.nBinderSize = 0;
' info.nDocType = 0;
' info.nDocuments = 0;
' info.nOriginalData = 0;
' info.nPermission = 0;
' info.nShowAnnotations = 0;
' info.nVersion = 0;
' //= { sizeof(XDW_DOCUMENT_INFO), 0 };
' api_result = XDW_GetDocumentInformation(h, info);
' int last_page = info.nPages;
'/*
' // 現在日時を求める
' //char date[120], time[120], date_time[250];
' //string date, time, date_time;
' string date_time;
' DateTime dt;
' dt = System.DateTime.Now;
' //GetDateFormat(GetThreadLocale(), 0, NULL, NULL, date, 120);
' //GetTimeFormat(GetThreadLocale(), 0, NULL, NULL, time, 120);
' //wsprintf(date_time, "%s %s", date, time);
' date_time = dt.ToString();
' // 各ページにアノテーションを貼り付ける
' for (int i = 1; i <= last_page; i++)
' {
' api_result = add_annotation(h, i, date_time);
' if (api_result <0) ' //print_error(api_result);
' //break;
' msgbox.Show(api_result.ToString());
' Application.Exit();
' }
' }
'
' // 変更をファイルに反映する
' if (api_result >= 0)
' {
' api_result = XDW_SaveDocument(h, 0);
' }
'*/
' // 文書ハンドルを閉じる
' XDW_CloseDocumentHandle(h, 0);
'
' /*
' if (api_result <0) return 0; ' return 1;
' */
' }
' }
'}
'

最新の画像もっと見る

コメントを投稿