-
August 19th, 2015, 09:20 AM
#1
[RESOLVED] Windows basic questions
I am using code blocks to create a basic windows application, and I have some basic questions about the skeleton program that it creates, and it does work all ok.
Firstly, when the window is defined by filling in the WNDCLASSEX, i noticed that there is a member lpszClassName. Does this have to be unique for every window class that you define, i.e. Will the same name cause RegisterClass() to fail?
Another thing I have noticed is that some code I have looked at shows programmers replacing (where I expect NULL) with 0, does this really matter?
More confusing to me is this; Some functions have a 'A' or a 'W' at the end of their name, but my code never states either. However am I right in thinking that the pre-processor works this out for me as a result of this stuff at the top of the file:
Code:
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
Does the preprocessor stuff really matter?
New to windows programming and just need a bit of clarification.
What the mind can conceive it can achieve.
-
August 20th, 2015, 05:32 AM
#2
Re: Windows basic questions
Originally Posted by Gerald Bates
Firstly, when the window is defined by filling in the WNDCLASSEX, i noticed that there is a member lpszClassName. Does this have to be unique for every window class that you define,
It does have to. This is what any sort of classification is about.
i.e. Will the same name cause RegisterClass() to fail?
Why don't you try that yourself?
Another thing I have noticed is that some code I have looked at shows programmers replacing (where I expect NULL) with 0, does this really matter?
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stddef.h
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdbg.h
Code:
/* Define NULL here since we depend on it and for back-compat
*/
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
More confusing to me is this; Some functions have a 'A' or a 'W' at the end of their name, but my code never states either.
Every API accepting string parameters exists in two incarnations, ANSI and Wide Character.
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WinUser.h
Code:
WINUSERAPI
BOOL
WINAPI
GetClassInfoA(
__in_opt HINSTANCE hInstance,
__in LPCSTR lpClassName,
__out LPWNDCLASSA lpWndClass);
WINUSERAPI
BOOL
WINAPI
GetClassInfoW(
__in_opt HINSTANCE hInstance,
__in LPCWSTR lpClassName,
__out LPWNDCLASSW lpWndClass);
#ifdef UNICODE
#define GetClassInfo GetClassInfoW
#else
#define GetClassInfo GetClassInfoA
#endif // !UNICODE
Those A and W versions are both present in user32.dll. What the highlighted header trick does is mapping non-specific API name to particular real version depending on default project settings, Multi-Byte or Unicode.
Code:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include>dumpbin /EXPORTS %windir%\system32\user32.dll | grep "GetClassInfo[A|W]"
1776 10B 00007490 GetClassInfoA
1779 10E 000116D0 GetClassInfoW
However am I right in thinking that the pre-processor works this out for me as a result of this stuff at the top of the file:
Code:
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
Does the preprocessor stuff really matter?
It does. Look at the quoted above. Some headers rely on UNICODE, but some on _UNICODE. The block you quoted makes sure both UNICODE and _UNICODE get defined once one of those was found defined.
New to windows programming and just need a bit of clarification.
All the answers are in headers, libs and dlls.
Last edited by Igor Vartanov; August 20th, 2015 at 05:54 AM.
Best regards,
Igor
-
August 20th, 2015, 08:22 AM
#3
Re: Windows basic questions
Originally Posted by Gerald Bates
Firstly, when the window is defined by filling in the WNDCLASSEX, i noticed that there is a member lpszClassName. Does this have to be unique for every window class that you define, i.e. Will the same name cause RegisterClass() to fail?
Everything you ever wanted to know About Window Classes.
Different processes can register different classes with the same name.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
August 20th, 2015, 10:57 AM
#4
Re: Windows basic questions
Many thanks for the reply, That's cleared up a few things. Most importantly the class name needs to be unique.
What the mind can conceive it can achieve.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|