IonicWind Software

Aurora Compiler => General Discussion => Topic started by: GWS on February 23, 2006, 02:16:50 PM

Title: hWnd
Post by: GWS on February 23, 2006, 02:16:50 PM
Since the Gui was born, lots of statements refer to m_hWnd.
Paul said some time ago, it was a variable associated with a window - the window's handle .. (I'm trying to avoid OOP'speak).

Since it gets so much use, why it is called m_hWnd instead of just hWnd.
Paul usually has a good reason for things, but I thought I'd better ask, since the simpler the better.

Graham :)
Title: Re: hWnd
Post by: Mike Stefanik on February 23, 2006, 02:27:50 PM
It's common for class member variables to be prefixed with "m_" so that when you look at the code, you know you're dealing with a variable that's a member of a class, not declared locally. Likewise, it's common to prefix global variables with "g_" so that you know they're global to the application or library.

Edit: For folks who aren't used to programming in C/C++ in the Windows environment, some of the conventions can seem pretty strange. For example, m_pszCustomerName or m_dwVolumeId. The origin of it is a notation developed by a Microsoft programmer named Charles Simonyi (http://en.wikipedia.org/wiki/Charles_Simonyi), commonly called "Hungarian Notation". It's a style that was adopted throughout Microsoft, including the Microsoft Foundation Classes for Visual C++. Other developers started using the same style, and it became a major coding convention that continues to be used today. There are detractors who argue that Hungarian isn't a good notation method, but on the Microsoft platform it's a defacto standard.
Title: Re: hWnd
Post by: Bruce Peaslee on February 23, 2006, 04:04:39 PM
I recommend the use of a coding standard to reduce errors. If you always prefix your member variables with something that denotes their type and scope, your less likely to use them incorrectly or in the wrong place.

My method is close to Microsoft's (but not the same) because of the high use of MSDN for API calls.
Title: Re: hWnd
Post by: Ionic Wind Support Team on February 23, 2006, 05:09:47 PM
Mine is an adaptation with my own style.   In my younger years I used to follow the naming conventions very stricty when coding.  Now I use just a shortened version to keep things straight in my own code.

Any class members are prefixed with m_ I'll use b for boolean, n or i for integer, f for float and d or db for double variables.  I used to be a stickler about 'sz' for strings but you will see me omit the z now and again since all strings in my languages are zero terminated anyway.

Some examples:

m_bDone; //member of a class, boolean (int);
m_nCount; //member of a class, integer
m_iValue; //Integer member.  Variation.
sName; //string variable;
pData; //pointer variable.

Title: Re: hWnd
Post by: GWS on February 24, 2006, 02:30:33 AM
Thanks guys .. I can see the patternÂÃ,  :)  Looks like we're stuck with m_hWnd for a window handle then.

Quote
For folks who aren't used to programming in C/C++ in the Windows environment, some of the conventions can seem pretty strange.
'er yes .. ::)

I can see that for serious commercial development such standards are necessary, but as a hobby programmmer simply Defining my variables is enough for me.ÂÃ,  So 'z32' might well be a string - if I say so :) ..ÂÃ,  I don't like to be straight-jacketted by convention.

all the best, :)

Graham

Title: Re: hWnd
Post by: Ionic Wind Support Team on February 24, 2006, 07:41:01 AM
Technically I shouldn't allow accessing any member variables direclty.

mywin.GetHandle();

Was the original plan. But I saw little point in it for the Alpha versions
Title: Re: hWnd
Post by: Bruce Peaslee on February 24, 2006, 09:14:52 AM
Quote from: Ionic Wizard on February 24, 2006, 07:41:01 AM
Technically I shouldn't allow accessing any member variables direclty.

I agree. In the trivial cases it makes for more coding, but I think Public vs Private, etc., is the way to go.