How to create GUI programs with Code::Blocks - c++

Previously I used Visual Studio for my C++ programmings. But some cost effects I had to change my IDE, so I chose Code::Clocks (12.11). But I can't find a way to develop GUI applications with C::B. Is there any way to develop GUIs with C::B?

Yes, You can develop GUIs with CodeBlocks if you have GTK+ or wxWidget Libraries. You can use one of them at your own choice. CodeBlocks can't use them until you download and install them, So you have to perform some actions to make them usable in CodeBlocks. For GTK+ configuration steps see this and for wxWidget see this.

I create Win32 gui apps all the time with Code::Blocks 20.3 (uses MinGW-W64 project compiler) because I code them using the Win32 api. This is the manual way of doing things, and it works great; the down-side is that you must learn the Win32 api. (its an aspiring challenge, but for an experienced C/C++ programmer and some google skills, its doable)
Many programmers believe that gui apps must be built with a graphical builder (GTK+, wxWidgets, etc) but not true. In fact, in the stock version of the 20.3 Code::Blocks one of the project options is Win32 app. It builds a 'very' minimal cpp file that displays a blank window and starts the message loop... this is a good place to start if you've never seen a gui cpp text file that produces a blank window. You will need to study the Win32 api and learn how to use the message loop, how to add controls (buttons etc) to your project, and how to debug it; its a learning curve, but it is rewarding education. Get the book, "Programming Windows" fifth edition--- make sure its the fifth edition only!
The Microsoft docs are pretty good for learning the Win32 api also, but the book is the best approach. Take a class.
marcus

If you want to start creating GUI programs with 'Code::Blocks' then using a 'Win32' approach looks promising.
I only recently installed 'Code::Blocks 20.03', using the defaults for the install directory, and type of installation( Full ), and was easily able to create a basic 'Win32 GUI project'.
NB: I was using Windows 10, and the basic project doesn't really do anything.
For some Microsoft documentation, see at
https://learn.microsoft.com/en-us/windows/win32/learnwin32/learn-to-program-for-windows
, please note at the bottom left of this page, a 'Download PDF' link.
You could start at page 18 of the pdf, which is where, 'Module 1. Your First Windows Program', starts, page 20 is illuminating.
For information on 'The Message Loop', mentioned in a previous answer, see page 24.
It might be worth bearing in mind 'Reply #3' to the question at
https://forums.codeblocks.org/index.php?topic=19537.0

Related

embedding .exe applications on a QT form

I wanted to know if its possible to embed other .exe applications on a QT form.
Say i have an app called foo.exe. Now I want to lauch foo.exe through my application. I know I could do that using QProcess::startDetached() however I would like that program to run within my form.Is that possible ?
Believe what you want is a kind of "EMBED", there seems to be something done, but I can direct you to a few ways:
Cygwin
In X Window System we have o "X-Embed"
For Windows exists Cygwin/X (apparently to run "multi-threaded" in "google chrome" uses cygwin).
QT X11 Systems: http://qt-project.org/doc/qt-4.8/qvfb.html
Nice example: http://arstechnica.com/information-technology/2009/03/experimental-process-per-tab-browser-created-with-qt-xembed/ (outdated)
ActiveX
You can create Activex Controls, see example: http://qt-project.org/doc/qt-4.8/activeqt-server.html
In two suggestions that you spent the programs you want to add to your main program should be created by you, in other words, programs that are not compiled with "Cygwin" or is not an "ActiveX" (QT you can add controls ActiveX, such as Internet Explorer or MSExcel).
Believe both examples programs work as "servers" and its main program as a "client", in other words, other processes need not necessarily one graphical interface, I believe the main software is who works the GUI part.
For this reason the programs should be "embedded" created with the purpose of "embedding"
Alternative solution (DotNet and user32.dll)
See article:
http://www.codeproject.com/Articles/9123/Hosting-EXE-Applications-in-a-WinForm-project

How to write a IE BHO in Plain C++ which executes my javascript

According to my client's demand, I am aiming to write a Internet Explorer BHO which on button click executes my custom Javascript. I have started with this link which contains an example BHO which is inplemented in C++,
http://www.codeproject.com/Articles/37044/Writing-a-BHO-in-Plain-C
But when I try to run it in Visual C++ 2010 Express, it doesnot build. I have these question regarding IE BHO:-
1) On which platform can I build and make changes to the above example code , in VC++ 2010 or Windows 7 SDK?
2) Any other tutorial you can refer me; which can guide me how to make BHO in C++ ?
3) I intend to make a button while using IE BHO, such that whenever it is clicked, my custom javascript is executed. Can anybody give me a general guidance on how to do this?
I have searched alot about this matter on Internet, but it seems that majority of the people are implementing BHO in C#. I am in need of some good suggestions.
First question: You should not ask a question saying "it does not build" and saying nothing about your build problem. Do you want us to download the project and guess what is Ok and what is not depending on VS and OS versions? Update your question with your build problem.
Second question: Use Google: Building Browser Helper Objects with Visual Studio 2005 It's old now, but nothing has really changed since then. Alas, you must have an ATL capable version of VS, and the Express versions are not. Anyway,I very strongly discourage writing a C++ BHO without the help of ATL. You may get the ATL sources by downloading a recent SDK, but you will not have the wizards. If you have a "full" VS2008, it will do the job perfectly well.
Third question: general guidance is the IHTMLWindow2 execScript method

Microsoft Visual cannot add tools

I´m new at Visual Studio C++ and maybe I´m asking a very trivial question. I have a project/application but I have to add a few new features to it. When I open the project in MVS and in "dialog" folder there are windows (or dialogs?) used by application and I can modify them but I´m not allowed to add components/tools that I really need. I have only Dialog editor tools unlocked. I can compile an run application but When I try to add a form to project I´ll see a message:
You are adding a CLR component to a native project. Your project will be converted to have Common language runtime support.
I´ve googled some information about .NET forms and windows dialogs, but I do not know what to do next. If I choose "yes" (convert project) I cannot compile it anymore.
What can I do if I would like to use a ZedGraph controll to plot graphs from data in this app?
The C# GUI tools are different to the C++ tools (like MFC).
When you try to add C# tools to a C++ project the IDE warns you "You are adding a CLR component..."
Depending on which IDE you are using, when you bring up the resource view (http://msdn.microsoft.com/en-us/library/d4cfawwc.aspx) e.g. with ctrl + shift + E you should be able to find the existing dialogs and double click to edit them.
It seems that ZedGraph is a C# library (from the docs), so you will have to convert into a C# project in order to use it, which will not be straightforward, or use a suitable C++ one.

Windows Phone: Log to console

Disclaimer: I'm quite new to the MSFT tech world and only started Windows Phone development a month or so ago.
I am unable to figure out how to log information to the Visual Studio Output window from within a C# and C++ (Direct3D) Windows Phone 8 App. Is this possible?
I am building in debug mode, targeting Windows Phone 8, running in the XDE emulator and my development machine is a Windows 8 box with VS2012 Ultimate installed. My App runs fine, my Direct3D scene renders normally, but I can't log anything! This makes tracing code execution difficult and forces me to use breakpoints (which can be overkill in many situations).
I've been searching far and wide and have tried many methods (OutputDebugString being one of them). I can't see anything on MSDN about this - why is this not documented anywhere?
Yep, it's possible to write debug strings from WP8 C++ to the output window in VS2012. I actually have an example of that here.
1) Invoke OutputDebugString from C++.
void Direct3DInterop::MyButtonWasClicked()
{
OutputDebugString(L"Button was clicked!");
}
2) Before running the app make sure to change to the native debugger from the managed debugger in the project's properties.
I believe the methods in System.Diagnostics.Debug (specifically the overloads of WriteLine()) work...although I haven't tried them with C++ apps.

Visual Studio Questions/C++

I'm a hobbyist developer and have a background with Java (IDE of choice was Eclipse). I'm using Visual Studio Express 2010 and wanting to learn C++.
Few questions:
I create a "HelloWorld" in C++ and compiles/runs in VS/Windows. When I try to compile it under Linux/GCC, it obviously throws tons of errors. Default windows console project includes windows specific files; but if just create an "Empty Project" it throws tons of linker/build errors. What's the best practices here to keep my code portable?
Why is it creating 47 files for 8 lines of code?
How do you format code? You can do Edit->Format Selection, but the hotkeys don't work?
How do I output to VS's 'Output' Window? ( like eclipse does when you run a console java app )
It keeps reverting my "Project Location" to my "home directory" every time I restart. How do you change it? Is it a bug? Because it's Express edition?
Is there a way to keep it from switching to Debug view when it runs?
I create a "HelloWorld" in C++ and
compiles/runs in VS/Windows. When I
try to compile it under Linux/GCC, it
obviously throws tons of errors.
Default windows console project
includes windows specific files; but
if just create an "Empty Project" it
throws tons of linker/build errors.
What's the best practices here to keep
my code portable?
For portable code, avoid VS wizards entirely. Use Make/NMake if you're starting with rocks and sticks, or the portable build system of your preference (Ant, CMake, etc.) Some of these will spit out a VS solution/project file for you to use.
Why is it creating 47 files for 8
lines of code?
Wizards are magical like that.
How do you format code? You can do
Edit->Format Selection, but the
hotkeys don't work?
Ctrl-K Ctrl-F (under Edit, Advanced)
How do I output to VS's 'Output'
Window? ( like eclipse does when you
run a console java app )
Lookup OutputDebugString() for the debug window. Output window should get all cout/cerr output.
It keeps reverting my "Project
Location" to my "home directory" every
time I restart. How do you change it?
Is it a bug? Because it's Express
edition?
Probably hidden in options somewhere - don't know that one, sorry.
Is there a way to keep it from
switching to Debug view when it runs?
Launch using Ctrl+F5 to run without the debugger attached.
Have fun!
I create a "HelloWorld" in C++ and compiles/runs in VS/Windows. When I try to compile it under Linux/GCC, it obviously throws tons of errors. Default windows console project includes windows specific files; but if just create an "Empty Project" it throws tons of linker/build errors. What's the best practices here to keep my code portable?
It's fairly difficult to keep your code truly portable if you're writing Windows applications. Standard C++ will obviously work on either platform, but Linux can't run Windows applications, and vice versa. Remember that console applications are also considered Windows applications. They're not any more "pure" just because they are text-based, rather than graphical. Windows applications have their own entry point, different from the standard main function found in ANSI C++ (technically, main is still there, but it's hidden and called internally by the Windows libraries).
The best thing to do is not to link to any of the Windows headers. Unfortunately, you won't be very satisfied with the results. About all that you'll be able to generate is library code. You can't get a UI on the screen unless you use the Windows functions to do it.
An "Empty Project" is just what it says—empty. I assume the build errors are because you're trying to call functions that aren't defined anywhere. You'll find that you need to include windows.h to get off the ground, which instantly makes your code non-portable.
Why is it creating 47 files for 8 lines of code?
This is obviously an exaggeration; none of the wizards produce anywhere near that many code files. Especially not the "Empty Project", which doesn't create any at all.
A Win32 console application includes the following 5 files:
stdafx.h and stdafx.cpp — these files are used to enable "precompiled headers", meaning that Visual Studio will compile all of your headers once, and only recompile them when they change, rather than recompiling them each time you build the project. This used to provide enormous speed boosts, and still does on large projects. You probably don't need or care about this for small projects, but it's not a bad idea to get familiar with their usage if you're going to be developing in Visual Studio.
A targetver.h file, whose only purpose is to specify the earliest version of Windows that you want your application to run on. This is necessary because later versions of Windows add additional functionality that wasn't available in previous versions. Your app won't run if you link to functions or libraries that don't exist. Set this up once and then forget about it.
A <projectname>.cpp file, which is the implementation code for your application. This is pretty standard stuff—it includes the _tmain function, which is the entry point for a console app.
A ReadMe.txt file, which you can immediately delete. It contains some introductory information and describes the files that have been added to your project. (Yes, reading this yourself could have answered this question.)
A Win32 application would have a few more files, but most of the same ones as well. In particular, you'll see a resource file (with the extension .rc) that contains the icons, dialogs, bitmaps, cursors, etc. used in your program.
If you don't like this structure, you can either forgo the use of a wizard, or modify it yourself. There's nothing set in stone about it.
How do you format code? You can do Edit->Format Selection, but the hotkeys don't work?
Formatting code works fine. I'm not sure why people are telling you that Visual Studio doesn't support this, or that you'll need a third-party plug-in. There's no "Format Document" command as there is in C#, but the "Format Selection" command works just fine. The only difference is, you have to select something in order for it to be enabled.
The default keyboard extension for that command is CtrlK, Ctrl+F. It also works fine, right out of the box. My typical workflow is to hit Ctrl+A first to select all.
How do I output to VS's 'Output' Window? ( like eclipse does when you run a console java app )
I don't know what Eclipse does, nor do I know anything about Java. What do you want this to do? When and what things do you want to get written to the "Output" window? A console application will run in a console window, not in the "Output" window. That's not what it's for.
It's intended for debugging purposes. The OutputDebugString function is one way of utilizing it. The output of the standard cerr keyword should be automatically redirected to the "Output" window.
It keeps reverting my "Project Location" to my "home directory" every time I restart. How do you change it? Is it a bug? Because it's Express edition?
This isn't a bug, it's a feature. Visual Studio is designed for working with projects and solutions, not one-off code files. So by default, it prompts you to specify a project folder, a location to store your files. And what better place for the default location than your home folder?
If you don't like that location, you can change it. Under the "Tools" menu, select "Options". Expand the "Projects and Solutions" category, and click the "General" item. Then, change the path of the "Projects location" (the top textbox). Couldn't get much simpler than that.
Is there a way to keep it from switching to Debug view when it runs?
I frankly don't understand how this question makes any sense at all. When you run an application with the debugger attached, Visual Studio switches to a different window layout specifically optimized for debugging. I just answered a similar question. The upshot is that there's no way of telling Visual Studio to use the same window layout for both design and debug view, but I also can't imagine why you'd want to, either. Different things are useful, depending on what you're currently doing.
The two window layouts are customizable, and your changes are remembered. I've customized mine heavily from the defaults; it's very likely that your tastes vary as well. There are lots of great features, like the "Locals" window, which shows a listing of all the values of the local variables in scope at the point where you break into your program's execution.
Also remember that the default "Debug" and "Release" build configurations have nothing to do with whether or not Visual Studio automatically attaches the debugger to your application's process. If you want to start your app without the debugger attached, select "Start without Debugging" from the Debug menu, or press Ctrl+F5. There are lots of side effects to this though, and it's probably not what you wanted. Without the debugger attached, you lose most of what Visual Studio provides to you as an IDE. You might as well just run the app from Windows Explorer without even launching VS.
Finally, if you prefer Eclipse (or at least are already accustomed to its nuances and prefer not to learn Visual Studio's), you can still use it for C++ development. Download it here.
If you're just wanting to learn C++ and you don't necessarily care about the platform, I would probably avoid using Visual Studio to start with. Visual Studio provides some functionality for managing projects and builds, but honestly, I think you're better off learning how to manage code files and use the compiler on the command line first, then working up from there.
If you're on Windows, I'd recommend installing Cygwin and getting the GNU compiler tools through the Cygwin setup utility (gcc or g++).
This is a bit of an opinionated answer, but my experience with C++ on Windows leads me to believe that you'd be better served trying to learn C++ from more of a unix-like angle. Windows C++ adds a whole layer of crap that will just confuse you when you're getting started.