|
Hi guys.
I have the following question?
I know that the WM_CHAR message goes to the main window of the program but isn't it Main Frame?Yeah,yeah ... i see that this is CView but where exactly this is coded in MFC?
And if I try to "go round" Doc/View and do something like
m_pMainWnd = new CMainFrame
m_pMainWnd->ShowWindow(..)
m_PMainWnd->UpdateWindow()
who gets WM_CHAR ?
and yes .. .I'm a newbie
10x in advance
|
|
|
|
|
OK. I made a template class that is like a circular buffer but then that could take many diffferent types of variables for a 2-D type graph.
Now, I want to use declare a pointer to this in another class BUT that does not know what kind of variables it will be before hand. Is this possible? After this, when I declare the graph class lets say, I want to tell it what kind of variables the circ buffer will be. This way, it can use the variable types and how I tell it to plot or do some manuipulation.
I am not sure how even to do this. Any ideas would be greatly appreciated.
Thanks
|
|
|
|
|
This can be done, but it is no trivial task. I'll sketch a basic scheme for a very simple data structure having only two member functions called put and get . As the host class (the one using the data structure) does not know in compile-time the exact type of the structure, this has to derive from an abstract base:
struct datastruct_base
{
virtual ~datastruct_base()=0{}
virtual void put(const void* arg)=0;
virtual void get(void* arg)=0;
}; Note the argument to the functions has to be declared as raw pointers to void , since datastruct_base does not know about the actual types handled by its derived classes. A better approach could be taken using some sort of polymorphic variable like the one featured in Boost.Any[^].
Now, template classes derive from this abstract base like this:
template<typename type>
struct datastruct: public datastruct_base
{
virtual void put(const void* arg)
{
put(static_cast<const type*>(arg));
}
virtual void get(void* arg)
{
get(static_cast<type*>(arg));
}
void put(const type* arg)
{
...
}
void get(type* arg)
{
...
}
}; That's it. The host class sees the passed data structure through its base virtual class. For each instantiation of datastruct , put and get forward to non-virtual , type-specific member functions:
class host{
private:
datastruct_base* ds;
public:
void set_datastruct(datastruct_base* ds){this->ds=ds;}
void put(const void* arg){ds->put(arg);}
void get(void* arg){ds->get(arg);}
};
host hs;
datastruct<int> dsi;
hs.set(&dsi);
int i=10;
hs.put(&i);
hs.get(&i); Hope you get the idea. This is a common idiom in modern C++, with roots stemming from a relatively old technique called envelope-letter. Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hello,
I must recover the privileges (user, administrator...) of the session in progress under Win2000 that it is in room or on networks.
How must one make (out of C, C++), there would have to you it an example some share.
Thank you.
Steph
|
|
|
|
|
Can you please help me .
I need to no how to change the colour of text in c++
Thanks for your help
Rich
|
|
|
|
|
What text ?
Displayed where ? How ?
Windows Application ?
Unix Application ?
Mac Application ?
Console Application ?
Say More and Answers will follow !!!
Max.
|
|
|
|
|
I have an object say myObject of some class. I do stuff with it after doing
MyObject myObject
Then after I'm done I say
myObject = NULL;
Now if I want to use myObject after this point, do I do all over again:
MyObject myObject
or can I just go ahead and do:
myOBject.Something(); without redeclaring it?
Appreciate your help,
ns
|
|
|
|
|
First this do look like CSharp, but the capital letters on NULL indicates c++.
If indeed it is c++, then you cannot assign NULL to myObject, since it is not a pointer (On the stack);
You cannot redeclare the object. If the compiler doesn't complain, then it is because there is another stack-frame.
If you want a new object, this is how you do.
first declare myObject as a pointer:
MYObject* pMyObject = NULL;
then create an instance of it:
pMyObject = new MyObject();
then delete it:
delete pMyObject;
change all the dots to reference operator:
{.} to {->}
|
|
|
|
|
You can have as many new, and delete pairs as you like.
and yes, you need to have all the calls to the object in between these operators.
GOOD LUCK!
|
|
|
|
|
no!
ns wrote:
MyObject myObject
is not a pointer ! it's on the stack. memory will be release when the declaration gets out of scope.
ns wrote:
myObject = NULL;
Should give you a compilation error/warning.
If the object is declared on the stack ( like you did ), it will be constructed when it's declared, and deconstructed when it's going out of scope. you don't have to explicitly delete it.
If the object is on the heap :
MyObject* myObject = NULL;
myObject = new MyObject;
you can delete it :
delete myObject;
myObject = NULL;
if you want to re-use it, you will need to re-new it.
Max.
|
|
|
|
|
Okay. Very good explanation. I was mistaken that I thought I saw an object being set to NULL. It had to have been a pointer like you said. Many thanks for clarifying this...
Appreciate your help,
ns
|
|
|
|
|
You may have seen a smart pointer which made you think this. A smart pointer is a class which wraps and controls a pointer, and often setting a smart pointer to NULL internally deletes the pointer and therefore does what you were after.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Precisely. This was happening with things like _RecordsetPtr which didnt have the * associated with pointers so I mistakenly thought they were actual objects, which they actually are, except they are pointer-objects.....something like that. Anyways that was exactly where I was swimming in confusion...you hit it right on the head!
Appreciate your help,
ns
|
|
|
|
|
I want to get the keyboard message from my application My application include some dialogs and forms
Thanks!
|
|
|
|
|
What sort of application is it, does it use MFC ? You ultimately want to catch WM_KEYDOWN, WM_KEYUP or WM_CHAR. You don't need MFC for this, but the class wizard will do it for you for free if you're using MFC.
You catch the message per window, not for the whole app.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Thanks!
Yes,My application use MFC.
I am coding for a class,I want to get the keyboard message if every application include this class.
Maybe I will try Keyboard Input API?
|
|
|
|
|
No, it does not work that way. Each MFC class that represents a window ( like CMainFrame, CDialog, CView ) has a message map, and you need to catch the message in those. Ctrl-W will bring up the class wizard, you can choose a class and a message from there and it will plumb it all in for you.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
I used the hook dll in my application,but it get all ketboard messages(include other application's messages).Can I only get the messages from my application use the hook dll?
Thx!
|
|
|
|
|
Why would you want to do that when I've provided a far easier solution ?
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Our application has so much dialogs and forms ,it's difficult to monitor the message in every dialog,and my boss need a common class or dll to monitor our application and other applications.
|
|
|
|
|
I'm not sure how the messages bubble, but you should be able to get all dialogs to send the message to their parent, and then handle them all in the one spot. It's a lot nicer than a global hook, that's just a hack.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Hi,
I am using MSVC 6.0. I activated the /3GB switch in Windows XP Professional and also used a linker flag /LARGEADDRESSAWARE in the application in order to enable the application to address more than 2GB of memory.
The GlobalMemoryStatus reported dwTotalVirtual = 3221094400 and dwAvailVirtual = 3203072000. It seems that the above configuration works.
However, when I do a VirtualAlloc(NULL, 2*1024*1024*1024, MEM_COMMIT, PAGE_READWRITE) to allocate 2GB of memory, I always get a "ERROR_NOT_ENOUGH_MEMORY"?
How can I allocate those available virtual memory?
Thank you.
|
|
|
|
|
I am not sure you are making the right use of this "feature".
There's a difference between be able to allocate a TOTAL of more than 2GB, and be able to allocate a single block of more than 2GB.
The use of the VirtualAlloc API is subordonated to the use of the /PAE flag, not /3GB. There is no special API to use along with /3GB, since it just orders the system to leave under 1GB instead of 2.
The book "windows 2000 programming" explains how to use it. I guess that if you are doing this in a real world case, then you certainly can have more direct MS support for that topic.
Besides that, have you more than 2GB free disk space available (configured disk swapping) ?
How low can you go ? (MS retrofuck)
|
|
|
|
|
Thank you for replying.
I also suspect that VirtualAlloc API might not be able to allocate a single block of more than 2GB. Can we play around with /PAE flag to make it allocate more memory?
Do you mean that the book "Windows 2000 Programming" gives some method on how we can allocate a block of more than 2GB? Who is the author of the book? I need the memory for a Finite Element Analysis software.
I do have more than 2GB free disk space available.
|
|
|
|
|
tsk wrote:
I also suspect that VirtualAlloc API might not be able to allocate a single block of more than 2GB
That's what I have told you. You can allocate the amount of memory you want per process (with a limit of 3GB with /3GB and up to 64GB with /PAE) by chunks, not by a single call.
How this works is explained in the book mentioned. It's from MSPRESS[^].
Never forget Windows is a 32-bit OS, thus cannot address pointers more than 4GB large. And because the kernel takes 2GB of these addresses (without /3GB), that's why you have at most 2GB per process. A lot of problems here because the most significant bit of pointers is 1 and becomes negative (comparisons may fail).
To break the 4GB barrier, Windows, through VirtualAlloc and the /PAE allows you to use pages of memory (with is an old technique). Of course, this constraints the whole design of your program.
tsk wrote:
how we can allocate a block of more than 2GB?
Although that's unlikely, you'll need a horsepower OS, such like MS datacenter (with 4GB or 16GB of physical memory on-board) : again, if you are in a real world case, your company should by this time already be in contact with MS reps.
How low can you go ? (enculage MS)
|
|
|
|