しかし、HSPの objimage 命令のようにマウスオーバー時の描画は
どのようにすれば良いのでしょうか?
//------------------------------------------------------------------------------ // ボタンのオーナードロー by 科学太郎 //============================================================================== // 新規作成日:2018-08-21 (火) 17:22:00 // 最終更新日:2018-08-21 (火) 20:28:00 //------------------------------------------------------------------------------ #include "Gdi32.as" #include "User32.as" //-------------------------------------- // 記号定数(API定数) //-------------------------------------- #const global NULL 0 #const global WM_DRAWITEM $0000002B #const global WM_MEASUREITEM $0000002C # #const global GWL_STYLE $FFFFFFF0 #const global BS_OWNERDRAW $0000000B # #const global SWP_NOSIZE $00000001 #const global SWP_NOMOVE $00000002 #const global SWP_NOZORDER $00000004 #const global SWP_FRAMECHANGED $00000020 # #const global BS_ICON $00000040 #const global BM_SETIMAGE $000000F7 #const global IMAGE_ICON $00000001 # #const global SRCCOPY $00CC0020 //-------------------------------------- // 列挙定数(MEASUREITEMSTRUCT) //-------------------------------------- #enum mis_CtlType=0 #enum mis_CtlID #enum mis_itemID #enum mis_itemWidth #enum mis_itemHeight #enum mis_itemData #enum DIM_MEASUREITEMSTRUCT #enum SIZE_MEASUREITEMSTRUCT=(DIM_MEASUREITEMSTRUCT*4) //-------------------------------------- // 記号定数(MEASUREITEMSTRUCT.CtlType) //-------------------------------------- #const global ODT_MENU $00000001 #const global ODT_LISTBOX $00000002 #const global ODT_COMBOBOX $00000003 #const global ODT_BUTTON $00000004 #const global ODT_STATIC $00000005 #const global ODT_HEADER $00000064 #const global ODT_TAB $00000065 #const global ODT_LISTVIEW $00000066 //-------------------------------------- // 列挙定数(DRAWITEMSTRUCT) //-------------------------------------- #enum dis_CtlType=0 #enum dis_CtlID #enum dis_itemID #enum dis_itemAction #enum dis_itemState #enum dis_hwndItem #enum dis_hDC #enum dis_rcItem #enum dis_rcLeft=dis_rcItem #enum dis_rcTop #enum dis_rcRight #enum dis_rcBottom #enum dis_itemData #enum DIM_DRAWITEMSTRUCT #enum SIZE_DRAWITEMSTRUCT=(DIM_DRAWITEMSTRUCT*4) //-------------------------------------- // 記号定数(DRAWITEMSTRUCT.itemAction) //-------------------------------------- #const global ODA_DRAWENTIRE $00000001 #const global ODA_SELECT $00000002 #const global ODA_FOCUS $00000004 //-------------------------------------- // 記号定数(DRAWITEMSTRUCT.itemState) //-------------------------------------- #const global ODS_SELECTED $00000001 #const global ODS_GRAYED $00000002 #const global ODS_DISABLED $00000004 #const global ODS_CHECKED $00000008 #const global ODS_FOCUS $00000010 #const global ODS_DEFAULT $00000020 #const global ODS_HOTLIGHT $00000040 #const global ODS_INACTIVE $00000080 #const global ODS_NOACCEL $00000100 #const global ODS_NOFOCUSRECT $00000200 #const global ODS_COMBOBOXEDIT $00001000 //-------------------------------------- // 記号定数(DrawText関数) //-------------------------------------- #const global DT_LEFT $00000000 #const global DT_CENTER $00000001 #const global DT_RIGHT $00000002 #const global DT_TOP $00000000 #const global DT_VCENTER $00000004 #const global DT_BOTTOM $00000008 #const global DT_WORDBREAK $00000010 #const global DT_SINGLELINE $00000020 #const global DT_EXPANDTABS $00000040 #const global DT_TABSTOP $00000080 #const global DT_NOCLIP $00000100 #const global DT_EXTERNALLEADING $00000200 #const global DT_CALCRECT $00000400 #const global DT_NOPREFIX $00000800 #const global DT_INTERNAL $00001000 #const global DT_EDITCONTROL $00002000 #const global DT_PATH_ELLIPSIS $00004000 #const global DT_END_ELLIPSIS $00008000 #const global DT_MODIFYSTRING $00010000 #const global DT_RTLREADING $00020000 #const global DT_WORD_ELLIPSIS $00040000 #const global DT_NOFULLWIDTHCHARBREAK $00080000 #const global DT_HIDEPREFIX $00100000 #const global DT_PREFIXONLY $00200000 //-------------------------------------- // 記号定数(SetBkMode関数) //-------------------------------------- #const global TRANSPARENT $00000001 #const global OPAQUE $00000002 //-------------------------------------- // 列挙定数(ウインドウID) //-------------------------------------- #enum global WID_MAIN=0 #enum global WID_BUTTON //-------------------------------------- // メイン部 //-------------------------------------- *Main ;ボタン・イメージの作成 MakeButtonImage WID_BUTTON,200,50:hDCButton=hDC ;メイン・ウインドウの作成 screen WID_MAIN,640,480,SCREEN_NORMAL|SCREEN_FIXEDSIZE|SCREEN_HIDE syscolor 15:boxf:color:title "ボタンのオーナードロー by 科学太郎" ;設定 oncmd gosub *OnDrawItem, WM_DRAWITEM oncmd gosub *OnMeasureItem, WM_MEASUREITEM ;配置 font "HG明朝E",30 objmode 2 objsize 200,50,60 color $FF,$FF,$FF pos 10,10 repeat 5 button gosub strf("ボタン(No.%d)",cnt+1), *Push SetButtonOwnerDraw stat loop ;表示 gsel WID_MAIN,1 stop //-------------------------------------- // ボタンをオーナードローに設定 //-------------------------------------- #deffunc SetButtonOwnerDraw int _id_ h=objinfo_hwnd(_id_) GetWindowLong h,GWL_STYLE SetWindowLong h,GWL_STYLE,(stat|BS_OWNERDRAW) SetWindowPos h,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED return(_id_) //-------------------------------------- // ボタンにアイコンを設定 //-------------------------------------- #deffunc SetButtonIcon int _id_,int _icon_ h=objinfo_hwnd(_id_) GetWindowLong h,GWL_STYLE SetWindowLong h,GWL_STYLE,(stat|BS_ICON) sendmsg h,BM_SETIMAGE,IMAGE_ICON,_icon_ return(_id_) //-------------------------------------- // WM_MEASUREITEMメッセージの処理 //-------------------------------------- *OnMeasureItem dupptr mis,lParam,SIZE_MEASUREITEMSTRUCT switch(mis.mis_CtlType) case ODT_MENU: :swbreak case ODT_LISTBOX: :swbreak case ODT_COMBOBOX: :swbreak case ODT_BUTTON: :swbreak case ODT_STATIC: :swbreak case ODT_HEADER: :swbreak case ODT_TAB: :swbreak case ODT_LISTVIEW: :swbreak swend return 1 //-------------------------------------- // WM_DRAWITEMメッセージの処理 //-------------------------------------- *OnDrawItem dupptr dis,lParam,SIZE_DRAWITEMSTRUCT sdim szBuff,1024 if(dis.dis_CtlType==ODT_BUTTON){ w=dis(dis_rcRight)-dis(dis_rcLeft) h=dis(dis_rcBottom)-dis(dis_rcTop) ;背景 if(dis(dis_itemState) & ODS_SELECTED){ BitBlt dis(dis_hDC),dis(dis_rcLeft),dis(dis_rcTop),dis(dis_rcRight),dis(dis_rcBottom),hDCButton,w*1,0,SRCCOPY ;選択時 x=2 y=2 } else:if(dis(dis_itemState) & ODS_FOCUS){ BitBlt dis(dis_hDC),dis(dis_rcLeft),dis(dis_rcTop),dis(dis_rcRight),dis(dis_rcBottom),hDCButton,w*2,0,SRCCOPY ;フォーカス時 x=0 y=0 } else{ BitBlt dis(dis_hDC),dis(dis_rcLeft),dis(dis_rcTop),dis(dis_rcRight),dis(dis_rcBottom),hDCButton,w*0,0,SRCCOPY ;通常時 x=0 y=0 } ;文字 n=0 n|=(ginfo_r<<8*0) n|=(ginfo_g<<8*1) n|=(ginfo_b<<8*2) SetTextColor dis(dis_hDC),n SetBkMode dis(dis_hDC),TRANSPARENT OffsetRect varptr(dis.dis_rcItem),x,y GetWindowText dis(dis_hwndItem),varptr(szBuff),1024 DrawText dis(dis_hDC),szBuff,stat,varptr(dis.dis_rcItem),(DT_CENTER|DT_VCENTER|DT_SINGLELINE) } return 1 //-------------------------------------- // ボタン・イメージの作成 //-------------------------------------- #deffunc MakeButtonImage int _id_,int _sx_,int _sy_ buffer(_id_),(_sx_)*3,(_sy_) x=(0) y=(0) w=(_sx_) h=(_sy_)/2 ;描画 color $99,$00,$00:DrawButtonImage(_sx_),(_sy_),$330000,$FF0000 ;通常時 color $00,$99,$00:DrawButtonImage(_sx_),(_sy_),$003300,$00FF00 ;押し下げ時 color $99,$66,$00:DrawButtonImage(_sx_),(_sy_),$552200,$FFCC00 ;マウスオーバー時 return //-------------------------------------- // 1つのボタンを描画 //-------------------------------------- #deffunc DrawButtonImage int _sx_,int _sy_,int _c1_,int _c2_ ;背景 gradf x,y+0,w,h,1,(_c1_),(_c2_) gradf x,y+h,w,h,1,(_c2_),(_c1_) ;外枠 cx=x cy=y ex=x+(_sx_)-1 ey=y+(_sy_)-1 line ex,cy,cx,cy line ex,ey line cx,ey line cx,cy ;次へ x+=(_sx_) return //-------------------------------------- // 空ボタンの処理 //-------------------------------------- *Push return //------------------------------------------------------------------------------ // End of sample311(ボタンのオーナードロー).hsp //------------------------------------------------------------------------------