有趣的代码 | 打开网址
2025-09-20 22:10:23
发布于:江苏
如果我们想打开 的某个网站,最常用的方法就是输入一个网址,然后 会自动跳转到相应的网站。
其实,也可以通过 代码来实现:
#include <windows.h>
#include <shellapi.h>
int main() {
const wchar_t* url = L"1";
HINSTANCE ret = ShellExecuteW(
nullptr,
L"open",
L"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
url,
nullptr,
SW_SHOWNORMAL
);
if (reinterpret_cast<INT_PTR>(ret) <= 32) {
MessageBoxW(nullptr, L"Failed to open Edge", L"Error", MB_ICONERROR);
return 1;
}
return 0;
}
把你想跳转到的网站的网址复制到代码中1的位置,再运行代码,即使并没有打开 ,也能直接跳转到那个页面。拿 更新哥 的 世界上最恐怖的事情(会更新) 举例:
- 这个网页的网址为
https://www.acgo.cn/discuss/post/56861
,复制到代码中
#include <windows.h>
#include <shellapi.h>
int main() {
const wchar_t* url = L"https://www.acgo.cn/discuss/post/56861";
HINSTANCE ret = ShellExecuteW(
nullptr,
L"open",
L"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
url,
nullptr,
SW_SHOWNORMAL
);
if (reinterpret_cast<INT_PTR>(ret) <= 32) {
MessageBoxW(nullptr, L"Failed to open Edge", L"Error", MB_ICONERROR);
return 1;
}
return 0;
}
- (可以把 关掉,测试实用性)运行代码
(也可以用 ) - 可以直接跳转到界面(这里不放图片了,你们自己尝试,有问题随便问)
这里空空如也
有帮助,赞一个