|
I just want to how to use them. And, the parameters.
|
|
|
|
|
this is example how to use func in dll :
<br />
# define LWA_COLORKEY 1<br />
# define LWA_ALPHA 2<br />
# define WS_EX_LAYERED 0x80000<br />
HWND hWnd=this->m_hWnd;<br />
typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);<br />
PSLWA pSetLayeredWindowAttributes;<br />
HMODULE hDLL = LoadLibrary ("user32");<br />
pSetLayeredWindowAttributes = (PSLWA) GetProcAddress(hDLL,"SetLayeredWindowAttributes");<br />
For parameter of functions refer to MSDN
|
|
|
|
|
diat wrote: what functions does netshell.dll include?
what parameters do they have?
What do you need exactly?
|
|
|
|
|
afx_msg void OnSize(UINT nID, int intWidth, int intHeight);
This function to change the position of all items on a dialog. Can i call this function by another function to redraw the dialog? If not, does it have another method to re-posit all items?
Thx
Another Questions:
How to set Picture control from invisible to visible?
how to get the width and the heigth of a dialog?
-- modified at 0:13 Monday 14th August, 2006
|
|
|
|
|
(1)you want to use WM_SIZE for redraw a window
(2)See ShowWindow(SW_*)
(3)See GetWindowRect(...) and ScreenToClient
|
|
|
|
|
But how to call onSize function?
And also how to set the picture control to visible??
thx a lot
|
|
|
|
|
use SendMessage(...) this method send messages to window and see WM_SIZE nWidth=LOWORD and height=HIWORD
|
|
|
|
|
If you have handle to that window, use SendMessage()for sending message to that window. Which eventually calls OnSize on that window.
i.e.
SendMessage(hWnd,WM_SIZE,wParam,lParam);
|
|
|
|
|
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 ?
|
|
|
|
|
This is a part of my non-MFC program, but I think you can get the idea
if(hThisApp) {
if (IsIconic(hThisApp) )
ShowWindow(hThisApp,SW_RESTORE);
SetForegroundWindow(hThisApp);
}
|
|
|
|
|
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)
{
DWORD vLen,langD;
BOOL retVal;
LPVOID retbuf=NULL;
char fileEntry[256];
sprintf(fileEntry,"\\VarFileInfo\\Translation");
retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
if (retVal && vLen==4)
{
memcpy(&langD,retbuf,4);
sprintf(fileEntry, "\\StringFileInfo\\%02X%02X%02X%02X\\%s",
(langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24,
(langD & 0xff0000)>>16, csEntry);
}
else
sprintf(fileEntry, "\\StringFileInfo\\%04X04B0\\%s",GetUserDefaultLangID(), csEntry);
if (VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen))
csRet = (char*)retbuf;
}
}
UnlockResource( hGlobal );
FreeResource( hGlobal );
}
return csRet;
}
BOOL CALLBACK AboutProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
static char Version[20],Date[40];
if (Message == WM_INITDIALOG)
{
char *tmp = LStr(IDS_14);
tmp = GetVersionInfo("SpecialBuild");
tmp = LStr(IDS_14);
STRINGTABLE DISCARDABLE
BEGIN
IDS_01 "ÃÜÂë´íÎó"
IDS_02 "´íÎóÓû§Ãû"
IDS_03 "Unkown Pending command"
IDS_04 "´ò¿ª"
IDS_05 "Excel Îĵµ (*.xls)\0*.xls\0\0"
IDS_06 "ѧÉúÊý¾Ý (*.sd)\0*.sd\0ËùÓÐÎĵµ (*.*)\0*.*\0\0"
IDS_07 "ѧÉúÊý¾Ý (*.sd)\0*.sd\0Excel Îĵµ (*.xls)\0*.xls\0ËùÓÐÎĵµ (*.*)\0*.*\0\0"
IDS_08 "ѧÉúÊý¾Ý¿â (*.sd)\0*.sd\0"
IDS_09 "¾¯¸æ"
IDS_10 "ÄãÏë±£´æÒѾÐ޸ĵÄÉèÖÃÂð?"
IDS_11 "ID ´íÎó'input_comment'"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_12 "ûÓпÉÓõļͼ"
IDS_13 "ÎÞ·¨»ñµÃѧÉú¼Í¼"
IDS_14 "ÎÞ·¨ÏÂÔØ 'Rich Edit' ¿ØÖÆ!"
IDS_15 "ÕýÔÚ×¼±¸..."
|
|
|
|
|
Hello
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!!!
please help me...
Kamyar Souri
|
|
|
|
|
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).
Main.cpp:
#include <iostream>
#include "Animal.cpp"
int main()
{
Animal Lucy(5.0);
std::cout << "Lucy is ";
std::cout << Lucy.GetAge();
std::cout << " years old.\n";
Lucy.Eat();
Lucy.Sleep();
Lucy.Speak();
return 0;
}
Animal.cpp:
#include <iostream>
#include "Animal.h"
Animal.h:
class Animal
{
public:
Animal();
Animal(unsigned short int defaultAge);
Animal(double defaultWeight);
Animal(unsigned short int defaultAge, double defaultWeight);
~Animal();
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;
protected:
void Init();
unsigned short int* itsAge;
double* itsWeight;
};
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.
|
|
|
|
|
#include "Animal.cpp"
you will almost never ever #include a .CPP file.
try #include "Animal.h"
|
|
|
|
|
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.
senthryl wrote: 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.
-- modified at 11:16 Sunday 13th August, 2006
|
|
|
|
|
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...
Thanks for your help!
|
|
|
|
|
declarations go in .H files.
definitions go in .CPP. you will probably never need to #include a definition.
you should add both files types to the Visual Studio project.
|
|
|
|
|
I now have main.cpp, Animal.cpp, and Animal.h.
Animal.h has the declarations.
Animal.cpp has the definitions, and #includes Animal.h.
main.cpp has the driver program, and also #includes Animal.h.
Is that correct?
|
|
|
|
|
senthryl wrote: Is that correct?
yep. exactly.
|
|
|
|
|
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:
#ifndef __UNIQUE_SYMBOL__
#define __UNIQUE_SYMBOL__
#endif // __UNIQUE_SYMBOL__ 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:
class MyClass; 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.
|
|
|
|
|
This is what I have:
class CGraphicsSystem
{
public:
class CImage
{
public:
... // public functions
DrawRectGradient(RECT&, CGradient&);
};
class CGradient
{
... // 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
Why??
Joel Becker
|
|
|
|
|
If you're just using CGraphicsSystem as a container for other classes, you may be better off defining it as a namespace rather than as a class .
|
|
|
|
|
Thanks for replying.
I actually have quite a bit of data and functions in the CGraphicsSystem class; I just showed the minimum code to highlight my problem. Any suggestions?
Thanks.
|
|
|
|
|
I guess CGradient is previously declared outside CGraphicsSystem (to make CImage compile).
Did you purposely cut out the return value types, or are the functions declared without them?
|
|
|
|
|