Page 1 of 2
Creating Windows GUI programs with C/C++
Posted: 13 Feb 2023, 11:12
by Go4IT
Anyone interested in learning how to create programs runnable in Windows?
I know there are so many ways to do this, using different languages, different tools, requiring different skills. Me personally like to do it in C++, an object oriented version of C, as i think this is most common in Windows environments. It can also be done without paying for development tools using Opensource software.
As one of my first projects i will try to create a tool to communicate with the CAN-Bus using a widespread ELM327 interface, but that should not be important.
I found this tutorial series on Youtube:
https://www.youtube.com/watch?v=8GCvZs55mEM
which i try to follow and would be glad to share my experiences.
All starts with setting up the development environment. As suggested in the video i use "Code::Blocks" IDE and MinGW as compiler. You can download it all here
http://www.codeblocks.org/downloads/binaries/
and i suggest to use the combined package with MinGW included (codeblocks-XX.YYmingw-setup.exe).
Here i found some hints on how to do the setup and configuration
https://www.geeksforgeeks.org/how-to-in ... n-windows/
Besides of this i only need to set the toolchain-directory im the compiler settings of codeblocks-IDE by clicking "Auto-Detect" and it all worked.
I was able to build the first "Hello World" example and also the following more advanced window-example as told in the video. The video also explains, but not in too deep, some fundamental concepts of building apps for Windows.
Re: Creating Windows GUI programs with C/C++
Posted: 13 Feb 2023, 13:00
by ZvonimirG
I would like to learn that
![😁](//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f601.svg)
Re: Creating Windows GUI programs with C/C++
Posted: 14 Feb 2023, 20:01
by Go4IT
Well, i've finished the first lesson
https://www.youtube.com/watch?v=8GCvZs55mEM
It is about the fundamentals of creating a window application.
You learn how to create a main window with it's width and height, a cursor to use, background color and name.
You will also learn about message queues, dispatching and processing signals like clicks.
After that lesson you are able to create an empty window. Not much, but a start!
Re: Creating Windows GUI programs with C/C++
Posted: 14 Feb 2023, 20:05
by Go4IT
In the second lesson
https://www.youtube.com/watch?v=7K6HCeog09c you learn how to add and handle menus.
Menus are stacked in an hyrarchie, so a menu-item like "Exit" is created and added to an main menu item like "File", which itself is attached to the window. Handlers are used for this.
I've attached my first compiled program and be curious if you can execute it. It does not do much but create a small window with some stub menus in it.
Re: Creating Windows GUI programs with C/C++
Posted: 15 Feb 2023, 20:17
by ZvonimirG
This is what I got when run app
gotitapp.jpg
Re: Creating Windows GUI programs with C/C++
Posted: 16 Feb 2023, 21:51
by Go4IT
Thx for testing. No Window at all, only the debug-console window? Strange...
Would you try again? I've done a static build (means all libs included) and also build as "debug".
Re: Creating Windows GUI programs with C/C++
Posted: 17 Feb 2023, 08:58
by DGAlexandru
Regarding ELM327 and CAN you can have a look here:
https://github.com/bigunclemax/FocusIPCCtrl
I've built two unstable tools for IPC bench test starting from this source code - and posted the binaries are on this forum - Focus 3 and Convers+
I've first ported it to QT "IDE", but it's in C++ so you can have a try with it.
Re: Creating Windows GUI programs with C/C++
Posted: 17 Feb 2023, 20:10
by ZvonimirG
Go4IT wrote: ↑16 Feb 2023, 21:51
Thx for testing. No Window at all, only the debug-console window? Strange...
Would you try again? I've done a static build (means all libs included) and also build as "debug".
now is working.
I got window where i can press interface in file menu and then in console show all serrial interfaces on pc
Re: Creating Windows GUI programs with C/C++
Posted: 19 Feb 2023, 15:18
by Go4IT
ZvonimirG wrote: ↑17 Feb 2023, 20:10
now is working. I got window where i can press interface in file menu and then in console show all serrial interfaces on pc
Thanks for testing! I've learned two things now:
Static linking of libraries
Whenever you include something with #include <....h> you refer to the header-files (this is what .h denotes at the end) of a library. A library is usally a seperate file. When you create and EXE later on, it usually refers to this library in a "dynamic" way. The library get's loaded on runtime. This safes memory and filesize of the EXE you build. But the libs need to exist on the machine executing the program. Sometimes it's smarter to not rely on this, as on machines not having the desired lib, the program does not start. So you can instruct Code:blocks to include the library itself (their binary) into the resulting program EXE. This makes it independant of the existance of the lib on the target host. It also ensures that the version of the library you had at development is the one on the target host.
The compiler is the one who decides wheather or not the library is statically linked (included) or not (dynamically linked). You can set the compiler options for this in the "Project" menu using "Project build options":
19-02-_2023_16-11-47.png
(I choosed all thre static linking options, maybe less would do, but i want to be shure)
Build for the right target
In the video tutorial the guy tells to choose "Console Application" when creating the example programs. He said that it don't matter. This is only half the truth. When creating a console app, the resulting EXE will always start a console shell to run, like for a commandline tool. This is the black window that opens. It then starts the final program which itself created a window based app which starts also. This console window has also some good use, as one could simply printf() debug messages in the program that will be shown up in the console window.
You can choose "GUI Application" when creating a project:
17-02-_2023_23-41-38.png
or change the App type later:
17-02-_2023_23-39-09.png
17-02-_2023_08-04-43.png
17-02-_2023_08-05-17.png
Re: Creating Windows GUI programs with C/C++
Posted: 19 Feb 2023, 15:23
by Go4IT
I also learned another thing: It's hard to choose the "right" toolset or libs. It seems there are a zillion possibilities to create visual apps having a window navigation:
Win32 API seems to be the basic way of doing it.
But there are also Libs/Frameworks like QT, GTK+, wxWidget, etc.
Also for serial communication, there are a lot of different way doing the same thing.
I've tried to simply enumerate all current serial devices on the PC, but that is not as easy as it sounds. I tried a lot of libs and methods, but not all of them work well.
But first, let's get back to the tutorial. @ZvonimirG did you manage to setup a development environment? And maybe walk through the first two lessons?
Somebody on Stackoverflow suggested "Windows Programming 5th Edition", which is pretty findable on the web:
https://vulms.vu.edu.pk/Courses/CS410/D ... h%20Ed.pdf