您的位置:程序门 -> 硬件/嵌入开发 ->



wince下drawtext与控件透明的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


wince下drawtext与控件透明的问题[已结贴,结贴人:happytt]
发表于:2007-09-19 08:41:37 楼主
基于对话框的程序里放了一个位图作为背景,上面放置了一个静态控件,这个静态控件的文字有时是要更新的,现在想要的就是不让静态控件的背景挡住对话框的位图,当然静态控件写的字可以看见.

自己解决方案想走三条路:
1.把静态控件透明,自己试了下,但不知使指定控件透明.
用下面的代码后,发现所有的static都变了,而且不是透明的.

if(message==wm_ctlcolorstatic)
{

hdc   hdc=getdlgitem(idc_staticcontrol)-> getdc()-> getsafehdc();  
hdc       hdc1,   mdc1;      
hdc1   =   getdlgitem(idc_main)-> getdc()-> getsafehdc();      
mdc1   =   createcompatibledc(hdc1);    
settextcolor(hdc,   rgb(0,0,0));  
                  bitblt(hdc,0,0,100,50,mdc1,200,30,srccopy
setbkmode(hdc,   transparent);
                  return   (int)getstockobject(null_brush);  
}

2.drawtext的方法,下面这段代码在vc里面就可行,换到evc下就不行了

cdc   *pdc=this-> getdc();
pdc-> setbkmode(transparent);
pdc-> drawtext(_t( "aaaaaa "),crect(10,10,100,100),dt_singleline ¦dt_left ¦dt_vcenter);

3.再者就是换背景图片,也就是想把静态控件上的文字放到背景图片上来,这样要改的时候,就更换一下图片就行了.不过感觉这样有点麻烦,换背景图屏幕刷新厉害.

哪位有做过的话,指点下吧...多谢多谢
发表于:2007-09-19 11:30:551楼 得分:18
加我msn:guohualee@hotmail.com
发表于:2007-09-19 11:56:202楼 得分:1
transparentblt   就可以呀
发表于:2007-09-19 14:02:063楼 得分:1
我在onpaint()  
{
cpaintdc   dc(this);
dc.setbkmode(transparent);
dc.settextcolor(group_text_color); //   选择文本颜色
dc.exttextout(pt.x   ,   pt.y   ,   eto_clipped   ,   &rcttext   ,   chtext   ,   null);
}
这样用可以呀.
发表于:2007-09-21 16:02:554楼 得分:0
1982pc()   :我这样不可以呀.有没有测试工程,我看一下.多谢了
happytrm@gmail.com
发表于:2007-09-21 20:58:365楼 得分:0
已经搞定了呵,多谢lenux()了.
发表于:2007-09-21 21:02:346楼 得分:0
这是解决方案.
我的email:
happytrm@gmail.com  


//从背景图上得到控件的在背景图的位置的brush,然后用这些brush来刷控件的背景
//onctlcolorstatic是关于设static       control的背景色或文本色的,也可以做,但比较//复杂一些,涉及至cdc的问题.      
       

//.h
message_handler(wm_ctlcolorstatic,   onctlcolorstatic   )
hbrush   getbkbrush(   hwnd   hwnd,   uint   nid,   hbitmap   hbmbk   );
hbrush     m_hbrctl[10];//刷子数组
//.cpp
//界面美化
m_hbmbkgnd   =   ::loadbitmap(_module.getresourceinstance(),   makeintresource(idb_bt_s_ss_main)   );
if(   m_hbmbkgnd   )
{
m_hbrctl[0]   =   getbkbrush(   m_hwnd,   idc_sendsms_1,   m_hbmbkgnd   );
m_hbrctl[1]   =   getbkbrush(   m_hwnd,   idc_sendsms_2,   m_hbmbkgnd   );
m_hbrctl[2]   =   getbkbrush(   m_hwnd,   idc_sendsms_3,   m_hbmbkgnd   );
m_hbrctl[3]   =   getbkbrush(   m_hwnd,   idc_sendsms_4,   m_hbmbkgnd   );
m_hbrctl[4]   =   getbkbrush(   m_hwnd,   idc_sendsms_5,   m_hbmbkgnd   );
m_hbrctl[5]   =   getbkbrush(   m_hwnd,   idc_sendsms_6,   m_hbmbkgnd   );
m_hbrctl[6]   =   getbkbrush(   m_hwnd,   idc_sendsms_7,   m_hbmbkgnd   );
m_hbrctl[7]   =   getbkbrush(   m_hwnd,   idc_sendsms_8,   m_hbmbkgnd   );
m_hbrctl[8]   =   getbkbrush(   m_hwnd,   idc_sendsms_9,   m_hbmbkgnd   );
m_hbrctl[9]   =   getbkbrush(   m_hwnd,   idc_sendsms_10,   m_hbmbkgnd   );
}
else
{
m_hbrctl[0]   =   null;
m_hbrctl[1]   =   null;
m_hbrctl[2]   =   null;
m_hbrctl[3]   =   null;
m_hbrctl[4]   =   null;
m_hbrctl[5]   =   null;
m_hbrctl[6]   =   null;
m_hbrctl[7]   =   null;
m_hbrctl[8]   =   null;
m_hbrctl[9]   =   null;
}

if(m_hbmbkgnd)
{
::deleteobject(   m_hbmbkgnd   );
m_hbmbkgnd   =   null;
}


lresult   csendsmsdlg::onctlcolorstatic(uint   /*umsg*/,   wparam   wparam,   lparam   lparam,   bool&   /*bhandled*/)
{
hdc   hdcbtn   =   (hdc)   wparam;
hwnd   hwndctrl   =   (hwnd)   lparam;

uint   nid   =   ::getdlgctrlid(   hwndctrl   );

::setbkmode(   hdcbtn,   transparent   );
::settextcolor(hdcbtn,   rgb(255,255,255));
switch(   nid   )
{
case   idc_sendsms_1:
return   (lresult)m_hbrctl[0];
case   idc_sendsms_2:
return   (lresult)m_hbrctl[1];
case   idc_sendsms_3:
return   (lresult)m_hbrctl[2];
case   idc_sendsms_4:
return   (lresult)m_hbrctl[3];
case   idc_sendsms_5:
return   (lresult)m_hbrctl[4];
case   idc_sendsms_6:
return   (lresult)m_hbrctl[5];
case   idc_sendsms_7:
return   (lresult)m_hbrctl[6];
case   idc_sendsms_8:
return   (lresult)m_hbrctl[7];
case   idc_sendsms_9:
return   (lresult)m_hbrctl[8];
case   idc_sendsms_10:
return   (lresult)m_hbrctl[9];
default:
break;
}

return   0;
}


#define   _x(x) (x.left)
#define   _y(x) (x.top)
#define   _w(x) (x.right   -   x.left)
#define   _h(x) (x.bottom   -   x.top)

//**************************************************************************************
//
// getbkbrush(   hwnd   hwnd,   uint   nid,   hbitmap   hbmbk   )
//    
// creates   background   brush   for   the   control   specified   by   nid
// according   to   its   position   in   the   parent   dialog   window.
//
// hwnd   [in]:   handle   to   the   parent   window
//     nid   [in]:   control   id
//     hbmbk   [in]:   bitmap   handle   of   the   parent   dialog 's   background   image
//
//
//**************************************************************************************

hbrush   csendsmsdlg::getbkbrush(   hwnd   hwnd,   uint   nid,   hbitmap   hbmbk   )
{
hwnd   hwndctrl;

hwndctrl   =   ::getdlgitem(   hwnd,   nid   );

hbrush hbrushctrl   =   null;

if(   null   !=   hwndctrl   )
{
rect   rcctrl;

::getwindowrect(   hwndctrl,   &rcctrl   );
::screentoclient(hwnd,   (lppoint)&rcctrl);
::screentoclient(hwnd,   ((lppoint)&rcctrl)+1);

hdc   hdc   =   ::getdc(hwnd);

hdc   hmemdcbk   =   createcompatibledc(   hdc   );
hdc   hmemdcctrl   =   createcompatibledc(   hdc   );

hbitmap   hbmctrl   =   createcompatiblebitmap(   hdc,   _w(rcctrl),   _h(rcctrl)   );

hbitmap   hbmoldbk;
hbitmap   hbmoldctrl;

hbmoldbk   =   (hbitmap)   ::selectobject(   hmemdcbk,   hbmbk   );
hbmoldctrl   =   (hbitmap)   ::selectobject(   hmemdcctrl,   hbmctrl   );

::bitblt(   hmemdcctrl,   0,   0,   _w(rcctrl),   _h(rcctrl),   hmemdcbk,   _x(rcctrl),   _y(rcctrl),   srccopy   );

::selectobject(hmemdcctrl,   hbmoldctrl   );
::selectobject(hmemdcbk,   hbmoldbk   );

hbrushctrl   =   ::createpatternbrush(   hbmctrl   );

deleteobject(   hbmctrl   );

::deletedc(   hmemdcbk   );
::deletedc(   hmemdcctrl   );
::releasedc(   hwnd,   hdc   );
}

return   hbrushctrl;
}




快速检索

最新资讯
热门点击