the following is an attempt to address the issue of making image buttons themed when run in xp. this has been a frequent request on this forum, but hasn’t yet been answered. i actually just draw red text, but bitblting an image onto a button would be nearly as easy.
don’t get too excited though, because my code doesn’t yet ‘hotlight’ the button by adding an orange border when the mouse cursor is on it. can anyone suggest why the %wm_drawitem message never seems to be received with the %ods_hotlight flag set?
the code assumes that there is an xp manifest in the resource file. calling isthemeactive does not appear to be necessary because openthemedata only returns a handle if the program is running under xp and the style chosen is themed (i.e. not ‘windows classic’).
theme.inc is by rosa meltronco and is the bottom half of the code posted at: http://www.powerbasic.com/support/pb...ad.php?t=23846
don’t get too excited though, because my code doesn’t yet ‘hotlight’ the button by adding an orange border when the mouse cursor is on it. can anyone suggest why the %wm_drawitem message never seems to be received with the %ods_hotlight flag set?
the code assumes that there is an xp manifest in the resource file. calling isthemeactive does not appear to be necessary because openthemedata only returns a handle if the program is running under xp and the style chosen is themed (i.e. not ‘windows classic’).
theme.inc is by rosa meltronco and is the bottom half of the code posted at: http://www.powerbasic.com/support/pb...ad.php?t=23846
Code:
#resource "themed" ‘includes xml manifest file #include "win32api.inc" #include "theme.inc" ‘by rosa meltronco callback function ownerdrawproc select case cbmsg case %wm_drawitem 'owner draw buttons dim t as drawitemstruct ptr dim txt$, r as rect, htheme as dword, istate as long t=cblparam r= @t.rcitem htheme= openthemedata(cbhndl, "button") if htheme then 'xp theme control send cbhndl,cbwparam,%wm_erasebkgnd,@t.hdc,0 'avoids button acquiring square corners after being pressed istate=1 ' default state = %minbs_normal if (@t.itemstate and %ods_inactive) then istate=5 if (@t.itemstate and %ods_disabled) then istate=4 if (@t.itemstate and %ods_hotlight) then istate=2 ' %minbs_hot if (@t.itemstate and %ods_selected) then istate=3 ' %minbs_pushed call drawthemebackground(htheme, @t.hdc, 1, istate, @t.rcitem, byval %null) call closethemedata(htheme) else 'not xp or not themed if(@t.itemstate and %ods_selected) then call drawframecontrol(byval @t.hdc,@t.rcitem,%dfc_button,%dfcs_buttonpush or %dfcs_pushed) r.ntop=r.ntop+2 : r.nleft=r.nleft+2 'move the text 1 pixel when button pressed else call drawframecontrol(byval @t.hdc,@t.rcitem,%dfc_button,%dfcs_buttonpush) end if end if 'we've drawn the button - now put text or graphics onto it control get text cbhndl,cbctl to txt$ settextcolor @t.hdc,%red setbkmode @t.hdc,%transparent drawtext @t.hdc,bycopy txt$,-1,r,%dt_singleline or %dt_center or %dt_vcenter function=%true end select end function function pbmain local hdlg as dword dialog new 0,"themed owner draw buttons",0,0,150,100,%ws_caption or %ws_sysmenu to hdlg control add button, hdlg, 100, "owner draw 1",5,20,50,14 ,%ws_tabstop or %bs_ownerdraw control add button, hdlg, 101, "owner draw 2",5,40,50,24 ,%ws_tabstop or %bs_ownerdraw control add button, hdlg, 102, "standard",5,80,50,14 'standard button for comparison dialog show modal hdlg, call ownerdrawproc end function
Comment