mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpigui] Add OpenURL (#4273)
This function opens a URL using the default browser.
This commit is contained in:
28
wpigui/src/main/native/cpp/wpigui_openurl.cpp
Normal file
28
wpigui/src/main/native/cpp/wpigui_openurl.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "wpigui_openurl.h"
|
||||
|
||||
#if _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
#include <shellapi.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void wpi::gui::OpenURL(const std::string& url) {
|
||||
#ifdef _WIN32
|
||||
ShellExecuteA(nullptr, "open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
static constexpr const char* opencmd = "open";
|
||||
#else
|
||||
static constexpr const char* opencmd = "xdg-open";
|
||||
#endif
|
||||
execlp(opencmd, opencmd, url.c_str(), static_cast<const char*>(nullptr));
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user