FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ToolBarButton.click Event

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
Dax89



Joined: 10 Aug 2009
Posts: 2

PostPosted: Sat Nov 07, 2009 10:54 am    Post subject: ToolBarButton.click Event Reply with quote

Hi!

I have saw that the toolbar button "click" event is handled in the ToolBar control.

So, I had an idea, why don't make a ToolBarButton.click event?
The implementation is pretty simple (I have made it in my old GUI library and it worked):

When we add a button in the ToolBar, the TBBUTTON.dwData member holds his instance of ToolBarButton

Code:

TBBUTTON tbn;

...
tbn.dwData = cast(DWORD)cast(void*)cast(ToolBarButton)tb;
...


And, when the parent control receives a WM_COMMAND with the handle come from the toolbar control, we check che clicked button index:

Code:

POINT pt;
DWORD pos = GetMessagePos();

pt.x = LOWORD(pos);
pt.y = HIWORD(pos);

pt = ScreenToClient(this.handle, &pt);

int index = SendMessage(cast(HANDLE)lParam, TB_HITTEST, 0, cast(LPARAM)&pt);

if(index != -1)
{
   TBBUTTON tbn;

   SendMessage(cast(HANDLE)lParam, TB_GETBUTTON, index, cast(LPARAM)&tbn);
   ToolBarButton btn = cast(ToolBarButton)cast(void*)tbn.dwData;

   if(btn!is null)
   {
      btn.click(EventArgs.empty);
   }               
}


Finally:

Code:

ToolBarNutton tBtn = new ToolBarButton();
tBtn.click ~= &this.myBtnClicked;


I hope it is useful!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group