Add a windows msg box, fix dark mode button.

Add text file menu and a pch.h file for later.
Move text file functions into text file menu.
Add test dll for project.
This commit is contained in:
kelson8 2024-08-25 13:34:08 -04:00
parent a0dfb53a9a
commit 26e3acf9eb
7 changed files with 249 additions and 63 deletions

View File

@ -16,10 +16,10 @@ int main(int, char**)
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <windows.h>
// Main code // Main code
// I moved the DirectX9 code into the test/directx9_test.cpp file, // I moved the DirectX9 code into the test/directx9_test.cpp file,
// The code above is disabled with a preprocessor.
#ifdef _DIRECTX9 #ifdef _DIRECTX9
#include "test/directx9_test.h" #include "test/directx9_test.h"
@ -29,8 +29,96 @@ int main(int, char**)
#include "test/opengl_test.h" #include "test/opengl_test.h"
#endif //_OPENGL #endif //_OPENGL
// New
#include <shellapi.h>
// https://stackoverflow.com/questions/14954876/how-to-create-a-message-box-with-user-defined-buttons-in-c
/*
* MessageBox() Flags
* These could be useful.
*/
//#define MB_OK 0x00000000L
//#define MB_OKCANCEL 0x00000001L
//#define MB_ABORTRETRYIGNORE 0x00000002L
//#define MB_YESNOCANCEL 0x00000003L
//#define MB_YESNO 0x00000004L
//#define MB_RETRYCANCEL 0x00000005L
//#if(WINVER >= 0x0500)
//#define MB_CANCELTRYCONTINUE 0x00000006L
//#endif /* WINVER >= 0x0500 */
// Needed for the dll, what exactly does this do?
typedef VOID(*DLLPROC) (LPTSTR);
int main(int, char**) int main(int, char**)
{ {
#define _TEST1
// Load a test dll
// Get path to the dll, use current path
// https://stackoverflow.com/questions/61382829/dynamically-use-a-dll-from-a-console-application
// https://www.tutorialspoint.com/dll/dll_writing.htm
// This seems to inject but I don't see the message box pop up
#ifdef _TEST1
#ifdef _DIRECTX9
HINSTANCE hinstDLL;
DLLPROC HelloWorld;
BOOL fFreeDLL;
hinstDLL = LoadLibrary("KCNet-TestDll.dll");
const std::string url = "https://git.internal.kelsoncraft.net/";
if (!hinstDLL)
{
// Well this seems to work well for an error message.
// TODO Add clickable links in this.
//Link is here: https://git.internal.kelsoncraft.net/"
//MessageBox(NULL, TEXT("You need the KCNet-TestDll.dll for this to work.\n Would you like to visit the link?: "),
// TEXT("Dll not found!"), MB_YESNO);
// https://stackoverflow.com/questions/12578642/how-to-detect-which-yes-no-cancel-button-was-clicked-in-a-messagebox
const int result = MessageBox(NULL, TEXT("You need the KCNet-TestDll.dll for this to work.\n Would you like to visit the link?: "),
TEXT("Dll not found!"), MB_YESNO);
switch (result)
{
case IDYES:
// https://stackoverflow.com/questions/17347950/how-do-i-open-a-url-from-c
//ShellExecute(0, 0, TEXT(url), 0, 0, SW_SHOW);
// I was able to remove the char* from the above by using c_str() on url.
ShellExecute(0, 0, url.c_str(), 0, 0, SW_SHOW);
break;
case IDNO:
break;
}
std::cout << "Could not find the dynamic library." << std::endl;
return EXIT_FAILURE;
// Continue with program if dll is found
}
else
{
std::cout << "Dynamic library loaded." << std::endl;
HelloWorld = (DLLPROC)GetProcAddress(hinstDLL, "HelloWorld");
// Run the message box prompt if it exists.
if (HelloWorld != NULL)
(HelloWorld);
// Unload the dll
fFreeDLL = FreeLibrary(hinstDLL);
}
#endif //_DIRECTX9
#endif //_TEST1
#ifdef _DIRECTX9 #ifdef _DIRECTX9
DirectX9Test::directX9Test(); DirectX9Test::directX9Test();
#endif //_DIRECTX9 #endif //_DIRECTX9
@ -39,6 +127,14 @@ int main(int, char**)
OpenGLTest::openGLTest(); OpenGLTest::openGLTest();
#endif //_OPENGL #endif //_OPENGL
// TODO Add these sometime
#ifdef _DIRECTX11
#endif //_DIRECTX11
#ifdef _DIRECTX12
#endif //_DIRECTX11
//std::cout << "Hello World"; //std::cout << "Hello World";
} }
#endif // _TEST #endif // _TEST

View File

@ -23,19 +23,21 @@
// Test macros // Test macros
#define LIMIT 5 #define LIMIT 5
// This file is inactive, not in use yet.
// Boolean values // Boolean values
bool DirectX9Test::show_demo_window = true; bool DirectX9Test::show_demo_window = false;
bool DirectX9Test::button1_clicked = false; bool DirectX9Test::button1_clicked = false;
bool DirectX9Test::show_app_main_menu_bar = false; bool DirectX9Test::show_app_main_menu_bar = false;
bool DirectX9Test::toggle_text = false; bool DirectX9Test::toggle_text = false;
bool DirectX9Test::dark_mode = false; bool DirectX9Test::dark_mode = true; // I have dark mode enabled, I'll leave this to true.
bool DirectX9Test::define_test = false; bool DirectX9Test::define_test = false;
bool DirectX9Test::list_values = false; bool DirectX9Test::list_values = false;
// //
// TODO Setup test for storing an array of pointers
// TODO Try to play around with PS3 homebrew or Nintendo Switch homebrew.
void MainMenu::MainMenuTest() { void MainMenu::MainMenuTest() {
ImGuiIO& io = ImGui::GetIO(); (void)io; ImGuiIO& io = ImGui::GetIO(); (void)io;
@ -58,6 +60,13 @@ void MainMenu::MainMenuTest() {
ImGui::BulletText("Hello, this should show up."); ImGui::BulletText("Hello, this should show up.");
ImGui::Separator(); ImGui::Separator();
// This works
if (ImGui::Button("Windows Msg Box"))
{
MessageBox(NULL, TEXT("Hello From ImGui, a MessageBox"),
TEXT("KCNet-ImGuiTest"), MB_OK);
}
// Menu toggle button // Menu toggle button
if (ImGui::Button("Menu toggle")) if (ImGui::Button("Menu toggle"))
{ {
@ -114,14 +123,35 @@ void MainMenu::MainMenuTest() {
// This below works for a dark mode toggle. // This below works for a dark mode toggle.
// 5-16-2024 @ 9:14PM // 5-16-2024 @ 9:14PM
/////////////
// Dark mode toggle
/////////////
#ifndef _TEST #ifndef _TEST
#define _TEST #define _TEST
#endif #endif
#ifdef _TEST #ifdef _TEST
// Well the checkbox is inverted lol, oh well I'll fix it later. if (ImGui::Checkbox("Dark Mode", &DirectX9Test::dark_mode))
// If it is checked it turns off dark mode, I guess its because I have dark mode as the default theme. {
if (DirectX9Test::dark_mode)
{
ImGui::StyleColorsDark();
ImGui::BulletText("On");
}
else
{
ImGui::StyleColorsLight();
ImGui::BulletText("Off");
}
}
ImGui::SameLine();
// Added some spacing to this
ImGui::Text(" Enabled by default for KCNet-ImGui");
#else
if (!ImGui::Checkbox("Dark Mode", &DirectX9Test::dark_mode)) if (!ImGui::Checkbox("Dark Mode", &DirectX9Test::dark_mode))
{ {
if (!DirectX9Test::dark_mode) if (!DirectX9Test::dark_mode)
@ -136,20 +166,6 @@ void MainMenu::MainMenuTest() {
ImGui::BulletText("Off"); ImGui::BulletText("Off");
} }
} }
#else
ImGui::Checkbox("Dark Mode", &dark_mode);
if (dark_mode)
{
ImGui::StyleColorsLight();
ImGui::BulletText("Off");
}
else
{
ImGui::StyleColorsDark();
ImGui::BulletText("On");
}
#endif //_TEST #endif //_TEST
// Disable preprocessor // Disable preprocessor
#undef _TEST #undef _TEST
@ -182,22 +198,13 @@ void MainMenu::MainMenuTest() {
else else
ImGui::Text("Mouse pos: <INVALID>"); ImGui::Text("Mouse pos: <INVALID>");
//if (ImGui::Checkbox("Show Text", &toggle_text))
//{
// ImGui::BulletText("Hello");
//}
//else
//{
// ImGui::BulletText("Hola");
//}
// How do I update this text in code? // How do I update this text in code?
// Like if a button is pressed. // Like if a button is pressed.
//ImGui::Separator(); //ImGui::Separator();
//ImGui::BulletText("Test"); //ImGui::BulletText("Test");
// I'm quite sure this will only work on Windows, will need tested on Linux once I get opengl working. // I'm quite sure this will only work on Windows, will need tested on Linux once I get opengl working.
// Yeah this uses WinUser.h which is windows specific
#ifdef _WIN32 #ifdef _WIN32
static bool test = false; static bool test = false;
@ -240,28 +247,32 @@ void MainMenu::MainMenuTest() {
//for (int i =0; i< keyboard_chars_enum) //for (int i =0; i< keyboard_chars_enum)
// This one didn't work // This one didn't work
//for (int i = 0; i < input; i++) { #ifdef _TEST
// if (GetKeyState(i) & 0x8000) for (int i = 0; i < input; i++) {
// ImGui::Text(i + " key was pressed"); if (GetKeyState(i) & 0x8000)
//} ImGui::Text(i + " key was pressed");
}
#else
// This works // This works
//if (GetKeyState('A') & 0x8000) if (GetKeyState('A') & 0x8000)
//{ {
// ImGui::Text("A Key pressed"); ImGui::Text("A Key pressed");
//} }
if (GetKeyState(VK_SHIFT) & 0x8000)
{
ImGui::Text("Shift Key pressed");
}
#endif //_TEST
//if (GetKeyState(VK_SHIFT) & 0x8000)
//{
// ImGui::Text("Shift Key pressed");
//}
// //
} }
else //else
{ //{
ImGui::Text("Goodbye"); // ImGui::Text("Goodbye");
} //}
#endif //_WIN32 #endif //_WIN32
@ -288,7 +299,7 @@ void MainMenu::MainMenuTest() {
//Sleep(2000); //Sleep(2000);
// This spams the console too much. // This spams the console too much.
KeyStates::test(); //KeyStates::test();
} }
else else
{ {
@ -296,6 +307,8 @@ void MainMenu::MainMenuTest() {
} }
} }
ImGui::Separator();
// This works for a column, having multiple items on the same row. // This works for a column, having multiple items on the same row.
ImGui::Columns(2); ImGui::Columns(2);
ImGui::Text("Hello"); ImGui::Text("Hello");

21
menus/pch.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
// Possibly switch over to using pre compiled headers for this project.
/*
#include "imgui.h"
#include "imgui_impl_dx9.h"
#if _WIN32
#include "imgui_impl_win32.h"
#include <Windows.h>
#include "../util/keystates.h"
#endif
#include <d3d9.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <fstream>
*/

45
menus/text_menu.cpp Normal file
View File

@ -0,0 +1,45 @@
#include "imgui.h"
#include "imgui_impl_dx9.h"
#if _WIN32
#include "imgui_impl_win32.h"
#include <Windows.h>
#include "../util/keystates.h"
#endif
#include <d3d9.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <fstream>
#include "../util/text_file_functions.h"
#include "../test/directx9_test.h"
#include "text_menu.h"
bool show_text = false;
void TextMenu::TextMainMenu() {
ImGui::BulletText("I will add reading files, writing and more to this.");
ImGui::Separator();
// I almost got this working 5-17-2024 @ 3:14PM
// It doesn't print out all of the lines from the return value.
ImGui::Checkbox("Test", &show_text);
if(show_text)
{
TextFileFunctions::printTextOutput("test.txt");
//ImGui::Text(TextFileFunctions::printTextOutput("test.txt"));
}
//if (ImGui::Button("Test"))
//{
// TextFileFunctions::printTextOutput("test.txt");
// //std::cout << TextFileFunctions::printTextOutput("test.txt") << std::endl;
//}
}

7
menus/text_menu.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
class TextMenu
{
public:
void TextMainMenu();
};

View File

@ -23,8 +23,7 @@
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp // - Introduction, links and more at the top of imgui.cpp
// ImGui
#include "imgui.h" #include "imgui.h"
#include "imgui_impl_dx9.h" #include "imgui_impl_dx9.h"
@ -33,6 +32,7 @@
#include <Windows.h> #include <Windows.h>
#include "../util/keystates.h" #include "../util/keystates.h"
#endif #endif
//
#include <d3d9.h> #include <d3d9.h>
#include <tchar.h> #include <tchar.h>
@ -41,9 +41,14 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
// Util
#include "../util/text_file_functions.h" #include "../util/text_file_functions.h"
#include "../util/text_functions.h" #include "../util/text_functions.h"
//
// Menus
#include "../menus/main_menu.h" #include "../menus/main_menu.h"
#include "../menus/text_menu.h"
//
// https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/ // https://www.geeksforgeeks.org/macros-and-its-types-in-c-cpp/
// Test macros // Test macros
@ -148,6 +153,9 @@ static void ShowWindow(bool* p_open)
void DirectX9Test::directX9Test() void DirectX9Test::directX9Test()
{ {
// Define custom booleans and features.
TextMenu *textMenu = new TextMenu();
#ifdef _TEST #ifdef _TEST
//std::cout << testString1(); //std::cout << testString1();
#endif #endif
@ -258,19 +266,12 @@ void DirectX9Test::directX9Test()
MainMenu::MainMenuTest(); MainMenu::MainMenuTest();
// Text file functions test menu // Text file functions test menu
if (ImGui::CollapsingHeader("Text File Functions")) if (ImGui::CollapsingHeader("Text File Functions"))
{ {
ImGui::BulletText("I will add reading files, writing and more to this."); textMenu->TextMainMenu();
ImGui::Separator();
// I almost got this working 5-17-2024 @ 3:14PM
// It doesn't print out all of the lines from the return value.
if (ImGui::Button("Test"))
{
TextFileFunctions::printTextOutput("test.txt");
//std::cout << TextFileFunctions::printTextOutput("test.txt") << std::endl;
}
} }
// End Text file functions test menu // End Text file functions test menu

View File

@ -60,9 +60,12 @@ void TextFileFunctions::readTextFile(std::string file)
#ifdef _TEST #ifdef _TEST
void TextFileFunctions::printTextOutput(std::string file) void TextFileFunctions::printTextOutput(std::string file)
{ {
//std::string line;
//std::string line[1000];
std::string line; std::string line;
std::ifstream myfile(file); std::ifstream myfile(file);
if (TextFileFunctions::fileExistCheck(file)) if (TextFileFunctions::fileExistCheck(file))
{ {
if (myfile.is_open()) if (myfile.is_open())