Structure IconButton 
  oldWndProc.l 
  icon.l 
EndStructure 
#BS_LEFT         =    $00000100 
#BS_RIGHT        =    $00000200 
#BS_TOP          =    $00000400 
#BS_BOTTOM       =    $00000800 
#DI_NORMAL       =    $00000003 
#iconsize        =    16 
Procedure DrawIconOnButton(hWnd,*p.IconButton,clicked) 
  hDC = GetDC_(hWnd) 
  GetClientRect_(hWnd,rect.RECT) 
  style = GetWindowLong_(hWnd,#GWL_STYLE) 
  If style & #BS_LEFT 
    x = rect\right - 10 - #iconsize 
    y = rect\bottom/2 - #iconsize/2 
  ElseIf style & #BS_RIGHT 
    x = 10 
    y = rect\bottom/2 - #iconsize/2 
  ElseIf style & #BS_TOP 
    x = rect\right/2 - #iconsize/2 
    y = rect\bottom - 5 - #iconsize 
  ElseIf style & #BS_BOTTOM 
    x = rect\right/2 - #iconsize/2 
    y = 5 
  EndIf 
  If clicked 
    x+1 
    y+1 
  EndIf 
  If GetWindowLong_(hWnd,#GWL_STYLE) & #WS_DISABLED 
    DrawState_(hDC,GetStockObject_(#LTGRAY_BRUSH),0,*p\icon,0,x+1,y+1,#iconsize,#iconsize,#DST_ICON|#DSS_MONO) 
    DrawState_(hDC,GetStockObject_(#GRAY_BRUSH)  ,0,*p\icon,0,x  ,y  ,#iconsize,#iconsize,#DST_ICON|#DSS_MONO) 
  Else 
    DrawIconEx_(hDC,x,y,*p\icon,#iconsize,#iconsize,1,0,#DI_NORMAL) 
  EndIf 
  ReleaseDC_(hWnd,hDC) 
EndProcedure 
Procedure IconButtonProc(hWnd,Msg,wParam,lParam) 
  *p.IconButton = GetWindowLong_(hWnd,#GWL_USERDATA) 
  If *p 
    If *p\oldWndProc 
      retval = CallWindowProc_(*p\oldWndProc,hWnd,Msg,wParam,lParam) 
      If Msg = #WM_PAINT And *p\icon 
        state = SendMessage_(hWnd,#BM_GETSTATE,0,0) 
        If state = #BST_CHECKED Or state=#BST_PUSHED 
          clicked=1 
        EndIf 
        DrawIconOnButton(hWnd,*p,clicked) 
      ElseIf Msg = #WM_LBUTTONDOWN Or Msg = #WM_LBUTTONDBLCLK 
        DrawIconOnButton(hWnd,*p,1) 
      ElseIf Msg = #WM_LBUTTONUP 
        DrawIconOnButton(hWnd,*p,0) 
      ElseIf Msg = #WM_MOUSEMOVE And wParam = #MK_LBUTTON 
        GetWindowRect_(hWnd,rect.RECT) 
        GetCursorPos_(pt.POINT) 
        If PtInRect_(@rect,pt\x|(pt\y<<32)) 
          clicked = 1 
        EndIf 
        DrawIconOnButton(hWnd,*p,clicked) 
      EndIf 
      ProcedureReturn retval 
    EndIf 
  EndIf 
  ProcedureReturn DefWindowProc_(hWnd,Msg,wParam,lParam) 
EndProcedure 
Procedure IconButtonGadget(Gadget,x,y,w,h,text$,icon,flags) 
  btn = ButtonGadget(Gadget,x,y,w,h,text$,flags) 
  If btn 
    *p.IconButton = AllocateMemory(SizeOf(IconButton)) 
    If *p 
      SetWindowLong_(GadgetID(Gadget),#GWL_USERDATA,*p) 
      *p\icon       = icon 
      *p\oldWndProc = SetWindowLong_(GadgetID(Gadget),#GWL_WNDPROC,@IconButtonProc()) 
    Else 
      FreeGadget(Gadget) 
      btn=0 
    EndIf 
  EndIf 
  ProcedureReturn btn 
EndProcedure 
SystemPath.s=Space(255)
Result=GetSystemDirectory_(SystemPath.s,255)
OpenWindow(0,0,0,140,80,"",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
 IconButtonGadget(0,20,20,80,24,"Кнопка  ",ExtractIcon_(0,SystemPath+"\SetupAPI.dll",4),#BS_RIGHT) 
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow