struct CMyBtn{
  dword vtbl;//ITlbButtonVtbl

  CMyBtn();
  ~CMyBtn();

  dword m_ObjRefCount;

  dword m_container;//ITlbContainer* m_container;
  RECT  m_rc;
  dword m_ID;

  dword QueryInterface(dword riid, ppReturn);
  dword AddRef();
  dword Release();
  dword Load(dword data);
  dword Save(dword data);
  dword SetRect(dword rcItem);
  dword SetContainer(dword cont);
  dword SetID(int btnID);
  dword Draw(dword hDC, dword rcItem);
  dword OnMouseOver(long keys, int x, int y);
  dword OnMouseLeave(long keys);
  dword OnMouseEnter(long keys, int x, int y);
  dword Create(dword data);
  dword StateChanged(int state, int needRedraw);
  dword OnLButtonDown(long key, int x, int y);
  dword OnLButtonUp(long key, int x, int y);
  dword Run(void);
  dword DoAction(int action);
  dword SetName(dword szName);
  int   QueryContextMenu(dword hMenu, int index, int cmdFirst, int cmdLast);
  dword InvokeCommand(int ID);
  dword SetLCID(dword dwLCID, dword hResModule);
  dword GetIconLocation(dword szLocation);
  dword SetIconLocation(dword szLocation);
  dword GetButtonInfo(dword btninfo);
  dword Invoke(dword id, dword wParam, dword lParam);
};

CMyBtn::~CMyBtn(){
  g_DllRefCount--;
}

dword CMyBtn::AddRef(){
  $push ESI
  m_ObjRefCount++;
  EAX=m_ObjRefCount;
  $pop ESI
}

dword CMyBtn::Release(){
  $push ESI
  m_ObjRefCount--;
  EAX=m_ObjRefCount;
  IF(!EAX)delete this CMyBtn;
  $pop ESI;
}

dword CMyBtn::QueryInterface(dword riid, ppReturn){
  $pushad
  DSDWORD[ppReturn] = NULL;
  IF(IsEqualIID(riid, #IID_IUnknown))
  ||(IsEqualIID(riid, #IID_ITlbButton)){
    DSDWORD[ppReturn] = this;
    AddRef();//COMETHOD(this,#IUnknownVtbl.AddRef);//(*(LPUNKNOWN*)ppReturn)->AddRef();
    $popad
    RETURN S_OK;
  }
  $popad
  return E_NOINTERFACE;
}

//////////////////////////////////////////////////////////////////////
// ITlbButton methods
//////////////////////////////////////////////////////////////////////


// Load parameters for button
dword CMyBtn::Load(dword data){//IStream *data
  //COMETHOD(data, #IStream, addr, size, cbreaded)
  return S_OK;
}

// Save button parameters
dword CMyBtn::Save(dword data){//IStream *data
  //COMETHOD(data, #IStream, addr, size, cbwritten)
  return S_OK;
}

// Sets button rectangle
dword CMyBtn::SetRect(dword rcItem){
  $pushad
  CopyMemory(#m_rc,rcItem,sizeof(RECT));
  $popad
  return S_OK;
}

// Set button container
// NOTE: do not call AddRef to store container pointer
dword CMyBtn::SetContainer(dword cont){
  $push ESI;
  m_container = cont;
  $pop ESI;
  return S_OK;
}

dword CMyBtn::SetID(int btnID){
  $push ESI
  m_ID = btnID;
  $pop ESI
  return S_OK;
}

dword CMyBtn::Draw(dword hDC, dword rcItem){
  return S_FALSE;
}

dword CMyBtn::OnMouseOver(long keys, int x, int y){
  return S_OK;
}

dword CMyBtn::OnMouseLeave(long keys){
  return S_OK;
}

dword CMyBtn::OnMouseEnter(long keys, int x, int y){
  return S_OK;
}

dword CMyBtn::Create(dword data){//IStream* data
  dword hResult=S_FALSE;
  $pushad
  IF(m_container){
//    HWND hWndBand = m_container->GetBandWND();
//    CPropsDlg dlg;
//    memcpy(dlg.m_data, m_data, sizeof(m_data));
//    dlg.m_showCPU = m_showCPU;
//    if(dlg.DoModal(hWndBand) == IDOK){
//       m_showCPU = dlg.m_showCPU;
//       memcpy(m_data, dlg.m_data, sizeof(m_data));
//       if(m_container){
//         m_container->UpdateButtonInfo(UPDATE_REDRAW);
//       }
//       return Save(data);
//    }
  }
  $popad
return S_OK;//++++++++++++++++++++++++++++++
  return hResult;
}

dword CMyBtn::StateChanged(int state, int needRedraw){
  EAX=needRedraw;DSDWORD[EAX]=TRUE;//needRedraw[0] = TRUE;
  return S_OK;
}

dword CMyBtn::OnLButtonDown(long key, int x, int y){
  return S_FALSE;
}

dword CMyBtn::OnLButtonUp(long key, int x, int y){
  return S_FALSE;
}

dword CMyBtn::Run(){
  $pushad;
  CoFreeUnusedLibraries();
  MessageBeep(MB_OK);
  $popad;
  return S_OK;
}

dword CMyBtn::DoAction(int action){
  dword hResult=S_OK;
  $pushad
  //CTMS_PROPERTIES CTMS_RENAME CTMS_CHANGEICON CTMS_HOVERRUN
  IF(action == CTMS_PROPERTIES){
    IF(m_container){
/*
      HWND hWndBand = m_container->GetBandWND();
      CPropsDlg dlg;
      memcpy(dlg.m_data, m_data, sizeof(m_data));
      dlg.m_showCPU = m_showCPU;
      if(dlg.DoModal(hWndBand) == IDOK)
      {
              m_showCPU = dlg.m_showCPU;
              memcpy(m_data, dlg.m_data, sizeof(m_data));
              if(m_container)
              {
                      m_container->UpdateButtonInfo(UPDATE_REDRAW);
              }
              return m_container->SaveButton();
      }
*/
    }
  }
  $popad
  return hResult;
}

int CMyBtn::QueryContextMenu(dword hMenu, int index, int cmdFirst, int cmdLast){
  return 0;
}

dword CMyBtn::InvokeCommand(int ID){
  return S_OK;
}

dword CMyBtn::SetLCID(dword dwLCID, dword hResModule){
  return S_OK;
}

dword CMyBtn::GetIconLocation(dword szLocation){
  return S_FALSE;
}

dword CMyBtn::SetIconLocation(dword szLocation){
  return S_FALSE;
}

dword CMyBtn::SetName(dword szName){
  //strcpy(m_Name, szName);
  return S_OK;
}

dword CMyBtn::GetButtonInfo(dword btninfo){//BUTTONINFO* btninfo
  $pushad
  EDI=btninfo;
  IF($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_MODEFLAG )
  {
    //EDI.BUTTONINFO.dwModeFlags      вид кнопки:
    //      BTN_FLAG_PLANE          //ненажимаемая кнопка
    //      BTN_FLAG_STOPDRAG       //неперетаскиваемая кнопка
    EDI.BUTTONINFO.dwModeFlags=0;
  }
  IF($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_ACTIONS )
  {
    //EDI.BUTTONINFO.dwActions        реакция на события
    //      CTMS_PROPERTIES
    //      CTMS_RENAME
    //      CTMS_CHANGEICON
    //      CTMS_HOVERRUN
    EDI.BUTTONINFO.dwActions = 0;
  }
//  if($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_SIZE)
//  {
//    EDI.BUTTONINFO.szBtnSize.cx=sizeX;
//    EDI.BUTTONINFO.szBtnSize.cy=sizeY;
//  }
  IF($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_ICON )
  {
//    EDI.BUTTONINFO.hIcon=m_icon1;
    EDI.BUTTONINFO.hIcon=_moduleIcon;
  }
  if($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_SELECTEDICON)
  {
//    EDI.BUTTONINFO.hIcon=m_icon1;
    EDI.BUTTONINFO.hIcon=_moduleIcon;
  }
  IF($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_DESCRIPTION )
  {
    lstrcpy(#EDI.BUTTONINFO.strData,"CoFreeUnusedLibraries");
  }
  IF($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_TEXT )
  {
    lstrcpy(#EDI.BUTTONINFO.strData,"CoFreeUnusedLibraries");
  }
//  if($test EDI.BUTTONINFO.dwMask,BTNINFO_MASK_ACTUALSIZE)
//  {
//    EDI.BUTTONINFO.szBtnSize.cx=sizeX;
//    EDI.BUTTONINFO.szBtnSize.cy=sizeY;
//  }
  $popad
  return S_OK;
}

dword CMyBtn::Invoke(dword id, dword wParam, dword lParam){
  return S_FALSE;
}

dword CMyBtnVtbl=
{ #EAX.CMyBtn.QueryInterface
 ,#EAX.CMyBtn.AddRef
 ,#EAX.CMyBtn.Release
 ,#EAX.CMyBtn.Load
 ,#EAX.CMyBtn.Save
 ,#EAX.CMyBtn.SetRect
 ,#EAX.CMyBtn.SetContainer
 ,#EAX.CMyBtn.SetID
 ,#EAX.CMyBtn.Draw
 ,#EAX.CMyBtn.OnMouseOver
 ,#EAX.CMyBtn.OnMouseLeave
 ,#EAX.CMyBtn.OnMouseEnter
 ,#EAX.CMyBtn.Create
 ,#EAX.CMyBtn.StateChanged
 ,#EAX.CMyBtn.OnLButtonDown
 ,#EAX.CMyBtn.OnLButtonUp
 ,#EAX.CMyBtn.Run
 ,#EAX.CMyBtn.DoAction
 ,#EAX.CMyBtn.SetName
 ,#EAX.CMyBtn.QueryContextMenu
 ,#EAX.CMyBtn.InvokeCommand
 ,#EAX.CMyBtn.SetLCID
 ,#EAX.CMyBtn.GetIconLocation
 ,#EAX.CMyBtn.SetIconLocation
 ,#EAX.CMyBtn.GetButtonInfo
 ,#EAX.CMyBtn.Invoke
};

CMyBtn::CMyBtn(){
  $pushad
  vtbl=#CMyBtnVtbl;
  m_ObjRefCount=1;
  g_DllRefCount++;
  $popad
}
