How to get ID of a button & bitmap in a BitmapButton???

Hii all,
I am using BitmapButtons in my application and I want to get the ID of the 
button aswell as the bitmap placed on it using a CWnd pointer to it.If this 
is not feasible please do help me with how to get a handler to button & 
bitmap so that I could use the GetDlgCtrlID() function to retrieve the 
button/bitmap ID’s.

A big Thanxxxxxxxxxxxx in advance,
Gov.
-----
0
Utf
3/6/2006 4:26:40 AM
vc.mfc 33608 articles. 0 followers. Follow

15 Replies
616 Views

Similar Articles

[PageSpeed] 25

Well if you have a CWnd pointer to the Button. (I think you answered your
own question on this one)
pButton->GetDlgCtrlID();

or
GetDlgCtrlID(pButton->m_hWnd);

As far as the Bitmap ID goes, that information is not stored in the button
class.
But what you can do is derive your own class from CBitmapButton, and create
a function that would load the bitmaps for you. Call that function instead
of LoadBitmaps(), and store the ID's in your button class, so that you can
retrive them later when asked.

AliR.

"Gov" <prabha.govind@microsoft(.)com> wrote in message
news:BAEBE5B0-4012-4463-8530-CE377A86B8E7@microsoft.com...
> Hii all,
> I am using BitmapButtons in my application and I want to get the ID of the
> button aswell as the bitmap placed on it using a CWnd pointer to it.If
this
> is not feasible please do help me with how to get a handler to button &
> bitmap so that I could use the GetDlgCtrlID() function to retrieve the
> button/bitmap ID's.
>
> A big Thanxxxxxxxxxxxx in advance,
> Gov.
> -----


0
AliR3470 (3236)
3/6/2006 5:25:34 PM
Well, the simplest thing to do is that, since to get a CBitmapButton, you have to have a
CBitmapButton variable, you can just call GetDlgCtrlID on it.  So you already have a
reference to it.  Now the bitmap ID is pretty meaningless.  First, once a bitmap is set,
there *is* no bitmap ID.  In fact, if you read the code for CBitmapButton::LoadBitmaps,
you will see that the bitmap names/IDs are not retained in any way whatsoever.  Therefore,
there is no way to retrieve the bitmap information.
					joe

On Sun, 5 Mar 2006 20:26:40 -0800, Gov <prabha.govind@microsoft(.)com> wrote:

>Hii all,
>I am using BitmapButtons in my application and I want to get the ID of the 
>button aswell as the bitmap placed on it using a CWnd pointer to it.If this 
>is not feasible please do help me with how to get a handler to button & 
>bitmap so that I could use the GetDlgCtrlID() function to retrieve the 
>button/bitmap ID�s.
>
>A big Thanxxxxxxxxxxxx in advance,
>Gov.
>-----
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
3/8/2006 1:22:16 AM
So if there is no way we could get the ID of the Bitmap on top of the 
BitmapButton …how can we tacked the situation in which we have to compare the 
bitmap on top of the BitmapButton to the biptmap we have in our resource.
-- 
Gov.


"Joseph M. Newcomer" wrote:

> Well, the simplest thing to do is that, since to get a CBitmapButton, you have to have a
> CBitmapButton variable, you can just call GetDlgCtrlID on it.  So you already have a
> reference to it.  Now the bitmap ID is pretty meaningless.  First, once a bitmap is set,
> there *is* no bitmap ID.  In fact, if you read the code for CBitmapButton::LoadBitmaps,
> you will see that the bitmap names/IDs are not retained in any way whatsoever.  Therefore,
> there is no way to retrieve the bitmap information.
> 					joe
> 
> On Sun, 5 Mar 2006 20:26:40 -0800, Gov <prabha.govind@microsoft(.)com> wrote:
> 
> >Hii all,
> >I am using BitmapButtons in my application and I want to get the ID of the 
> >button aswell as the bitmap placed on it using a CWnd pointer to it.If this 
> >is not feasible please do help me with how to get a handler to button & 
> >bitmap so that I could use the GetDlgCtrlID() function to retrieve the 
> >button/bitmap ID’s.
> >
> >A big Thanxxxxxxxxxxxx in advance,
> >Gov.
> >-----
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> 
0
Utf
3/8/2006 4:35:34 AM
Gov wrote:
> So if there is no way we could get the ID of the Bitmap on top of the 
> BitmapButton …how can we tacked the situation in which we have to compare the 
> bitmap on top of the BitmapButton to the biptmap we have in our resource.

You can derive a class from CBitmapButton and use your derived class. 
Your derived class can have additional variables and code to provide 
whatever new things you need.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
3/8/2006 1:08:28 PM
You could load the bitmap from the resource, get its bits, get the bitmap from the button,
get its bits, and compare the bits.  Just study the code of CBitmapButton, and you will
see that the bitmap ID is discarded and never becomes part of the information retained by
the button.  Bitmaps do not have any identity; you could just as easily set the bitmap
from the program at runtime (for example, in my "Better Bitmap Button class" on my MVP
Tips site, I do exactly that: if there is no "disabled" bitmap, I synthesize one).  For
that matter, feel free to use my class; then you can modify it to retain the bitmap IDs if
you want.
					joe

On Tue, 7 Mar 2006 20:35:34 -0800, Gov <prabha.govind@microsoft(.)com> wrote:

>So if there is no way we could get the ID of the Bitmap on top of the 
>BitmapButton �how can we tacked the situation in which we have to compare the 
>bitmap on top of the BitmapButton to the biptmap we have in our resource.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
3/8/2006 8:25:03 PM
I think the only way to do this would be to "remember" the ID, but if that 
were possible then the OP would have probably already done that.  It is 
confusing that bitmaps just become "bits" when they are rendered.  There are 
not really windows with IDs.  Too many confusing things today ...

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:q8fu02tqr773cu6cek73l57negkuc5i38e@4ax.com...
> You could load the bitmap from the resource, get its bits, get the bitmap 
> from the button,
> get its bits, and compare the bits.  Just study the code of CBitmapButton, 
> and you will
> see that the bitmap ID is discarded and never becomes part of the 
> information retained by
> the button.  Bitmaps do not have any identity; you could just as easily 
> set the bitmap
> from the program at runtime (for example, in my "Better Bitmap Button 
> class" on my MVP
> Tips site, I do exactly that: if there is no "disabled" bitmap, I 
> synthesize one).  For
> that matter, feel free to use my class; then you can modify it to retain 
> the bitmap IDs if
> you want.
> joe
>
> On Tue, 7 Mar 2006 20:35:34 -0800, Gov <prabha.govind@microsoft(.)com> 
> wrote:
>
>>So if there is no way we could get the ID of the Bitmap on top of the
>>BitmapButton .how can we tacked the situation in which we have to compare 
>>the
>>bitmap on top of the BitmapButton to the biptmap we have in our resource.
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
tserface (3861)
3/8/2006 10:54:20 PM
Actually, it is not clear why the OP needs to do this at all; the program should already
know what the IDs are, since it did a LoadBitmaps call already.  But the other suggestion
made, to subclass CBitmapButton and override LoadBitmaps, would also work.
				joe

On Wed, 8 Mar 2006 14:54:20 -0800, "Tom Serface" <tserface@msn.com> wrote:

>I think the only way to do this would be to "remember" the ID, but if that 
>were possible then the OP would have probably already done that.  It is 
>confusing that bitmaps just become "bits" when they are rendered.  There are 
>not really windows with IDs.  Too many confusing things today ...
>
>Tom
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:q8fu02tqr773cu6cek73l57negkuc5i38e@4ax.com...
>> You could load the bitmap from the resource, get its bits, get the bitmap 
>> from the button,
>> get its bits, and compare the bits.  Just study the code of CBitmapButton, 
>> and you will
>> see that the bitmap ID is discarded and never becomes part of the 
>> information retained by
>> the button.  Bitmaps do not have any identity; you could just as easily 
>> set the bitmap
>> from the program at runtime (for example, in my "Better Bitmap Button 
>> class" on my MVP
>> Tips site, I do exactly that: if there is no "disabled" bitmap, I 
>> synthesize one).  For
>> that matter, feel free to use my class; then you can modify it to retain 
>> the bitmap IDs if
>> you want.
>> joe
>>
>> On Tue, 7 Mar 2006 20:35:34 -0800, Gov <prabha.govind@microsoft(.)com> 
>> wrote:
>>
>>>So if there is no way we could get the ID of the Bitmap on top of the
>>>BitmapButton .how can we tacked the situation in which we have to compare 
>>>the
>>>bitmap on top of the BitmapButton to the biptmap we have in our resource.
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
3/9/2006 7:59:10 AM
Unless he's trying to get the bitmaps from someone else's window (another 
app found with FindWindow for example?)  Don't know.

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:vsnv02phvnecqf73j58npg1jfr2qt1u7rr@4ax.com...
> Actually, it is not clear why the OP needs to do this at all; the program 
> should already
> know what the IDs are, since it did a LoadBitmaps call already.  But the 
> other suggestion
> made, to subclass CBitmapButton and override LoadBitmaps, would also work.
> joe


0
tserface (3861)
3/9/2006 4:13:51 PM
In that case, the problem has no solution other than the one I first suggested: load the
bitmap resource from the resource segment of the other application (LoadLibraryEx is a
good way to get even a .exe file mapped in) and compare pixels.
					joe

On Thu, 9 Mar 2006 08:13:51 -0800, "Tom Serface" <tserface@msn.com> wrote:

>Unless he's trying to get the bitmaps from someone else's window (another 
>app found with FindWindow for example?)  Don't know.
>
>Tom
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:vsnv02phvnecqf73j58npg1jfr2qt1u7rr@4ax.com...
>> Actually, it is not clear why the OP needs to do this at all; the program 
>> should already
>> know what the IDs are, since it did a LoadBitmaps call already.  But the 
>> other suggestion
>> made, to subclass CBitmapButton and override LoadBitmaps, would also work.
>> joe
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
3/10/2006 2:32:42 AM
Scott McPhillips  Said:-
You can derive a class from CBitmapButton and use your derived class. 
Your derived class can have additional variables and code to provide 
whatever new things you need.

  I am exactly doing the same thing,deriving a CBitmapButon into MyButton 
Class with extra variable to hold the bitmap parameter.But since I am using  
p= (CMyButton*)GetFocus() function to identify the clicked button,which 
returns a CWnd pointer,I am not able to access parameters defined by me. Is 
there a better way to do this, or am I seriously ignorant about some basics. 
Please help.

-- 
Gov.


"Joseph M. Newcomer" wrote:

> In that case, the problem has no solution other than the one I first suggested: load the
> bitmap resource from the resource segment of the other application (LoadLibraryEx is a
> good way to get even a .exe file mapped in) and compare pixels.
> 					joe
> 
> On Thu, 9 Mar 2006 08:13:51 -0800, "Tom Serface" <tserface@msn.com> wrote:
> 
> >Unless he's trying to get the bitmaps from someone else's window (another 
> >app found with FindWindow for example?)  Don't know.
> >
> >Tom
> >
> >"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
> >news:vsnv02phvnecqf73j58npg1jfr2qt1u7rr@4ax.com...
> >> Actually, it is not clear why the OP needs to do this at all; the program 
> >> should already
> >> know what the IDs are, since it did a LoadBitmaps call already.  But the 
> >> other suggestion
> >> made, to subclass CBitmapButton and override LoadBitmaps, would also work.
> >> joe
> >
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> 
0
Utf
3/10/2006 8:32:27 AM
Gov wrote:
> Scott McPhillips  Said:-
> You can derive a class from CBitmapButton and use your derived class. 
> Your derived class can have additional variables and code to provide 
> whatever new things you need.
> 
>   I am exactly doing the same thing,deriving a CBitmapButon into MyButton 
> Class with extra variable to hold the bitmap parameter.But since I am using  
> p= (CMyButton*)GetFocus() function to identify the clicked button,which 
> returns a CWnd pointer,I am not able to access parameters defined by me. Is 
> there a better way to do this, or am I seriously ignorant about some basics. 
> Please help.
> 

It's not clear why you even need to use code to identify the clicked 
button.  The clicked button should be inherently known to the click 
message handler because the button ID is part of the message map.  So 
the message handler is only called for a click on a particular button. 
How are you detecting the click message?

Nevertheless, suppose you have m_MyButton member variable, then 
something like this may help do what you seem to be trying:

if (&m_MyButton == GetFocus())
   if( m_MyButton.extravariable == something)
      whatever...

-- 
Scott McPhillips [VC++ MVP]

0
Scott
3/10/2006 1:54:55 PM
If you are doing this in the same app as the bitmap button is defined, and running in the
same thread as the GUI, and you have defined the button as a CMyBitmapButton, then
GetFocus() should find the pointer to the class in the permanent handle map, and give you
a pointer to your associated CMyBitmapButton object.

If the bitmap button is in some other application, all bets are off, and the only solution
is to then have a user-defined message which you can send the button which returns the
information, e.g.,
	id = button->SendMessage(UWM_QUERY_BITMAP);
or something like that.
					joe

On Fri, 10 Mar 2006 00:32:27 -0800, Gov <prabha.govind@microsoft(.)com> wrote:

>Scott McPhillips  Said:-
>You can derive a class from CBitmapButton and use your derived class. 
>Your derived class can have additional variables and code to provide 
>whatever new things you need.
>
>  I am exactly doing the same thing,deriving a CBitmapButon into MyButton 
>Class with extra variable to hold the bitmap parameter.But since I am using  
>p= (CMyButton*)GetFocus() function to identify the clicked button,which 
>returns a CWnd pointer,I am not able to access parameters defined by me. Is 
>there a better way to do this, or am I seriously ignorant about some basics. 
>Please help.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
3/10/2006 6:58:02 PM
Thank you Scott,Joe,Tom,AliRfor for  ur great help and patience!
nd a special thanx to Scott And Joe.
Thank you very much! :-)
-- 
Gov.


"Joseph M. Newcomer" wrote:

> If you are doing this in the same app as the bitmap button is defined, and running in the
> same thread as the GUI, and you have defined the button as a CMyBitmapButton, then
> GetFocus() should find the pointer to the class in the permanent handle map, and give you
> a pointer to your associated CMyBitmapButton object.
> 
> If the bitmap button is in some other application, all bets are off, and the only solution
> is to then have a user-defined message which you can send the button which returns the
> information, e.g.,
> 	id = button->SendMessage(UWM_QUERY_BITMAP);
> or something like that.
> 					joe
> 
> On Fri, 10 Mar 2006 00:32:27 -0800, Gov <prabha.govind@microsoft(.)com> wrote:
> 
> >Scott McPhillips  Said:-
> >You can derive a class from CBitmapButton and use your derived class. 
> >Your derived class can have additional variables and code to provide 
> >whatever new things you need.
> >
> >  I am exactly doing the same thing,deriving a CBitmapButon into MyButton 
> >Class with extra variable to hold the bitmap parameter.But since I am using  
> >p= (CMyButton*)GetFocus() function to identify the clicked button,which 
> >returns a CWnd pointer,I am not able to access parameters defined by me. Is 
> >there a better way to do this, or am I seriously ignorant about some basics. 
> >Please help.
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> 
0
Utf
3/15/2006 6:12:26 AM
Joe  Said:-
Just study the code of CBitmapButton, and you will
see that the bitmap ID is discarded and never becomes part of the 
information retained by
the button.  Bitmaps do not have any identity; you could just as easily set 
the bitmap
from the program at runtime

I am new to vc and it would be of great help if u could share how u got this 
info from….where do we get such internal details?

-- 
Gov.


"Gov" wrote:

> Thank you Scott,Joe,Tom,AliRfor for  ur great help and patience!
> nd a special thanx to Scott And Joe.
> Thank you very much! :-)
> -- 
> Gov.
> 
> 
> "Joseph M. Newcomer" wrote:
> 
> > If you are doing this in the same app as the bitmap button is defined, and running in the
> > same thread as the GUI, and you have defined the button as a CMyBitmapButton, then
> > GetFocus() should find the pointer to the class in the permanent handle map, and give you
> > a pointer to your associated CMyBitmapButton object.
> > 
> > If the bitmap button is in some other application, all bets are off, and the only solution
> > is to then have a user-defined message which you can send the button which returns the
> > information, e.g.,
> > 	id = button->SendMessage(UWM_QUERY_BITMAP);
> > or something like that.
> > 					joe
> > 
> > On Fri, 10 Mar 2006 00:32:27 -0800, Gov <prabha.govind@microsoft(.)com> wrote:
> > 
> > >Scott McPhillips  Said:-
> > >You can derive a class from CBitmapButton and use your derived class. 
> > >Your derived class can have additional variables and code to provide 
> > >whatever new things you need.
> > >
> > >  I am exactly doing the same thing,deriving a CBitmapButon into MyButton 
> > >Class with extra variable to hold the bitmap parameter.But since I am using  
> > >p= (CMyButton*)GetFocus() function to identify the clicked button,which 
> > >returns a CWnd pointer,I am not able to access parameters defined by me. Is 
> > >there a better way to do this, or am I seriously ignorant about some basics. 
> > >Please help.
> > Joseph M. Newcomer [MVP]
> > email: newcomer@flounder.com
> > Web: http://www.flounder.com
> > MVP Tips: http://www.flounder.com/mvp_tips.htm
> > 
0
Utf
3/15/2006 6:44:26 AM
Gov wrote:
> Joe  Said:-
> Just study the code of CBitmapButton, and you will
> see that the bitmap ID is discarded and never becomes part of the 
> information retained by
> the button.  Bitmaps do not have any identity; you could just as easily set 
> the bitmap
> from the program at runtime
> 
> I am new to vc and it would be of great help if u could share how u got this 
> info from….where do we get such internal details?
> 

The Visual C++ setup CD gives you an option to install the MFC source 
code.  Probably under "custom setup" or a similar choice.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
3/15/2006 1:32:38 PM
Reply:

Similar Artilces: