In case the windows(Dialog Base)is minimize status.
What is the function to use to make the windows show in screen again.
Is it ShowWindow(SW_RESTORE)?
If so, my problem is after call this function the windows will can't minimize again.
What the code I have to write with this function ?
I am displaying some of the version info in an 'about' box within my app. The problem is, after reading Chinese text from the version info it kinda screws up following calls to LoadString(). I have narrowed the problem down to a single call to VerQueryValue(). This function does as it should, it reads the string from the version info and returns it. But for some reason, When calling LoadString with a resource id of IDS_13 (8 Chinese characters Shown below), instead of returning the null terminated string, it fills the provided buffer with all the strings from IDS_14 and up. If LoadString is called with an id of higher than IDS_13 the app crashes.
LPSTR GetVersionInfo(LPCTSTR csEntry)
LPSTR csRet = NULL;
HRSRC hVersion = FindResource( hGlobLang,
MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION );
if (hVersion != NULL)
HGLOBAL hGlobal = LoadResource( hGlobLang, hVersion );
if ( hGlobal != NULL)
LPVOID versionInfo = LockResource(hGlobal);
if (versionInfo != NULL)
retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
if (retVal && vLen==4)
(langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24,
(langD & 0xff0000)>>16, csEntry);
sprintf(fileEntry, "\\StringFileInfo\\%04X04B0\\%s",GetUserDefaultLangID(), csEntry);
// The following function seems to be the cause
if (VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen))
csRet = (char*)retbuf;
UnlockResource( hGlobal );
FreeResource( hGlobal );
I want to change window layout to RTL in a CDialog based class.
I have done it by using SetWindowLong and WS_EX_LAYOUTRTL style at runtime.
BUT POSITION OF CONTROLS ON DIALOG WILL NOT BE MIRRORED!!!
This is my first attempt at a program with classes, as I'm new to VC6. The program worked fine, until I decided to split it into multiple files with #include. I've looked for a solution but have only found answers about declaring global variables in a header file, which I don't think I've done.
Here's the code for my Animal class (this program doesn't really serve any purpose, I'm just trying to learn how to use classes).
std::cout << "Lucy is ";
std::cout << Lucy.GetAge();
std::cout << " years old.\n";
//This file continues to implement all of the methods in Animal.h, but it was trimmed for size.
Animal(unsigned short int defaultAge);
Animal(unsigned short int defaultAge, double defaultWeight);
unsigned short int GetAge() const;
double GetWeight() const;
void SetAge(unsigned short int newAge);
void SetWeight(double newWeight);
void Eat() const;
void Sleep() const;
void Speak() const;
unsigned short int* itsAge;
I receive the following errors when linking:
Animal.obj : error LNK2005: "protected: void __thiscall Animal::Init(void)" (?Init@Animal@@IAEXXZ) already defined in main.obj
Animal.obj : error LNK2005: "public: __thiscall Animal::Animal(void)" (??0Animal@@QAE@XZ) already defined in main.obj
Animal.obj : error LNK2005: "public: __thiscall Animal::Animal(unsigned short)" (??0Animal@@QAE@G@Z) already defined in main.obj
Animal.obj : error LNK2005: "public: __thiscall Animal::Animal(double)" (??0Animal@@QAE@N@Z) already defined in main.obj
Animal.obj : error LNK2005: "public: __thiscall Animal::Animal(unsigned short,double)" (??0Animal@@QAE@GN@Z) already defined in main.obj
Animal.obj : error LNK2005: "public: __thiscall Animal::~Animal(void)" (??1Animal@@QAE@XZ) already defined in main.obj
Animal.obj : error LNK2005: "public: unsigned short __thiscall Animal::GetAge(void)const " (?GetAge@Animal@@QBEGXZ) already defined in main.obj
Animal.obj : error LNK2005: "public: double __thiscall Animal::GetWeight(void)const " (?GetWeight@Animal@@QBENXZ) already defined in main.obj
Animal.obj : error LNK2005: "public: void __thiscall Animal::SetAge(unsigned short)" (?SetAge@Animal@@QAEXG@Z) already defined in main.obj
Animal.obj : error LNK2005: "public: void __thiscall Animal::SetWeight(double)" (?SetWeight@Animal@@QAEXN@Z) already defined in main.obj
Animal.obj : error LNK2005: "public: void __thiscall Animal::Eat(void)const " (?Eat@Animal@@QBEXXZ) already defined in main.obj
Animal.obj : error LNK2005: "public: void __thiscall Animal::Sleep(void)const " (?Sleep@Animal@@QBEXXZ) already defined in main.obj
Animal.obj : error LNK2005: "public: void __thiscall Animal::Speak(void)const " (?Speak@Animal@@QBEXXZ) already defined in main.obj
Debug/ClassTest.exe : fatal error LNK1169: one or more multiply defined symbols found
All of these files are included in the same workspace in the same directory.
I'm confused about where I should put the declarations for my classes and where to put the definitions. When reading my book I got the impression that a header file would contain only the class declarations, and that it would come with an associated .cpp file which contained the definitions. In the book they include the .cpp definition file from their main file, which then includes the .h declaration file at the top.
If I move all of the definitions from the .cpp file into the .h file with the declarations, and include the header file all at once, it works fine. But my book says that the definitions and declarations should be in different files...
Should they be in the same file, or different files, and if so, how must I include them?
they should be in different files (except in special cases like inline functions or templates - which you don't need to worry about here).
and you should only #include the .H files. somtimes .H files will #include other .H files.
In the book they include the .cpp definition file from their main file, which then includes the .h declaration file at the top.
that's very very unusual - there's almost no good reason to do that in 99.99% of the situations you're likely encounter. they might be trying to get out of telling the compiler to explicity compile the .CPP (by #including it, the compiler will compile it as part of the main file), but with Visual Studio, it's trivial to add the .CPP to the project so the compler can compile it separately.
Perfect! I just stored the declarations in another header file and included that from the definition header file.
So I have main.cpp which includes Animal.h (containing the definitions) which includes Animal_Dec.h (containing the declarations).
It's odd, the book says:
"The definition must be in a file that the compiler can find. Most C++ compilers want that file to end with .c or .cpp. This book uses .cpp, but check your compiler to see what it prefers."
Apparently I didn't check my compiler to see what it prefers Although I would have thought that they would give proper instructions for VC6 anyway, since that is what the book is mainly written for...
The C++ model is that any function can be implemented in any translation unit, so long as there are not multiple definitions: that's what the LNK2005 error is telling you, that the same functions were defined more than once.
A 'translation unit' is the standardese for the result of preprocessing a given input. It's given this odd name because the input doesn't necessarily have to be a file - some C++ compilers will accept input from standard input or another redirected stream, although of course in practice this isn't very useful.
It's worth understanding that the #include statement simply pastes - includes - the contents of the referenced file into the current file at that point. This is the source of the multiple inclusions problem - that you can get 'multiply defined symbol' errors if you include a file more than once in any given translation unit. The traditional workaround is to wrap the whole 'header' file like this:
You change __UNIQUE_SYMBOL__ for every new header file, so that each file has a unique definition. This so-called '#ifdef guard' effectively removes the contents of the file from the second definition. Microsoft's compilers since Visual C++ 4.0 support #pragma once which simply tells the compiler not to include this file again if it is encountered again, which is a little quicker than opening the file and noticing that the macro at the top is already defined. This feature is now supported by a number of other compilers.
In order to use a class, structure, or enumeration in a given translation unit, you must declare it. Traditionally this is done by including a so-called header file (traditionally given the .h extension although you might see .hpp or .hxx for C++ headers, but it can have any extension you like, or none in the case of the C++ standard library headers). You can simply redeclare the class in the second file but you can then have problems if the declarations get out of sync, which is why the #include mechanism exists.
It's best to think of each translation unit - each .cpp file - as being compiled completely independently from all the others, although the Microsoft compiler actually can work more efficiently with a batch of source files all specified on the same command line, and particularly with the Pre-Compiled Headers feature.
If you only refer to the class with a pointer (or reference), and never dereference the pointer (or reference), you can simply forward declare it, for example:
You have to use the right keyword, so if it's declared as a struct you must forward-declare it as a struct.
If you define a new class using Visual Studio's wizards, it creates a header and a single .cpp file matching the class's name, but this is simply convention - you can define as many classes in a single header as you like, and you can implement multiple classes in a single file or a single class in multiple files, as you prefer. You might split a class into multiple files if the implementation is very large, to speed up compiles - the compiler will only recompile those files that have actually changed. You might be advised to reduce the number of methods in the class if that occurs, however. It is generally considered best practice to declare only one class in a header and implement it in a single source file, unless there are good reasons not to.
... // public functions
... // public functions and protected member variables
friend CImage::DrawRectGradient(RECT&, CGradient&);
I'm getting compiler error:
error C2245: nonexistent function 'CGraphicsSystem::CImage::DrawRectGradient' specified as friend