|
Mouse events are sent by the system, not a form
(unless you have a form that sends them).
Subclass the control and you'll get the first look
at the messages and you can decide what messages to
let the control handle.
Are you using MFC or straight Win32 APIs?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually I am using MFC but I am able to use direct win32
And I got what you mean by sub classing the control,
But the problem is that I am trying to catch mouse event send to a com component not an ordinary control, so that I can't subclass it, it is a black box
But I believe that I should be able to catch the event through the default window Proc and before dispatching it, where the application itself dispatch the every event and send it any GUI item
But I am new in that area so I found difficulty
And I need help.
|
|
|
|
|
In that case, override CWinApp::PreTranslateMessage()[^] in your
application class. You can filter messages there.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
many thx, it works
and here is the code
const UINT RBUTTONDOWN = 0x204;
const UINT RBUTTONUP= 0x205;
BOOL Cmfc01App::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case RBUTTONDOWN:return true;
case RBUTTONUP:return true;
default:CWinApp::PreTranslateMessage(pMsg);
}
}
|
|
|
|
|
Remember, that disables ALL RBUTTON messages for ALL windows
You can also check the message and filter by HWND if you need to.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hey i tried to use the handle to not disable all the RButton messages
and i used this code
but it fails
BOOL Cmfc01App::PreTranslateMessage(MSG* pMsg)
{
CButton* pb = (CButton*) GetDlgItem( m_pMainWnd->m_hWnd,IDC_BUTTON5);
switch (pMsg->message)
{
case RBUTTONDOWN:if(pMsg->hwnd==pb->m_hWnd)return true;
default:CWinApp::PreTranslateMessage(pMsg);
}
}
give me an exception " Access violation reading location 0x00100d46."
plz help
|
|
|
|
|
is there any one can help ?
|
|
|
|
|
Hi Friends,
I am writing a MFC Application for UNICODE convertion,
After convertion i need to delete unwanted files in a particular folder.
Could any one tell me how to do that.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
|
Of course I suggest use of SHFileOperation because it ask of you for confirm.
|
|
|
|
|
Hello everyone,
I am confused what is the type of *this? Type of reference to instance or type of instance?
Looks like both code can compile, no warning messages. Any ideas?
class A{
A& foo1()
{
return *this;
}
A foo2()
{
return *this;
}
};
thanks in advance,
George
|
|
|
|
|
Hi,
The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.
// Example of the this pointer
void Date::setMonth( int mn )
{
month = mn; // These three statements
this->month = mn; // are equivalent
(*this).month = mn;
}
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
THANKS . I am also confused aboout 'this'.but now got it.
|
|
|
|
|
Thanks SANTHOSH,
My question is not what is this pointer, but when we return *this, should we treat return type as reference to object type, object type, or both are ok?
regards,
George
|
|
|
|
|
foo1 returns a reference to the object pointed at by this . foo2 returns a copy of the object pointed at by this .
|
|
|
|
|
Thanks gleat,
You mean if we invoke,
1. fun1, like A& a = fun1(), then return a reference;
2. fun2, like A a = fun2(), return a new copy of instance (invokes assignment operator on A)
Both are good code, right?
regards,
George
|
|
|
|
|
Yep. That's the idea. As for whether its good code or not depends on what you want to do. Some simple thumb-rules are:- Don't pass around data heavy structures by value as the copying overhead can prove to be a performance drain. Be especially wary of passing them via STL (or any other) collection types. Imagine returning a
vector<BigHeavyClass> containing 500 items by value! - When passing around objects by reference remember to use
const if you do not intend to alter the object's state via that reference.
|
|
|
|
|
Thanks for your advice, gleat!
My question is answered.
regards,
George
|
|
|
|
|
George_George wrote: (invokes assignment operator on A)
Not exactly true. It invokes the copy constructor, which is not the same thing.
Software Zen: delete this;
|
|
|
|
|
Thanks Gary, you are correct. I want to confirm with you that,
1.
A a = fun2() will invoke copy constructor on a;
2.
A a;
a = fun2();
will invoke assignment operator on a.
Both are correct?
regards,
George
|
|
|
|
|
Since foo1 returns a reference (which is really just a pointer), it can just return the address of the 'this ' object.
The other function, foo2 actually returns an object of type A . In order to do that, it invokes the copy constructor for A , copying the contents of this to the destination.
Software Zen: delete this;
|
|
|
|
|
Thanks Gary,
How about your comments on my two questions before?
--------------------
1.
A a = fun2() will invoke copy constructor on a;
2.
A a;
a = fun2();
will invoke assignment operator on a.
Both are correct?
--------------------
regards,
George
|
|
|
|
|
I believe your statements are both true. The compiler is supposed to turn #1 into this:
A a(fun2()); automatically, which is a call to the copy constructor.
#2 obviously calls the assignment operator. Note that the default constructor for A is called first, when the variable is declared.
Software Zen: delete this;
|
|
|
|
|
Thanks for your clarification, Gary!
regards,
George
|
|
|
|
|
George_George wrote:
class A{
A& foo1()
{
return *this;
}
A foo2()
{
return *this;
}
};
Well, there's nothing special related to this in the above snippet:
you can do as well:
class B
{
int i;
int * p;
...
int getiValue(){ retirn i;}
int & getiRef(){ return i;}
int getpValue(){ return *p;}
int & getpRef(){ return *p;}
...
}
it is simply C++ syntax for dealing with references.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|