Creating Windows GUI programs with C/C++

About software development, techniques, tools, compilers, etc.
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Creating Windows GUI programs with C/C++

Post by Go4IT »

Everything starts with the "Program Entry Point". Like the entry point to a C program, where it is defined as main(), the entry point to a Windows program is called WinMain()

This is the most basic program:

Code: Select all

int WINAPI WinMain (
    HINSTANCE hInstance, 
    HINSTANCE hPrevInstance,
    PSTR szCmdLine,
    int iCmdShow)
{
    ....
}
hPrevInstance is not used anymore and was only used in legacy 16 bit, just set it to NULL.
ZvonimirG
Starter
Posts: 44
Joined: 21 Jun 2021, 17:23

Re: Creating Windows GUI programs with C/C++

Post by ZvonimirG »

Yes I setup code blocks and finished first tutorial
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Creating Windows GUI programs with C/C++

Post by Go4IT »

Was it all clear to you?
Another way is to let Codeblocks create an GUI app code by selecting "Win32 App" when creating a new project. This will generate the entrypiont function and the messageloop function and will present an empty window when run.
ZvonimirG
Starter
Posts: 44
Joined: 21 Jun 2021, 17:23

Re: Creating Windows GUI programs with C/C++

Post by ZvonimirG »

Well if we take in account that im mechanic and didn't learn to program in school it goes well :D
Go4IT
Pro
Posts: 967
Joined: 08 Feb 2019, 12:25

Re: Creating Windows GUI programs with C/C++

Post by Go4IT »

Ok, then it would be a rough ride. Some programming experience is helpfull as this course does not cover fundamentals of
C/C++ programming. How deep shoulde we go? As a mechanic you have at least technical understanding and logics, that is good!
So, assigning and using variables is a fundamental thing in every language. C++ covers most of C (like other C variantes do), and right now the object oriented behave is not relevant now. C is procedural, easier to learn.

In C variable have a name, a type and a value. When creating one you are forced to give it a type. Very simple example:

Code: Select all

int a = 1;
This declares a variable named "a" as of type "integer" and also assigns it a value of '1'.
There are serveral subtypes of numbers, like "float" for fractional numbers, "uint" for unsigned integers (can only be positive) or "sint" for signed integers (can be negative), "long" (stores biiig numbers), "ulong" and "slong" also.
You can find out how much memory used by a type using "sizeof()" function:

Code: Select all

printf("%d\n", sizeof(int));
Normaly you don't care about how numbers are stored internally, so you don't know how much memory the compiler uses for a "int". If you need to be specific you can also use basic datatypes like "byte" (1 byte), "word" (2 bytes in machine order), "dword" (4 bytes), and so on.

When it comes to strings it's more complicated. What looks easy:

Code: Select all

char s[] = "Hello World!";
need some explaination. There is no "string" type in C. Text is in fact just a series of characters, or better an array of chars. This is what the declaration "char s[]" tells. The basic type is "char", the name "s" and the brackets "[]" denotes it as an array.
Post Reply