Dax89
Joined: 10 Aug 2009 Posts: 2
|
Posted: Sat Nov 07, 2009 10:54 am Post subject: ToolBarButton.click Event |
|
|
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! |
|