界面开发之Flat3DButton[2]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 40star 的 blog

const color_btnhighlight = 20

private declare function fillrect lib "user32" (byval hdc as long, lprect as rect, byval hbrush as long) as long

private declare function framerect lib "user32" (byval hdc as long, lprect as rect, byval hbrush as long) as long

private declare function roundrect lib "gdi32" (byval hdc as long, byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long, byval x3 as long, byval y3 as long) as long

'pen api
private declare function createpen lib "gdi32" (byval npenstyle as long, byval nwidth as long, byval crcolor as long) as long
'  pen styles
const ps_solid = 0
const ps_dash = 1                    '  -------
const ps_dot = 2                     '  .......
const ps_dashdot = 3                 '  _._._._
const ps_dashdotdot = 4              '  _.._.._
const ps_null = 5
const ps_insideframe = 6
const ps_userstyle = 7
const ps_alternate = 8
const ps_style_mask = &hf

private declare function movetoex lib "gdi32" (byval hdc as long, byval x as long, byval y as long, lppoint as pointapi) as long

private declare function lineto lib "gdi32" (byval hdc as long, byval x as long, byval y as long) as long

private type pointapi
        x as long
        y as long
end type

private declare function drawtext lib "user32" alias "drawtexta" _
    (byval hdc as long, byval lpstr as string, byval ncount as long, _
    lprect as rect, byval wformat as long) as long

private const dt_singleline = &h20
private const dt_center = &h1
private const dt_vcenter = &h4

private declare function settextcolor lib "gdi32" (byval hdc as long, _
    byval crcolor as long) as long
   
private declare function setbkmode lib "gdi32" (byval hdc as long, _
    byval nbkmode as long) as long
   
private const transparent = 1


private sub drawbutton(byval hwnd as long, byval hdc as long, _
rct as rect, byval nstate as long)

   dim p as pointapi
   dim s as string
   dim hbr as long
   dim hpen as long
   
   hbr = createsolidbrush(getsyscolor(color_btnface))
   selectobject hdc, hbr
   fillrect hdc, rct, hbr
   deleteobject hbr
  
   '画文字时背景为透明状
   setbkmode hdc, transparent
   '得到button的caption
   s = string$(255, 0)
   getwindowtext hwnd, s, 255
   s = left$(s, instr(s, chr$(0)) - 1)
   '根据button的enabled状态进行重画
   if (nstate and ods_disabled) = ods_disabled then
      '画内侧3d效果->亮色
      hpen = createpen(ps_solid, 1, getsyscolor(color_btnhighlight))
      selectobject hdc, hpen
      movetoex hdc, rct.left, rct.top, p
      lineto hdc, rct.right, rct.top
      movetoex hdc, rct.left, rct.top, p
      lineto hdc, rct.left, rct.bottom
      deleteobject hpen
      '画内侧3d效果->暗色
      hpen = createpen(ps_solid, 1, getsyscolor(color_btnshadow))
      selectobject hdc, hpen
      movetoex hdc, rct.left, rct.bottom - 1, p
      lineto hdc, rct.right, rct.bottom - 1
      movetoex hdc, rct.right - 1, rct.top, p
      lineto hdc, rct.right - 1, rct.bottom
      deleteobject hpen
      '画阴影文字
      rct.left = rct.left + 1
      rct.right = rct.right + 1
      rct.bottom = rct.bottom + 1
      rct.top = rct.top + 1
      settextcolor hdc, getsyscolor(color_btnhighlight)
      drawtext hdc, s, len(s), rct, dt_center or dt_singleline or dt_vcenter
      rct.left = rct.left - 1
      rct.right = rct.right - 1
      rct.bottom = rct.bottom - 1

本文关键:Button WM_DRAWITEM SubClass 界面
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top