打开pdf并打开特定页面

时间:2015-06-29 13:49:46

标签: c++ pdf

我正在尝试在用户输入正确的号码时在特定页面上打开pdf,我一直在四处看看但是我迷失了windows.h不知道下一步该怎么做,这里有#s我的代码:

// DungeonsAndDragons.cpp : Defines the entry point for the console application. //  
#include "stdafx.h" 
#include <iostream> 
#include "windows.h"  

using namespace std;

int _tmain(int argc, _TCHAR* argv[]) {  
    int featsSpells;
    int select1;
    int select2; 
    int select3;
    string exit; 
    cout << "******Brad's DnD Feat/Spell Glossary*********" << endl;    
    cout << "Are you looking for Feats[#1] or Spells[#2]" << endl; 

    cin >> featsSpells; 

    if (featsSpells == 1){      
        ShellExecute(GetDesktopWindow(), "open", Argv[1],NULL,NULL,SHOWNORMAL); 
    }           
    system("pause"); 
    return 0;
}

代码无法编译,因为我收到有关"const char *" is incompatible with parameter of type "LPCWSTR"的投诉。

1 个答案:

答案 0 :(得分:1)

你应该改变几件事。

编译器/编辑器错误是因为您正在混合数据类型。您需要将ARGV转换为LPCWSTR,因为这是ShellExecute所期望的。

要确保ShellExecute找到.pdf,您可以指定文件的完整路径,例如C:\temp\foo.pdf(如果硬编码到源代码中,则需要指定反斜杠两次)。

为了告诉您要启动的页面上的Acrobat阅读器(我认为并非所有其他替代pdf查看器都支持此功能),您可以附加#page=123。 Adobe在PDF中记录list of possible parameters - 你猜对了;-) - pdf文件

相关问题