Author Topic: Some questions to app coding using Win32 API  (Read 4257 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
hi guys!
Since i am trying to start coding my frist Win32 API based GUI app with VS, i have some generall questions to the Win32 GUI experts here!

Creating/Using Menus:
There are two ways to create/use normal and popup menus. One way is to create and use a *.rc (resource) file to define the menu... and the other way i know and personally me prefer, is to code it directly using Appendmenu() and other API calls... One benefit of directly coding the menu using API calls may be, that nobody can easy use a ResourceHacker and modify the Menus or other resources like GUI and so on...

Creating/Using GUI:
For creating/using GUIs, there are the same methods like for the menus. Using resource files or creating directly with pure Win32 API... as i said for the menu stuff before, i dont really like the way that ppl can modify the content with a resource editor.

So my question to the experts here, what way do you prefer to use and why? Is there something i miss or should know about using resources and coding stuff directly?

Handling GUIs:
When having an app, where the GUI is directly coded by hand (also no resource file), there are two or three API ways to access the created buttons (windows)... This confused me a little bit... in the past i used stuff like SetWindowText() and never used the *Dlg* commands like SetDlgItemText() ...

Code: [Select]
SetWindowText()   vs   SetDlgItemText()     vs i.e.    SendMessage()

So whats the best way to use when you can do the same stuff with this two/three API functions? Something i have/should know?

Generall:
I found on the web and in some books i looked two different version how people write stuff... upper/lower case... is there any standard ppl should use like for handles:

Code: [Select]
HWND hWnd     // personally i would prefer this version...
HWND hwnd

   

- 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
Re: Some questions to app coding using Win32 API
« Reply #1 on: January 21, 2009 »
I wouldn't care about people hacking my resource files.  Not much to be learned or gained by doing so, except maybe pinching an icon.  With anything but the tiniest GUI I would use the resource editor built in to visual studio to do it all visually.

SetWindowText, SetDlgItemText, SendMessage - those 3 API calls do pretty much the same thing.  SendMessage can do a lot more than change text though.

The variable naming (hWnd/hwnd etc) is called Hungarian Notation.  Microsoft use it everywhere and if you're writing Windows API code you might benefit from following the same style.  I don't usually do that, though.

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Some questions to app coding using Win32 API
« Reply #2 on: January 21, 2009 »
Quote
SetWindowText, SetDlgItemText, SendMessage - those 3 API calls do pretty much the same thing.  SendMessage can do a lot more than change text though.

yes, i know all this 3 api calls can be used for doing the same thing. but is there any reason to use a, b or c? So are the *Dlg* commands more modern and prefered to use instead the API calls without *Dlg* like SetWindowText? Yes, i know SendMessage can be used for a lot of things... but i am a bit confused - that their are three ways for doing the same thing and which way would be the best, if there is somewhere any different? For example from some API calls, that MS prefer to not use the functions anymore for future compatiblity like tha API calls to read/write/create INI files, afaik...

Quote
The variable naming (hWnd/hwnd etc) is called Hungarian Notation.  Microsoft use it everywhere and if you're writing Windows API code you might benefit from following the same style.  I don't usually do that, though.

Ok, i will take a look to what version of Hwnd vs hWnd is the so called hungarin notation standard ;) thx for your reply!
- 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
Re: Some questions to app coding using Win32 API
« Reply #3 on: January 21, 2009 »
There's no problem or benefit from using those three different API calls to change the text in a dialog.  A dialog is just a window anyway, as are all the controls.

Jim

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Some questions to app coding using Win32 API
« Reply #4 on: January 21, 2009 »
Quote
i am trying to start coding my frist Win32 API based GUI app with VS
If you're not talking about very simple things (like a single options-dialogue for example) and you don't care about the file-size, have a look at a serious toolkit (like Qt).
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Some questions to app coding using Win32 API
« Reply #5 on: January 21, 2009 »
thx hellfire..
but i absolutly dont like all this "bloody" 3rd part stuff like SDL, QT and whatever... why not just use the functions directly, windows has inbuild for us? ^^
i
- 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 hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Some questions to app coding using Win32 API
« Reply #6 on: January 22, 2009 »
Quote
why not just use the functions directly, windows has inbuild for us?
Because you'll end up building lots of wrapper classes which are already done better by other people and your code keeps portable.
Challenge Trophies Won: