当用户输入正确的数字时,我试图在特定页面打开 pdf,我一直在四处寻找,但在 windows.h 中迷路了,不知道下一步该做什么,这是我的代码:
// 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 *”与“LPCWSTR”类型的参数不兼容
的投诉。
最佳答案
有几件事你应该改变。
编译器/编辑器错误是因为您混合了数据类型。您需要将 ARGV
转换为 LPCWSTR
,因为这是 ShellExecute
所期望的。
为确保 ShellExecute 找到 .pdf,您可以指定文件的完整路径,例如 C:\temp\foo.pdf
(如果硬编码到源代码中,您需要指定反斜杠两次)。
为了告诉 Acrobat 阅读器(我认为并非所有其他替代 pdf 查看器都支持此功能)您要从哪个页面开始,您可以附加 #page=123
。 Adobe 记录 list of possible parameters在 PDF 中 - 你猜对了 ;-) - pdf 文件
关于c++ - 打开pdf并打开特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117434/