how do I get win32 file browser with SDL? - c++

I want to create an editor in C++ using SDL & OpenGL and have decided to use the win32 api to access the window bar menus (for file, edit and so on) and it seems quite simple, but I don't know how to create a "file-> open" file browser/loader... I'm hoping it's quite simple but I'm finding it hard to look up any tutorials on google because of the phrasing...
I just want to have an "open" or "import" option in the file menu that will open a standard windows file browser... then grab the file location, place it into a string then pass it into a function that is activated by selection a file... (I hope that makes sense).
The method I'm using to create the win32 menus are from this post:
http://www.gamedev.net/topic/400677-sdl-with-a-win32-menu/
Half way down the page there is a comment by "caseyd"... that's how I learnt how to use it, so that is my current understanding of win32 menus in SDL... I wanted to post the code here, but I didn't know how to paste it here in codeblocks without reformatting every line.
I'm hoping this is quite simple... Thanks to anyone who can teach me how or just point me in the right direction.
Oh, and I'm not trying to convert this to other operating systems, I just like SDL.

Use GetOpenFileName(). Note that that function blocks until the user selects a file, so if you want to continue rendering etc. in the background, make sure to run it on a separate thread.

Related

Is it possible for a DLL to open explorer?

Im trying to make (what I thought was a simple) extension for Game maker studio 2.
I am restricted to making a DLL app.
I am wondering is there any was to have a dll app open the file explorer have the user locate a file and then return said directory?
I fell like this is a sumb question but one I really need to know the answer too before slaving away coding for hours only to find its not possible.
You do not want to launch the explorer but to open a file dialog that allows the user to select a file.
Depending on the framework you use in your program the solutions may differ.
If you are using Qt framework you may use a QFileDialog for a platform independent mechanism.
If you are okay that it will only works on Windows then you may directly use the WinAPI functions GetOpenFileName or GetSaveFileName (that is a lot easier than the Common Item Dialog that is suggested as replacement on their documentation pages)
On GameMaker terms, you want to use get_open_filename or get_open_filename_ext.
See Dialog Module (marketplace, github) for C++ implementation reference.

C++ - Making a program open itself

I have a program that opens a WAV file and then plots the waveform. If the WAV file has 2 channels, two graphs are shown, one for each channel. It's working fine but I want to add things in the File Menu that I created. So far, I have three buttons: New, Open File, and Close. So far, the Open File and the Close buttons are working fine.
I want to make the program to be able to let the user view several waveforms of several WAV Files at the same time. One option would be to create more graphs, the process would be quite tedious. Another option would be to open another window and this is what I want to do.
However, this is my problem. I made a quick search on how to open an existing program in C++, and so far, the solutions that I encounter involve opening an exe file and the project folder does not contain an exe file.
I also tried to take a quick look on the functions and I can't find the function that seems to open the window and I can't seem to find it.
Your best bet is to use fork. Alternatively you could use threads.
Use GetModuleFileName API to get the path+ name of your executable. Then Use ShellExecute to run this APP.

Multiple console windows from one Win32 console app

I've written a program based on an empty Win32 console app in VS2008 running on Win7 64bit. The program is entirely menu based spawning from a main.cpp which only calls external functions that lead to other interfaces based on the users needs (e.g. cashier, inventory, report, etc...). What I would love to do is provide a new console window for each interface.
Ideally it would close the main menu upon invoking any other interfaces and so on as the user progresses through its functions, including reopening the main menu when necessary.
The basis for doing it this way is that I'm starting a new semester next week diving deeper in OOP with C++ and I wanted to go over my text and complete the capstone project which progresses with the topics to ensure that I have all the basics down pat. As much as I would love to do this the smartest-easiest way, it's best if I stick to the limited knowledge presented in the book which only hints at STL and speaks nothing of additional libraries like boost.
I, of course, have searched on SO and elsewhere looking for the solution. I have found answers, most of them falling outside of my tight requirements, some dealing with building a console window from scratch. While from-scratch seems the most promising, it seemed to be dealing with those not using a robust IDE like VS and I don't know if it will cause more conflict than it's worth, or if it can even be used in multiplicity. The majority, however, left me with the impression it isn't possible. The one exception to this was linking a console to a process. This is what I hope is in my future!
What brought me to this was the need to present a clean look at each turn of events. At first I was fooling around with trying to clear the screen with a basic function like void clearScreen(int lines); but this will always clear from the bottom. So, if I clear the screen before the next interface it's still at the bottom. If I clear it then accept input, the prompt is still at the bottom.
In case it hasn't been clear up to this point. My question is:
Is it possible, within reason, to produce multiple console windows which are tied to processes, or is there an easy way which I do not know to manipulate the scrolling of the main console window?
Even though I "need" to stay within the confines of the baby-step process of traditional learning, I would love to hear any input aside from switching the app type.
This is more of an OCD issue than a requirement of the task, so if the effort isn't worth the benefit that's okay too.
There is no portable way of moving the cursor around the console window - in Unix/Linux, you can send terminal codes for that, in Windows I have no idea.
What would work cross-platform, but be terribly slow and not too nice, would be:
read your input character-by-character
remember where on the screen the next character should appear
redraw the whole screen after each key press
If you want to do better, you must turn to platform-specific solutions, or find a library which would do it for you (like ncurses in the Unix world), but I don't know if any of these fit in your requirements.
You can set the cursor-position on Windows using SetConsoleCursorPosition.
Since you were saying something about VS, I assume restricting yourself to Windows isn't a problem. If so, you can use the Windows API for this.
Other than that, ncurses seems to be at least partially ported to most common platforms.
If you were looking for a way to do this in standard C++ - it doesn't exist. C++ doesn't require the platform it's running on to even have a console, so there are no console manipulation functions.
Both aren't that hard to use, but if this is really just some student thingy where you expect to learn something useful you probably shouldn't bother. Console manipulation isn't something you'll have or want to do very often.
Although it may not have been clear in my original question, I was looking for a solution to be used in a console window. Ideally the solution would have been operable on at least Linux and Windows because any programs I write for school must be compiled on each. This wasn't an assignment but it's obviously advantageous to learn things that are usable there as well.
Here's what I found ...Solution thanks to Tim Wei
void clearScreen()
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
This, as simple as it is, was exactly what I was looking for. The function clears the screen and puts the cursor at the top of the console window providing a way to provide static headers or titles with changing data tables. It also allows for simple text based animations - if you like that sort of thing. It made a significant difference in the look, feel and consistency in my console applications this semester!

Need guidance in non C/C++ based graphics interface

I have prepared a program launcher in C++ (the only language I know), which accepts strings as program trigger.
But however hard I try I'm unable to give it a GUI like look; using graphics.h's graph functions creates graphics but in cmd like window.
All I need is a small widget/window like thing that sits on the desktop where a user can type the command string (and error messages can be displayed as usual).
Can I get a code snippet for such a widget/window?
The input string may be copied to a .txt file and my prog will read it from there.
P.S.- I'm a beginner & rookie so please avoid complex alternatives.
Well, one of the easiest options in my opinion is to use .NET Framework:
http://10rem.net/blog/2010/03/04/my-first-windows-cplusplus-application-in-ages-hello-world-in-win32-with-visual-cplusplus-2010
http://msdn.microsoft.com/en-us/library/bb384845.aspx

Ahk script and C++ communication

I wish to use the functions of autohotkey within a C++ program.
I am currently running my scripts triggered by the c++ program- I just run them as a .bat file. This works well but the problem is that I cannot return values from the script to the c++ program.
I wish to be able to read the position of the mouse from the script and make decisions based upon this in my C++ program. My scripts do quite complex things- so doing this in autohotkey is the best solution for me- I have knowledge of C, but little of C++.
I have read about the Autohotkey .DLL - I know how to trigger it but not how to read values from it. If anyone could instruct me or even post example code of a .dll being loaded and a value sent to a script and a value returned- I would be eternally grateful!!
I have spent hours on this and to no avail!
to return a value, could this possibly work http://www.autohotkey.net/~tinku99/ahkdll/functions/ahkgetvar.htm
I'm not sure about the dll, but you could just write your own application in Autohotkey and package it along with your C++.
The communication takes place over a hidden window with an edit control and a button. You use one application to set text in the edit box, and then to click the submit button. The other application owns the window can process whatever is put into the edit control - as if you were passing a variable. Basically, that's it.
Check out this thread where I've explained it in more detail: How to send a command to a running application via commandline
Now, that's not quite what you wanted, but the effect is the same, and you already know all the api.