How to know the down-left coordinate of one of toolbutton in wxToolbar Topic is solved
How to know the down-left coordinate of one of toolbutton in wxToolbar
Hi,
I'm using wxToolbar. Id like to know the down-left coordinate of one of bitmap button in toolbar.
Is there somebody could help me? Thanks!
I'm using wxToolbar. Id like to know the down-left coordinate of one of bitmap button in toolbar.
Is there somebody could help me? Thanks!
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Hi,
What are you trying to do? What is the reason you need this?
Can you show some code?
Thank you.
What are you trying to do? What is the reason you need this?
Can you show some code?
Thank you.
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Oh, I just want to do some trick popup menu for one of clicked toolbutton. I know, there is dropdown menu style for toolbutton, but the bitmap button is also could be clicked. For my special purpose, I don't like this, I want to response menu clicking only.ONEEYEMAN wrote:Hi,
What are you trying to do? What is the reason you need this?
Can you show some code?
Thank you.
I expect the popup position is below of clicked toolbutton and align the left of clicked toolbutton.
For the first toolbutton, it's easy to know its coordinate, just use wxPoint(0,0) and convert this coordinate into parent coordinate. But for other toolbuttons, I couldn't find out a way to get their coordinate in toolbar.
Thanks!
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Catching the mouse clicking position is another way to get coordinate, but it can't always align the left of clicked toolbutton.
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Hi,
You mean you want to distinguish between the left and right clicks?
Thank you.
You mean you want to distinguish between the left and right clicks?
Thank you.
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
No, I want to get the coordinate of clicked(left mouse) toolbutton, and I'm meant to popup a menu at the below of toolbutton with left alignment to toolbutton.ONEEYEMAN wrote:Hi,
You mean you want to distinguish between the left and right clicks?
Thank you.
dropdown style is not my desire, the reason I've said in above post.
Thanks!
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Hi,
But it should produce the same event naturally and unless you really want to have a different behaviour I don't see a point.
Also, did you try to check the toolbar sample? Does it work for you? If not - how can I see the issue?
And finally - what is your target OS and wx version?
Thank you.
OK, so you mean to differentiate between the click on the tool and click on the dropdown?I know, there is dropdown menu style for toolbutton, but the bitmap button is also could be clicked.
But it should produce the same event naturally and unless you really want to have a different behaviour I don't see a point.
Also, did you try to check the toolbar sample? Does it work for you? If not - how can I see the issue?
And finally - what is your target OS and wx version?
Thank you.
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Well, after looking at the wxToolBar API (and its MSW source), I believe it is not possible (unless using horrible hacks such as iterative calls to FindToolByPosition).
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
There is no function in the public API that does this.
Under MSW, wx uses this helper function internally. It's not public, so you'd have to copy the code in order to use it.
Under MSW, wx uses this helper function internally. It's not public, so you'd have to copy the code in order to use it.
Code: Select all
static RECT wxGetTBItemRect(HWND hwnd, int index, int id = wxID_NONE)
{
RECT r;
// note that we use TB_GETITEMRECT and not TB_GETRECT because the latter
// only appeared in v4.70 of comctl32.dll
if ( !::SendMessage(hwnd, TB_GETITEMRECT, index, (LPARAM)&r) )
{
// This call can return false status even when there is no real error,
// e.g. for a hidden button, so check for this to avoid spurious logs.
const DWORD err = ::GetLastError();
if ( err != ERROR_SUCCESS )
{
bool reportError = true;
if ( id != wxID_NONE )
{
const LRESULT state = ::SendMessage(hwnd, TB_GETSTATE, id, 0);
if ( state != -1 && (state & TBSTATE_HIDDEN) )
{
// There is no real error to report after all.
reportError = false;
}
else // It is not hidden.
{
// So it must have been a real error, report it with the
// original error code and not the one from TB_GETSTATE.
::SetLastError(err);
}
}
if ( reportError )
wxLogLastError(wxT("TB_GETITEMRECT"));
}
::SetRectEmpty(&r);
}
return r;
}
Use the source, Luke!
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Yes, I didn't find it out, too. Thank you PB.PB wrote:Well, after looking at the wxToolBar API (and its MSW source), I believe it is not possible (unless using horrible hacks such as iterative calls to FindToolByPosition).
Re: How to know the down-left coordinate of one of toolbutton in wxToolbar
Oh, It's so trick. Thanks you, doublemax!doublemax wrote:There is no function in the public API that does this.
Under MSW, wx uses this helper function internally. It's not public, so you'd have to copy the code in order to use it.Code: Select all
static RECT wxGetTBItemRect(HWND hwnd, int index, int id = wxID_NONE) { RECT r; // note that we use TB_GETITEMRECT and not TB_GETRECT because the latter // only appeared in v4.70 of comctl32.dll if ( !::SendMessage(hwnd, TB_GETITEMRECT, index, (LPARAM)&r) ) { // This call can return false status even when there is no real error, // e.g. for a hidden button, so check for this to avoid spurious logs. const DWORD err = ::GetLastError(); if ( err != ERROR_SUCCESS ) { bool reportError = true; if ( id != wxID_NONE ) { const LRESULT state = ::SendMessage(hwnd, TB_GETSTATE, id, 0); if ( state != -1 && (state & TBSTATE_HIDDEN) ) { // There is no real error to report after all. reportError = false; } else // It is not hidden. { // So it must have been a real error, report it with the // original error code and not the one from TB_GETSTATE. ::SetLastError(err); } } if ( reportError ) wxLogLastError(wxT("TB_GETITEMRECT")); } ::SetRectEmpty(&r); } return r; }