Author Topic: Start coding first tool with Visual Studio (using Win32 API)  (Read 7626 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Hi guys!
I will start to code my first simple app/tool using Visual Studio (atm 2008 version installed) and Win32 API, no MFC!
Do you know a good place / tutorial how to start as newbie step by step using Visual Studio and Win32 for creating a first small app/tool (GUI)? I know there are two ways to create GUIs... resource files (like for MenuBar) and just create gadgets (windows) at runtime inside the code without resource files.

Atm i am not really sure what kind is better and has its benefits! I think there are no real differences, isnt it? Just that resource files in an executeable can be modified easy by any resourcehacker.

However, some generall things i would like/try to code in my first app are:  MenuBar, ToolBar, Directory ListView, StatusBar, multiply windows and so on... also just some generall GUI objects! If you have any good resource website / tutorial for me, it would be really nice!

Something i need to check/learn when coding C/CPP... from basic coding i did all the code and functions in just one big file! How do i have to split my programm in multiply files? Does it makes more sence to code stuff procedural or to have each part in its own class (OOP)? Where are the benefits, differences and so on?

First i will just try to create/open an empty Win32 window... next with menubar, toolbar and so on ^^
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Btw, some ppl told me, i should start coding C#... Afaik C# is using the Win32 API layer and something like a wrapper... and afaik (or just heard in the past) C# is in some situations extremly slow... The question is, does it makes more sence to code appz/tools using C# and beeing portable or using directly Win32 API to have biggest control / flexibility and even amazing speed without beeing portable? I am not really sure... personally i think Win32 API will never die and ever present as the layer, where C# is based on. What do you think?
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
Hi I'm starting to code in C++ this year and i've found it a lot easier because i already have a prior knowlegd of C# and there is (syntacticly) a lot of similarities between C# and C++ with the added bonus that C# "looks after" you more than C++ and so its easier as a language to learn because it makes checks to make sure youve not done anything silly. this is good because when you then come to learn C++ you will not make those mistakes.

as far as speed goes my lecturer describes it like this C# is like a family car: its reliable and gets the job done, C++ is like an F1 car it gets the job done at break neck speed but if you make a mistake it will kill you. also i would like to point out that C# is slower than C++ but it is by no means extreemly slow.

Dont know how helpfull this all has been but i hope it helps.

James
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Va!n - whether you use C# or C++, the dialog editor in VS is way easier than trying to code them inline.  Forget about people hacking the resource file - who cares about that?

C# is great for Windows applications.  It can be slow for intensive number crunching, but not necessarily that slow.  It's always possible to mix them and write C++ code for the fast bits while using C# for everything else.  The .NET library is vast and comprehensive.  Of course, you can use it from managed C++, VB too, but C# is nicer.

You really need to switch to an OO style.  Even if you don't use any of the advanced features of OO, you should still break your program up into files which contain the major concepts.  e.g. screen manager, sprite, font, sound, IO, file manager, etc.  It will help clean up your thinking and tidy up the interfaces between the parts.  That will naturally lead you in to writing OO.

Jim
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
If you want to create serious applications and care about portability I recommend to stay with C++ and use a platform-independent toolkit like Qt or wxWidgets.
Prior to that:
You really need to switch to an OO style.
Challenge Trophies Won:

Offline JL235

  • C= 64
  • **
  • Posts: 71
  • Karma: 9
    • View Profile
    • Play My Code
Something i need to check/learn when coding C/CPP... from basic coding i did all the code and functions in just one big file! How do i have to split my programm in multiply files? Does it makes more sence to code stuff procedural or to have each part in its own class (OOP)? Where are the benefits, differences and so on?
When breaking your code up into files in an OO style this is trivial to answer, just put each class into it's own file. The questions becomes what goes into each class? and how do you chose between adding functionality via tacking it onto an existing class or by creating an entirely new class? Typically this just takes experience, but as general tips: always aim to build your code as a library rather then an app (to encourage code reuse), try to ensure each class only aims to solve one task (keeping the code simple makes it easier to maintain) and never be scared of creating classes (this helps you to keep classes only concentrating on solving one task).

This is all based on my personal experience, but for procedural vs object-oriented; procedural is simpler and easier whilst object-oriented gives your more power and flexibility. Typically examples of object-oriented code take up more lines then their procedural counterparts, but this is because those examples are often only a couple of hundred or a thousand lines long. Once you get over 5,000 lines (which is pretty small project) I find object-oriented code really starts to scale a lot better then procedural code where it will take up less lines of code (increasing your productivity) and less duplicate lines of code (which lowers code drift).

But for both your code is only clean and well designed if it's clean and well designed. You can write terrible code with both paradigms.

For a small one off task I tend to write my code procedurally in one giant class. For my main projects I try to build them as a library of classes with a very small app on the side that uses them. This is all easier said then done.
Play My Code - build games in your browser!

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
As far as I know and experienced I would give C# a try first.
I am not really an expert in C++/C# - but for me it seems to
be easier than C++. I would keep in mind what Hellfire says -
that even with the existance of Mono C# is not really platform
independent.

Maybe an alternative would also be Java.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
as the others said with C# there will always be portability issues (microsoft really dont like sharing) but as a language to learn its very freindly.

as far as OO goes visual studio is very good for this its as simple as clicking on your solution and adding a new class and the Ide will add a new class for you(if you do this in C++ it creates the class and the header file). for creating classes i find it usefull to write down what the program does in words and then read through it, the nouns represent classes and the verbs will represent methods eg a simple bank has accounts, members etc and these represent classes within the system.

Quote
Typically examples of object-oriented code take up more lines then their procedural counterparts, but this is because those examples are often only a couple of hundred or a thousand lines long. Once you get over 5,000 lines (which is pretty small project) I find object-oriented code really starts to scale a lot better then procedural code

I generally find this to be true as well. I have a freind on my course who almost always programs procedurally and on the smaller prodjects he's always got less lines of code but when it comes to the bigger stuff OO always gives me less code due to the fact that OO makes it alittle more work to do things once but then much easier to keep using them.

James
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline James_wright_1990

  • C= 64
  • **
  • Posts: 48
  • Karma: 4
    • View Profile
if you still need tutorials this http://www.robmiles.com/c-yellow-book/Rob%20Miles%20CSharp%20Yellow%20Book%202009.pdf is the book i used to learn c# its a little basic at the begging and geared towards windows forms but i still find it a good reasorce for general C# knowledg (it's written by my lecturer and meant for people with no prior prograsmming knowledg so thats why it starts out basic but stillwell worth a look) as far as C++ goes Idont realy know of that many tutorials i just hit the msdn site (or there's google which is the fountain of knowledg) and post quetstions here if i get really stuck.

James

edit(just realised that the link doent work as a link you have to right click on it and save it to your computer to use it sorry dont know why)
« Last Edit: December 20, 2009 by James_wright_1990 »
"if debugging is the proccess of removing bugs from software then that means that programming must be the proccess of putting them in" my favourite programming quote.

Offline JL235

  • C= 64
  • **
  • Posts: 71
  • Karma: 9
    • View Profile
    • Play My Code
I would adsive looking for tutorials on object-orientation as well as those on C# and C++. I've seen plenty of tutorials that give the presumption that just using classes and calling methods makes your code object-oriented. It doesn't. Your overall design does this.
Play My Code - build games in your browser!

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Okay, thanks for all the infos guys! I think i will start with C# for apps/tool coding. Btw, when coding c# console, what keyword must be used, to wait for hitting a key, before program ends? ^^ thx
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
That's not normally how it works.  With C# you will get a Form which will trigger events, such as window close, mouse click, key pressed etc...
You have to realise you are not in control.  Actually, you have to realise you don't *want* to be in control of this shit, the OS is the best person to handle IO.
It's possible to write console C# programs, if that's really what you want to do, but it rarely is.  Is it what you want?

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
@Jim:
No no! Its not what i want! I want code ofcourse WinForms appz! But for testing and starting my first steps in C#, i would like to see the result in the console without directly exit the program... So i want something like "WaitKeyPressed()", so i can read the result and press then any key to close the console app showing me the result(s).

I have played a bit with Visual Designer C#... Seems to be very nice and easy... Have just to check how to to check the Menu events ^^ I will take a closer look to some basics over xmas days when i dont must work ;)
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
You don't need the console to do that.  If you're running your program in the VS debugger, you just need to use
Code: [Select]
Debug.WriteLine("hey, I never knew about this!");
And then you can forget about console, it comes out in the Output window in the IDE.

Jim
Challenge Trophies Won:

Offline JL235

  • C= 64
  • **
  • Posts: 71
  • Karma: 9
    • View Profile
    • Play My Code
There are no keywords in C# for creating side-effects (interactions with outside of the program), it's all done through libraries. In basic languages it's common to have these functions in-built, making it a part of the language. I think this is a misconception your making with C#. The vast majority of languages add functions through external modules and libraries (although in some languages libraries might be included by default).

One way to wait for the user to input is through the Console.readLine method. You can use Console.writeLine for outputting text followed by an end of line character, and Console.readline to wait and read in a line of text the user has inputted. i.e.

Code: [Select]
Console.writeLine("press enter to quit");
Console.readLine();
Note that's untested code, but the MSDN is your friend. It has all the info you need for libraries, once you get used to it.
Play My Code - build games in your browser!