├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── example └── main.cpp ├── images ├── icon.png ├── linux_error.png ├── linux_info.png ├── linux_warning.png ├── mac_error.png ├── mac_info.png ├── mac_warning.png ├── win_error.png ├── win_info.png └── win_warning.png └── include └── NMB └── NMB.h /.gitignore: -------------------------------------------------------------------------------- 1 | # ======= 2 | # FOLDERS 3 | # ======= 4 | /projects 5 | /binaries 6 | /build 7 | /node_modules 8 | 9 | 10 | # =============== 11 | # FILE EXTENSIONS 12 | # =============== 13 | *.obj 14 | *.idb 15 | *.tlog 16 | *.pdb 17 | *.lastbuildstate 18 | *.log 19 | *.suo 20 | *.blend1 21 | *.blend2 22 | *.pro.user 23 | 24 | 25 | # ============= 26 | # VISUAL STUDIO 27 | # ============= 28 | *.opensdf 29 | *.sdf 30 | *.vcxproj.user 31 | *.sln 32 | *.opendb 33 | *.VC.db 34 | 35 | 36 | # ===== 37 | # CLION 38 | # ===== 39 | /.idea 40 | 41 | 42 | # ===== 43 | # CMAKE 44 | # ===== 45 | /cmake-build-debug 46 | /cmake-build-release 47 | 48 | 49 | # ===== 50 | # XCODE 51 | # ===== 52 | *.xcuserstate 53 | .DS_Store 54 | .AppleDouble 55 | .LSOverride 56 | Icon 57 | 58 | 59 | # ======= 60 | # MAC OSX 61 | # ======= 62 | ._* 63 | 64 | 65 | # ============= 66 | # EXTERNAL DISK 67 | # ============= 68 | .Spotlight-V100 69 | .Trashes 70 | 71 | 72 | # ============= 73 | # DO NOT IGNORE 74 | # ============= 75 | !/thirdparty/**/*.dll 76 | !/thirdparty/**/*.lib 77 | !/thirdparty/**/*.dylib 78 | !/thirdparty/**/*.a 79 | !/thirdparty/**/*.so 80 | !/premake/*.exe 81 | .vs/ 82 | UpgradeLog.htm 83 | *.vspx 84 | 85 | 86 | # ==== 87 | # LOGS 88 | # ==== 89 | logs 90 | *.log 91 | npm-debug.log* 92 | yarn-debug.log* 93 | yarn-error.log* 94 | lerna-debug.log* 95 | 96 | 97 | # ============ 98 | # RUNTIME DATA 99 | # ============ 100 | pids 101 | *.pid 102 | *.seed 103 | *.pid.lock 104 | 105 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ======================================================== 2 | # Copyright (c) 2020 Gabriel Schmitz. All rights reserved. 3 | # ======================================================== 4 | 5 | cmake_minimum_required( VERSION 3.16 ) 6 | project( native_message_box ) 7 | set( CMAKE_CXX_STANDARD 14 ) 8 | 9 | 10 | # ======= 11 | # WINDOWS 12 | # ======= 13 | 14 | if( WIN32 ) 15 | 16 | message( STATUS "Platform: Windows" ) 17 | 18 | 19 | # ===== 20 | # MACOS 21 | # ===== 22 | 23 | elseif( APPLE ) 24 | 25 | message( STATUS "Platform: MacOS" ) 26 | 27 | find_library( CORE_FOUNDATION_LIBRARY CoreFoundation ) 28 | if (NOT CORE_FOUNDATION_LIBRARY) 29 | message( FATAL_ERROR ": Framework CoreFoundation not found" ) 30 | else() 31 | message( STATUS "CoreFoundation: ${CORE_FOUNDATION_LIBRARY}" ) 32 | link_libraries( ${CORE_FOUNDATION_LIBRARY} ) 33 | endif() 34 | 35 | 36 | # ===== 37 | # LINUX 38 | # ===== 39 | 40 | elseif( UNIX ) 41 | 42 | message( STATUS "Platform: Linux" ) 43 | 44 | FIND_PACKAGE( PkgConfig REQUIRED) 45 | PKG_CHECK_MODULES( GTK REQUIRED gtk+-3.0 ) 46 | INCLUDE_DIRECTORIES(${GTK_INCLUDE_DIRS}) 47 | LINK_DIRECTORIES(${GTK_LIBRARY_DIRS}) 48 | ADD_DEFINITIONS(${GTK_CFLAGS_OTHER}) 49 | link_libraries( ${GTK_LIBRARIES} ) 50 | 51 | 52 | # =========== 53 | # UNSUPPORTED 54 | # =========== 55 | 56 | else() 57 | 58 | message( FATAL_ERROR "Platform: Not supported" ) 59 | 60 | endif() 61 | 62 | 63 | # =================== 64 | # EXAMPLE APPLICATION 65 | # =================== 66 | 67 | add_executable( native_message_box_example example/main.cpp ) 68 | target_include_directories( native_message_box_example PRIVATE include ) 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Gabriel Schmitz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Icon](images/icon.png) 2 | 3 | # Native Message Box 4 | NMB or (N)ative (M)essage (B)ox is a very tiny, cross platform and header only C++ library to handle message dialogs natively. 5 | 6 | ## Supported 7 | - Windows (using [Winuser.h](https://docs.microsoft.com/en-us/windows/win32/api/winuser/)) 8 | - MacOS (using [CoreFoundation](https://developer.apple.com/documentation/corefoundation)) 9 | - Linux (using [GTK](https://www.gtk.org/docs/installations/linux/)) 10 | 11 | ## Example Usage 12 | 13 | ```cpp 14 | #include "NMB/NMB.h" 15 | 16 | ... 17 | 18 | NMB::Result result = NMB::show( "Error", "Error Message", NMB::Icon::ICON_ERROR ); 19 | 20 | if( result == NMB::Result::OK ) 21 | { 22 | // DO SOMETHING 23 | } 24 | else 25 | { 26 | // DO SOMETHING ELSE 27 | } 28 | ``` 29 | 30 | ## Screenshots 31 | ### Windows 32 | 33 | ![WinInfo](images/win_info.png) 34 | 35 | ![WinWarning](images/win_warning.png) 36 | 37 | ![WinError](images/win_error.png) 38 | 39 | ### MacOS 40 | 41 | ![MacInfo](images/mac_info.png) 42 | 43 | ![MacWarning](images/mac_warning.png) 44 | 45 | ![MacError](images/mac_error.png) 46 | 47 | ### Linux 48 | 49 | ![LinuxInfo](images/linux_info.png) 50 | 51 | ![LinuxWarning](images/linux_warning.png) 52 | 53 | ![LinuxError](images/linux_error.png) 54 | 55 | ## License 56 | 57 | LICENSE File covers all files in this repo. 58 | -------------------------------------------------------------------------------- /example/main.cpp: -------------------------------------------------------------------------------- 1 | #include "NMB/NMB.h" 2 | #include 3 | 4 | 5 | #if defined(__linux__) 6 | static void dummy( GtkApplication* p_app, gpointer user_data ){} 7 | #endif 8 | 9 | 10 | int main( int argc, char** argv ) 11 | { 12 | #if defined(__linux__) 13 | GtkApplication* p_app = gtk_application_new( "org.native_message_box.example", G_APPLICATION_FLAGS_NONE ); 14 | g_signal_connect( p_app, "activate", G_CALLBACK(dummy), NULL ); 15 | g_application_run( G_APPLICATION(p_app), argc, argv ); 16 | #endif 17 | 18 | NMB::Result info = NMB::show( "Info", "I am some really valuable information, but nobody ever reads me. If only I were recognized by somebody. :(", NMB::Icon::ICON_INFO ); 19 | NMB::Result warning = NMB::show( "Warning", "Look at the yellow sign to my left. It is yellow, not even red. So just proceed.", NMB::Icon::ICON_WARNING ); 20 | NMB::Result error = NMB::show( "Error", "Oh Crap. I can't take this any more. This is a hell of an error. Just Run!", NMB::Icon::ICON_ERROR ); 21 | 22 | printf( "Info: %i\n", info ); 23 | printf( "Warning: %i\n", warning ); 24 | printf( "Error: %i\n", error ); 25 | 26 | #if defined(__linux__) 27 | g_object_unref( p_app ); 28 | #endif 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/icon.png -------------------------------------------------------------------------------- /images/linux_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/linux_error.png -------------------------------------------------------------------------------- /images/linux_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/linux_info.png -------------------------------------------------------------------------------- /images/linux_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/linux_warning.png -------------------------------------------------------------------------------- /images/mac_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/mac_error.png -------------------------------------------------------------------------------- /images/mac_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/mac_info.png -------------------------------------------------------------------------------- /images/mac_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/mac_warning.png -------------------------------------------------------------------------------- /images/win_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/win_error.png -------------------------------------------------------------------------------- /images/win_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/win_info.png -------------------------------------------------------------------------------- /images/win_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thegabman/native_message_box/dfbd5471553c68002d51e18bbcd24b2527706609/images/win_warning.png -------------------------------------------------------------------------------- /include/NMB/NMB.h: -------------------------------------------------------------------------------- 1 | // ======================================================== 2 | // Copyright (c) 2020 Gabriel Schmitz. All rights reserved. 3 | // ======================================================== 4 | 5 | #pragma once 6 | 7 | 8 | #if defined(_WIN32) 9 | #include 10 | #elif defined(__APPLE__) 11 | #include 12 | #elif defined(__linux__) 13 | #include 14 | #else 15 | #error "Platform not supported!" 16 | #endif 17 | 18 | 19 | namespace NMB 20 | { 21 | 22 | enum Result 23 | { 24 | CANCEL, 25 | OK 26 | }; 27 | 28 | enum Icon 29 | { 30 | ICON_INFO, 31 | ICON_WARNING, 32 | ICON_ERROR 33 | }; 34 | 35 | 36 | Result show( const char* p_title, const char* p_message, Icon icon ) 37 | { 38 | #if defined(_WIN32) 39 | 40 | int icon_flag; 41 | 42 | switch( icon ) 43 | { 44 | case NMB::Icon::ICON_INFO: 45 | icon_flag = MB_ICONINFORMATION; 46 | break; 47 | case NMB::Icon::ICON_WARNING: 48 | icon_flag = MB_ICONWARNING; 49 | break; 50 | case NMB::Icon::ICON_ERROR: 51 | icon_flag = MB_ICONERROR; 52 | break; 53 | } 54 | 55 | int result = MessageBoxA( nullptr, p_message, p_title, MB_OKCANCEL | MB_SYSTEMMODAL | icon_flag ); 56 | 57 | if( result == IDOK ) 58 | return NMB::Result::OK; 59 | else 60 | return NMB::Result::CANCEL; 61 | 62 | #elif defined(__APPLE__) 63 | 64 | CFOptionFlags cf_alert_icon; 65 | 66 | switch( icon ) 67 | { 68 | case NMB::Icon::ICON_INFO: 69 | cf_alert_icon = kCFUserNotificationNoteAlertLevel; 70 | break; 71 | case NMB::Icon::ICON_WARNING: 72 | cf_alert_icon = kCFUserNotificationCautionAlertLevel; 73 | break; 74 | case NMB::Icon::ICON_ERROR: 75 | cf_alert_icon = kCFUserNotificationStopAlertLevel; 76 | break; 77 | } 78 | 79 | CFStringRef cf_title = CFStringCreateWithCString( kCFAllocatorDefault, p_title, kCFStringEncodingUTF8 ); 80 | CFStringRef cf_message = CFStringCreateWithCString( kCFAllocatorDefault, p_message, kCFStringEncodingUTF8 ); 81 | 82 | CFOptionFlags result; 83 | 84 | CFUserNotificationDisplayAlert( 0, cf_alert_icon, nullptr, nullptr, nullptr, cf_title, cf_message, CFSTR("OK"), CFSTR("Cancel"), nullptr, &result ); 85 | 86 | CFRelease( cf_title ); 87 | CFRelease( cf_message ); 88 | 89 | if( result == kCFUserNotificationDefaultResponse ) 90 | return NMB::Result::OK; 91 | else 92 | return NMB::Result::CANCEL; 93 | 94 | #elif defined(__linux__) 95 | 96 | GtkMessageType gtk_message_type; 97 | 98 | switch( icon ) 99 | { 100 | case NMB::Icon::ICON_INFO: 101 | gtk_message_type = GTK_MESSAGE_INFO; 102 | break; 103 | case NMB::Icon::ICON_WARNING: 104 | gtk_message_type = GTK_MESSAGE_WARNING; 105 | break; 106 | case NMB::Icon::ICON_ERROR: 107 | gtk_message_type = GTK_MESSAGE_ERROR; 108 | break; 109 | } 110 | 111 | GtkWidget* p_dialog = gtk_message_dialog_new( nullptr, GTK_DIALOG_DESTROY_WITH_PARENT, gtk_message_type, GTK_BUTTONS_OK_CANCEL, "%s\n\n%s", p_title, p_message ); 112 | gint result = gtk_dialog_run( GTK_DIALOG(p_dialog) ); 113 | gtk_widget_destroy( p_dialog ); 114 | 115 | if( result == GTK_RESPONSE_OK ) 116 | return NMB::Result::OK; 117 | else 118 | return NMB::Result::CANCEL; 119 | 120 | #else 121 | 122 | #error "Platform not supported!" 123 | 124 | #endif 125 | } 126 | 127 | } 128 | --------------------------------------------------------------------------------