|
Hi,
I am having the following scenario
a class CMy( and is not MFC class ),
and I create 3 objects a,b,c ( actually I need to create
any number of objects)
CMy a , b ,c
now CMy has an event WM_LBUTTONDOWN, WM_LBUTTONUP
I want only 1 function(event handler) OnMouseLButtonDown(),
so this is called whenever I press any one of the object
i.e a , b or c
I am trying to avoid Subclassing.
Can some tell me what should I do.
Thanks,
Sansky
God is Good, all the Time.
All the Time, God is Good.
|
|
|
|
|
Maybe you may try to modify my code below into what you want to...
#include <iostreamᡊe9ac73-238b-46be-991d-0f050c37248dusing namespace std;
class CCore
{
public:
void Job(int iId) {
cout << "Hey this is button " << iId << " clicked.\n";
}
};
class CMy
{
int _iId;
static CCore _EventMachine;
public:
CMy(int iId) { _iId = iId; }
void ButtonLClicked() {
_EventMachine.Job(_iId);
}
};
CCore CMy::_EventMachine;
void main()
{
CMy btn[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
btn[2].ButtonLClicked();
btn[6].ButtonLClicked();
}
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Subclassing is precisely what you need. In fact, it's what the MFC control classes do for you internally. Therefore, you don't want to use MFC, you'll need to either manually do the subclassing yourself or use another library that does it (such as MFC).
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom Archer wrote:
Subclassing is precisely what you need.
Hi Tom, was my way wrong ?
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Hi Maxwell, I would have thought you would have a base class as you've done and then have virtual OnxxxButton() function in the base class to handle the event. This could then be overriden in the derived classes as required.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Hi Maxwell,
I guess I'm just not understanding how your code is going to attach handlers to control windows messages without hooking the control's wndproc. Can you explain that a bit more? Maybe I'm just missing something obvious here.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Ok. I finally took more than a second to look at your code The issue is that I'm looking at it from a different level than you. You're assuming you already have the routed messages (via subclassing the control) and are providing an event machine to better handle the messaging of an array of controls. I, on the other hand, was thinking that the poster wasn't even at the point of getting the messages for the controls yet. He hasn't responded to any of the posts yet so it'll be interesting to see what he really is trying to get.
By the way, with regards to your "event engine", is this something you threw together for this question or is it something more fleshed out that you could share with us (maybe in an article with examples of its use)?
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
CMy is non-MFC ? Ok., forget it, I might be wrong......
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
Exactly. He wants a non-MFC solution, which was my first question as to how you were getting the messages to begin with. Your solution looks quite intriguing, but assumes that the messages are already being received in some fashion.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Hi ,
Thanks for the reply.
I certainly have limitations here. I am trying to create
instances of 3rd party Ax( ActiveX ), and hence I am not
able to SubClass it.
Secondly I tried using ON_EVENT_RANGE, but here I don't
know how to detect the Control ID .
Can someone shed more light on this.
Thanks,
Sansky
God is Good, all the Time.
All the Time, God is Good.
|
|
|
|
|
Where Can i find a source code of TabCtrlBar?
i am coming quietly just as i am leaving quietly.
|
|
|
|
|
Hi, i have an owner draw popup menu that always return 0, as if no command was selected. i´m using the TPM_RETURN_CMD flag, and GetLastError also returns 0. So i don´t know where the error can be! If i don´t use the flag the command handlers never get called either.
There is nothing about owner-draw menu´s command notifications on the sdk docs.
I´m not using mfc or wtl just plain sdk ( wanna learn )
Any idea??'
Gabriel
don´t worry drink happy
|
|
|
|
|
I am having a real tough time figuring out where the following is coming from:
The instruction at ... referenced memory at ... The memory could not be read.
THe problem is that the program works fine while I do thing back and forth. What I mean is the same "motion" many times. SOmtimes I close it and open it again. Then this occassionally comes up. What exactly causes this? Is it mainly when you use new ? If you use Cstring etc that should not occur right?
Because this does not happen all the time or at so .. intervals it is so tough to track down.
Thanks for any suggestions.
|
|
|
|
|
it usually means you have a stray pointer somewhere (possibly as a result of using "new")
-c
I don't care, and you can't make me.
|
|
|
|
|
intermittent bugs like this usually mean you have a path thru the code that gets executed very rarely ... check all code paths and the new and deletes
bummer
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
coming soon: situations to avoid #38: "...and the dog was there too?"
|
|
|
|
|
Thanks. I think I found the little beast.
|
|
|
|
|
Hello,
I'd like to know the simplest way by which I can capture the entire screen [I dont want that method where we send a Print-Screen-Key and get it in the clipboard]
Can someone give me some elementary steps. Code not needed unless necessary.
Something like
1. get the DC
2. stretch blt it or whatever
3. now get some oher dc
etc...
My GDI sucks! So pardon the absolute stupidity that this post might seem to reflect in the above 3 lines
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
I haven't tried this, so it may not work, but it sounds plausible :
Get the screen DC ( ::GetDC(NULL) )
Get the size of the screen ( ::GetDeviceCaps(HORZRES); ::GetDeviceCaps(VERTRES); )
Create a compatible memory DC (i'm tired of typing <code> and you said it wasn't required )
Create a compatible bitmap of the same size
Select the bitmap in the memory DC
Blit from the screen DC to the memory DC
--------
People they come together
People they fall apart.
No one can stop us now
'cause we are all made of stars... -- Moby, We are all made of stars
|
|
|
|
|
|
I did this as a demo for one of the chapters in my MFC book. If you want I'll send you the source code.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Thanks Tom. I'd love it if you could mail it to me
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Actually, I'll post the salient code here and mail the entire project to you.
By the way, in case you're wondering why the code is so bunched up, the <pre> tags are screwed up in the forums and don't show the blank lines in the code as they should be rendered.
- In an SDI app, I defined the following global variable in the view class:
CDC* g_pMemoryDC = NULL;
- In a menu handler for screen capture I added the following code. Note that the hiding of the window and sleeping are done just to get the app out of the way so that I can capture the desktop without my app.
if (g_pMemoryDC)
{
delete g_pMemoryDC;
g_pMemoryDC = NULL;
}
g_pMemoryDC = new CDC();
GetParentFrame()->ShowWindow(SW_HIDE);
Sleep(1000);
CDC screenDC;
screenDC.CreateDC("DISPLAY", NULL, NULL, NULL);
int nHeight = screenDC.GetDeviceCaps(HORZRES);
int nWidth = screenDC.GetDeviceCaps(VERTRES);
CBitmap bitmap;
g_pMemoryDC->CreateCompatibleDC(&screenDC);
bitmap.CreateCompatibleBitmap(&screenDC, nWidth, nHeight);
g_pMemoryDC->SelectObject(&bitmap);
g_pMemoryDC->BitBlt(0, 0, nWidth, nHeight, &screenDC, 0, 0, SRCCOPY);
GetParentFrame()->ShowWindow(SW_SHOW);
Invalidate();
- In the OnDraw, I add the following.
if (g_pMemoryDC)
{
CClientDC clientDC(this);
int nWidth = g_pMemoryDC->GetDeviceCaps(HORZRES);
int nHeight = g_pMemoryDC->GetDeviceCaps(VERTRES);
clientDC.BitBlt(0, 0, nWidth, nHeight, g_pMemoryDC, 0, 0, SRCCOPY);
}
That's all there is to it!
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom Archer wrote:
That's all there is to it!
Thanks a LOT Tom. Now I understand why you are a successful author. Cause you write readable code. Of all the various examples I saw on the net, this one is the clearest and simplest.
Thanks again
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
No problem, Nish. Thanks for the kinds words.
I'm actually working on my demo now and sent you the bare bones bit you needed. When I get finished it will have a capture settings dialog for things like countdown interval in seconds and let you specify if you want the app to beep during the countdown. I'll also include my ImageObject library so that the image can then be saved to JPG or GIF format once captured. It won't be a terribly fancy app, but a neat little demo nonetheless.
Let me know if you're interested and I'll send it to you Monday.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom, do you have a sample that (optionally) includes the mouse cursor in the capture? I expect this would be done by BitBlt'ing the image of the cursor at the appropriate location.
Btw, would it be possible to post your demo at CP? I'm sure a lot of folks (me included) would love to see it!
Thanks!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|