parameters; what they do and mean?

Hello,
I am new to c++ but I coded for a while in VS c#, so I am not a complete beginner. I have 37 years - not too young either.

I just installed and run Code:Blocks compiler & editor.
I started a win32 GUI project.
I started a tutorial on how to create a form and a button.
But I get an error at this line:
1
2
3
4
5
6
7
8
   if (LOWORD(WPARAM)== 1)  
//in the tutorial he actually uses wPARAM But here on my end I get autocorected.
//error:  expected primary-expression before ')'  <--How dare you?
//----
//and, if I use his exact code, I get this error: 
//'wPARAM' was not declared in this scope  
//-because is with a lower 'w'... Oo?

And in the tutorial, the same code is working just fine.


My question is: - How do I really understand what those parameters do and mean?
LOWORD?WPARAM? and the rest of them from that Form file that was created for me. Where to look to figure them out?

Thank you very much and excuse my rookiness.

Last edited on
You can check the docs:
https://msdn.microsoft.com/en-us/library/windows/desktop/ff468925(v=vs.85).aspx
(I think that's the right site! I don't do Windows stuff any more.)

WPARAM is a type alias, which means that in the context you've given the correct code must actually be wParam or wPARAM or something else -- an identifier declared elsewhere. Or a typo.

LOWORD is a macro which extracts the least-significant word from some double-word (32-bit) argument.
e.g., something like
#define LOWORD(x) (x & 0xFFFF)

Can you provide a link to that tutorial?
Last edited on
When I used [wParam] now, It worked !!!
Your suggestion and the tutorial guy suggestion worked !
(with some New additional bugs).


I was using WPARAM and wPARAM
But you and the tutorial guy used wParam
Rooookie big mistake for me. I am so ashamed...

Thank you - Now I figure it out!
---------
But...
My question is how do I specifically know what keyword must be used ? And where, and why :((((( - crying with desperation...

I also look into your msdn link page, it seems I went into it already for [CreateWindow function] ; But !!! I couldn't find the correct sintax I am using.
For clarification:
on msdn page is used this formulation:
HWND WINAPI CreateWindow(...);
and I am using (from the tutorial) another formulation:
WM_COMMAND:

How do I find and use the correct formulation/sintax for what I have? :(( - again, crying my ass off. I am in complete dark right now.

Here is the link with the tutorial I was following:
https://www.youtube.com/watch?v=NZkpp-a-tYA
Last edited on
My advice is to use Visual Studio for programming, Intellisense will help you a lot with syntax, as well as VS has some boilerplate for windows to get you started. Especially since you said you used VS for C#, I see no reason to switch to a less efficient IDE.

Also, if you want to learn WINAPI, I recommend getting Pretzold's book, nicknamed "The Windows Bible".

WM_COMMAND:
this is a message for a dialog/window procedure, not the window itself

CreateWindow();
this creates a window

For the main window you should use something like this:
1
2
3
HWND handle=CreateWindowEx( WS_EX_CLIENTEDGE,className,L"Caption",
                            WS_OVERLAPPEDWINDOW, width,height, CW_USEDEFAULT, 
                            CW_USEDEFAULT,NULL,NULL, hInstance, NULL);


As well, you may want a handle (HWND,H-handle WND-window) for your window

Last edited on
Golden Lizard, thank you for your reply.
yes I do use VS for c#.
But what bother me a lot was the levels of 'security' they forced you to comply.
Maybe is for c# only? Maybe is for c++ too, I don't know since I have to install it and it takes a couple of Gb's. So I will try something more flexible (hopefully) and thinner like the CodeBlock editor. It looks the c# is way too experimental and it got away with it, while c++ is the foundation of mostly every type of software - winapp,webapp,games,db,etc. Maybe I am so wrong, but I spend so much time and effort with c# and I still suck at it. Or maybe I am not that smart. I dont know. But my intuition is that c++ is more agile , and VS is offering at the surface some good benefits, but I had to literally fight through its barriers of freedom - which eat all my time and effort and I am sick with it... Well, after I will see how hard this language is and I will return back to it ... eh...
But to respond to your argument, I will stick for awhile with low level editors and stay away from VS for the simple reason of "barriers of freedom".
-
Your book, do you have a link to it? It is free? I searched on google but nothing concludent.
-
I see you re-edited in the meantime,
My interest is how do I discover myself these keywords that you guys are using, they meaning, they functionality, examples, and basically full information about them? I will use your code, but I want to learn about it and other possible permutations. I hope you get my point and can direct me into the right direction.
Thank you so much.
Last edited on
Those extra gbs used by the VS are worth it, trust me.The book is not free, however, but it contains everything you may need to know about WINAPI.

https://www.amazon.com/Programming-Windows%C2%AE-Fifth-Developer-Reference/dp/157231995X
i find the free version here:
http://venom630.free.fr/pdf/Programming%20Windows%20Fifth%20Edition.pdf
I will definitely look into this recommendation.
----
I see you re-edited in the meantime,
My interest is how do I discover myself these keywords that you guys are using, they meaning, they functionality, examples, and basically full information about them? I will use your code, but I want to learn about it and other possible permutations. I hope you get my point and can direct me into the right direction.
Thank you so much.
----
thank you.
Well, it shouldn't be free, if you know what I mean :P (arr!). The Forger has also a good tutorial on win32 api, check it out:

http://www.winprog.org/tutorial/

There's also MFC (microsoft foundation classes), which is basically win32 api encapsulated inside classes, it may be easier to digest for someone that has a c# background.
Last edited on
! ! ! I strongly think that things to learn from should be always free ! ! !
But is an imperfect world.
So, Thank you again for being specific this time and finding this tutorial on win32 api. It is a good start for me - I hope.
To auto-respond to my questions about where do I get the information about new classes and new functions and new parameters? From books. c# excels in google finds. That is so appealing to it. Probably I dont know where to look yet, or how to look, but googling about c++ classes and functions and param, didnt give me any clue (as a beginner) to what to do and how to do it. I hope is my rookiness and my trembling start.
Thank you very much mister Golden Lizard.
from: http://www.winprog.org/tutorial/simple_window.html
it say: " If you know the functions you need to call then it is a matter of seconds to look up the exact parameters in your help files. If you don't have help files, get them. You are lost without. "
This is what I need !
But I made a search for myself first and find this:
http://planetsquires.com/cplus/index.php?topic=35.0
which sadly is an empty *.chm... :(
I loaded it into CodeBlocks too, but still empty.
CodeBlocks help is about editor things. But not c++.
but from there I find this:
http://en.cppreference.com/w/
Which is fantastic. I think I find the right thing here. What do you say?


Now, on the same page tutorial, I get confuse about this part:
"Step 1: Registering the Window Class
...
A Window Class has NOTHING to do with C++ classes." --the hell?!? :)

I start to see the real problem now. All those keywords and declarations are not from c++ or c.
Like this one:
1
2
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)

or like the one that is creating the buttons or other controls.
Where do I find the help for them ?
With description and examples?
(I will still continue to read the tutorial... if nothing is saving the day)
Thank you!



Last edited on
For learning Windows programming I recommend the "Bible" from Charles Petzold. Start at the beginning and also get the examples from his website. It tells you most things you need, the others you can ask either here or stackoverflow.com. CodeProject.com has also good articles but not for absolute beginners.

I spend so much time and effort with c# and I still suck at it.

What are your your problems with C#?
C# is much higher level and easier so be prepared for a much higher learning curve with C++. The C# compiler is much meaner and will prevent many mistakes.
All those keywords and declarations are not from C++ or C.

They're names introduced by the Win32 API -- Microsoft's code. If you're approaching the Win32 API without experience in a C-like language it might be confusing to you. The site I linked to you, the MSDN, contains the information about Microsoft's APIs.

To make things worse, the Win32 API is written in C, not C++. C code is (often) compatible, but not idiomatic C++.

Conventional wisdom says that you should learn the standard language first. Whether or not you bother with that depends on how you feel.
Topic archived. No new replies allowed.