Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4764110
  • 博文数量: 206
  • 博客积分: 5240
  • 博客等级: 大校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-12 21:40
文章分类

全部博文(206)

文章存档

2013年(13)

2012年(8)

2011年(33)

2010年(152)

我的朋友

分类: 敏捷开发

2013-12-26 17:16:53

//toolbar 工具条
/************************************
Author      : lujjjh
Date        : 2010.9
************************************/

import win.imageList;
import win.ui.tooltip;
import win.ui.ctrl.common;
win.ui.ctrl.common.initEx(  0x4
/*_ICC_BAR_CLASSES*/ ) //初始化工具条支持

namespace win.ui {
    
import util.metaProperty;   
    toolbar = 
class {
        
ctor (winform) {
            
if( ! winform[["hwnd"]] ){
                
if(type(winform)==type.number){
                    winform = {hwnd=winform;_mapCommandProc={}}
                }
                
else {
                    
error("第一个构造参数必须指定有效窗口",3)
                } 
            } 
            
this.parent = winform;
            
this.hParent = winform.hwnd;
            
            
this.flat = true;
            
this.label = true;
            
this.buttons = {};
        };
        create = 
function (tParam) {  
            
var style = 0x40000000/*_WS_CHILD*/ | 0x10000000/*_WS_VISIBLE*/ ;
            
if( tParam[["style"]] ) style = style | tParam[["style"]];
            
if( tParam[["style"]] ) style = style | tParam[["style"]];
            
ifthis.flat ) style = style | 0x800/*_TBSTYLE_FLAT*/ | 0x100/*_TBSTYLE_TOOLTIPS*/;
            
            
this.hwnd = ::CreateWindowEx(tParam[["exstyle"]] or 0, 
                                         
"ToolbarWindow32", ,style,
                                         0, 0, 0, 0, 
                                         
this.hParent, 0 );
            ::SendMessageInt(
this.hwnd, 0x41e/*_TB_BUTTONSTRUCTSIZE*/, 20, 0);
            
            
this.tooltip = ..win.ui.tooltip(winform);
            
this.tooltip.create();
            ::SendMessageInt(
this.hwnd, 0x424/*_TB_SETTOOLTIPS*/this.tooltip.hwnd, 0);
         
            
this.showLabel = label;
            
return this.hwnd;
        }; 
        adjust = 
function(){
            ::SendMessageInt(
this.hwnd, 0x421/*_TB_AUTOSIZE*/, 0, 0);
        }; 
        add = 
function (text, proc, iBitmap = 0,id) { 
            
if(!id)
                id = 
this.parent._getFreeCommandId();
            
            
if(proc){
                
iftype(proc)!=type.function
                    
error("参数二必须是一个回调函数",2  );
                    
                
this.parent._mapCommandProc[id] = proc; 
            }
            
            
var tbb = TBBUTTON(this);
            tbb.iBitmap = iBitmap - 1;
            tbb.idCommand = id;
            tbb.fsState = 0x4
/*_TBSTATE_ENABLED*/;
            tbb.fsStyle = text == 
null ? 0x1/*_TBSTYLE_SEP*/ : 0x0/*_TBSTYLE_BUTTON*/;
            tbb.iString = text 
or "";
            ..table.push(
this.buttons,tbb );
            
            ::SendMessageByStruct(
this.hwnd, 0x414, 1, tbb);  
            ::SendMessageInt(
this.hwnd, 0x421/*_TB_AUTOSIZE*/, 0, 0);  
            
return tbb;
        } 
        @_metaProperty;
    }
    
    
namespace toolbar{
        _metaProperty = ..util.metaProperty(
            showLabel = {
                _get = 
function () {
                    
return owner.label;
                }
                _set = 
function (v) {
                    
if (owner.hwnd)
                        ::SendMessageInt(
owner.hwnd, 0x400/*_WM_USER*/+60/*_TB_SETMAXTEXTROWS*/, v ? 1 : 0, 0);
                    
owner.label = v ? true : false;
                }
            };
            style = {
                _get = 
function () {
                    
return ::SendMessageInt(owner.parent.hwnd, 0x439/*_TB_GETSTYLE*/owner.idCommand, 0);
                }
                _set = 
function (v) {
                    
return ::SendMessageInt(owner.parent.hwnd, 0x438/*_TB_SETSTYLE*/owner.idCommand, ::MAKELONG(v, 0));
                }
            }; 
            modifyStyle = 
function( remove=0,add=0 ){
                
var style = ( owner.style & ~remove ) | add ; 
                
owner.style = style;
                
return style;
            };
            imageList = {
                _get = 
function () {
                    
return ::SendMessageInt(owner.hwnd, 0x400/*_WM_USER*/+49/*_TB_GETIMAGELIST*/, 0, 0);
                }
                _set = 
function (v) { 
                    
return ::SendMessage(owner.hwnd, 0x400/*_WM_USER*/+48/*_TB_SETIMAGELIST*/, , v);
                }
            }
        ) 
        
        
class TBBUTTON{
            
ctor (parent) {
                
this.parent = parent; 
            }
            int iBitmap;
            int idCommand;
            BYTE fsState;
            BYTE fsStyle;
            INT dwData;
            string iString; 
            @_metaProperty;
        }
        
        
namespace TBBUTTON{ 
            
class INFO {
                INT cbSize = 32;
                INT mask = 0;
                int idCommand;
                int iImage;
                BYTE fsState;
                BYTE fsStyle;
                WORD cx;
                INT lParam;
                pointer text;
                int cchText;
            };
            INFO_AUTOSET_MASK = 
function(info){ 
                
if( info.text !== null ){ 
                    info.cchText = #info.text+1; 
                }
                
if( info.cchText ){
                    info.mask |= 2
/*_TBIF_TEXT*/  
                }
                
if( info.fsState ){
                    info.mask |= 4
/*_TBIF_STATE*/ 
                }
                
if( info.idCommand ){
                    info.mask |= 0x20
/*_TBIF_COMMAND*/ 
                }
                
if( info.iImage ){
                    info.mask |= 1
/*_TBIF_IMAGE*/
                }
                
if( info.cx ){
                    info.mask |= 0x40
/*_TBIF_SIZE*/
                }
                
if( info.fsStyle ){
                    info.mask |= 8
/*_TBIF_STYLE*/
                }
            };
            
            _metaProperty = ..util.metaProperty(
                getInfo = 
function(){
                    
var info = INFO();
                    
if( ::SendMessageByStruct(owner.parent.hwnd,0x441/*_TB_GETBUTTONINFO*/,owner.idCommand,info) )
                        
return info;
                }
                setInfo = 
function(info){ 
                    
if(!info._struct)info = ..table.mixin(INFO(),info);
                    INFO_AUTOSET_MASK(info);
                    
return !! ::SendMessageByStruct(owner.parent.hwnd,0x442/*_TB_SETBUTTONINFO*/,owner.idCommand,info);
                } 
                id = {
                    _get = 
function () {
                        
return owner.idCommand;
                    }
                    _set = 
function (v) {
                        
if(  owner.setInfo( idCommand = v ) ){ 
                            
owner.idCommand = v;
                        }
                    }
                }; 
                text = {
                    _get = 
function () {
                        
return owner.iString;
                    }
                    _set = 
function (v) {
                        
ifowner.setInfo( text = v ) ){
                            
owner.iString = v;
                        }
                    }
                };
                getRect = 
function(){
                    
var rc = ::RECT()
                    
if( ::SendMessageByStruct(owner.parent.hwnd,0x433/*_TB_GETRECT*/,owner.idCommand,rc) )
                        
return rc;
                };
                state = {
                    _get = 
function () {
                        
return ::SendMessageInt(owner.parent.hwnd, 0x412/*_TB_GETSTATE*/owner.idCommand, 0);
                    }
                    _set = 
function (v) {
                        
return ::SendMessageInt(owner.parent.hwnd, 0x411/*_TB_SETSTATE*/owner.idCommand, ::MAKELONG(v, 0));
                    }
                }; 
                disabled = {
                    _get = 
function () {
                        
return !( owner.state & 0x4);
                    }
                    _set = 
function (v) {
                        
if (v)
                            
owner.state -= 0x4;
                        
else
                            
owner.state |= 0x4;
                    }
                }
                enabled = {
                    _get = 
function () {
                        
return !owner.disabled;
                    }
                    _set = 
function (v) {
                        
owner.disabled = !v;
                    }
                }
                checked = {
                    _get = 
function () {
                        
return owner.state & 0x1;
                    }
                    _set = 
function (v) {
                        
if (v)
                            
owner.state |= 0x1;
                        
else
                            
if (owner.checked)
                                
owner.state -= 0x1;
                    }
                }
            );
        }
    };
    

}
  
/**intellisense()
win.ui.toolbar(__/*父窗口*/) = 创建一个 Toolbar 控件 
!toolbar.create() = 创建工具条
!toolbar.add(标题,回调函数,图像索引,可选指定命令ID) = @.add(\n  "文字", \n  function (id) {\n\n },1\n)
!toolbar.add() = 添加一个分隔条\n!toolbar_button.
!toolbar.style = 工具栏样式,\n 使用 _TBSTYLE_ 前缀常量表示样式
!toolbar.modifyStyle(.(移除样式,添加样式) = 所有参数可选,默认为0\n使用 _TBSTYLE_ 前缀常量表示样式
!toolbar.showLabel = 是否在按钮上显示文字
!toolbar.imageList = 指定 Toolbar 的 imageList 
!toolbar.buttons[1__/*索引*/] = 返回指定的按钮对象\nadd()函数返回按钮id
!toolbar.buttons[] = !toolbar_button.
?win.ui.toolbar = !toolbar.
win.ui.toolbar() = !toolbar.
!toolbar_button.id = 命令ID
!toolbar_button.state = 读写按钮状态
!toolbar_button.disabled = 是否禁用
!toolbar_button.checked = 是否选中 
!toolbar_button.text = 按钮文本
!toolbar_button.getRect() = 返回按钮区块\n!rect.
end intellisense**/

 
 
/**intellisense()

_TB_SETSTYLE=@0x438/*_TB_SETSTYLE*/
_TB_GETSTYLE=@0x439/*_TB_GETSTYLE*/
_TB_GETBUTTONSIZE=@0x43A/*_TB_GETBUTTONSIZE*/
_TB_SETBUTTONWIDTH=@0x43B/*_TB_SETBUTTONWIDTH*/
_TB_SETDISABLEDIMAGELIST=@0x436/*_TB_SETDISABLEDIMAGELIST*/
_TB_GETDISABLEDIMAGELIST=@0x437/*_TB_GETDISABLEDIMAGELIST*/
_TB_GETRECT=@0x433/*_TB_GETRECT*/
_TB_GETTOOLTIPS=@0x423/*_TB_GETTOOLTIPS*/
_TB_SETTOOLTIPS=@0x424/*_TB_SETTOOLTIPS*/
_TB_CHANGEBITMAP=@0x42B/*_TB_CHANGEBITMAP*/
_TB_GETBITMAP=@0x42C/*_TB_GETBITMAP*/
_TBIF_IMAGE=@1/*_TBIF_IMAGE*/
_TBIF_TEXT=@2/*_TBIF_TEXT*/
_TBIF_STATE=@4/*_TBIF_STATE*/
_TBIF_STYLE=@8/*_TBIF_STYLE*/
_TBIF_LPARAM=@0x10/*_TBIF_LPARAM*/
_TBIF_COMMAND=@0x20/*_TBIF_COMMAND*/
_TBIF_SIZE=@0x40/*_TBIF_SIZE*/
_TB_GETBUTTONINFO =@0x441/*_TB_GETBUTTONINFO*/
_TB_SETBUTTONINFO =@0x442/*_TB_SETBUTTONINFO*/
_TB_GETBUTTONTEXT=@0x42D/*_TB_GETBUTTONTEXT*/

_TBSTYLE_BUTTON=@0/*_TBSTYLE_BUTTON*/
_TBSTYLE_SEP=@1/*_TBSTYLE_SEP*/
_TBSTYLE_CHECK=@2/*_TBSTYLE_CHECK*/
_TBSTYLE_GROUP=@4/*_TBSTYLE_GROUP*/
_TBSTYLE_CHECKGROUP=@6/*_TBSTYLE_CHECKGROUP*/
_TBSTYLE_DROPDOWN=@8/*_TBSTYLE_DROPDOWN*/
_TBSTYLE_AUTOSIZE=@0x10/*_TBSTYLE_AUTOSIZE*/
_TBSTYLE_NOPREFIX=@0x20/*_TBSTYLE_NOPREFIX*/
_TBSTYLE_TOOLTIPS=@0x100/*_TBSTYLE_TOOLTIPS*/
_TBSTYLE_WRAPABLE=@0x200/*_TBSTYLE_WRAPABLE*/
_TBSTYLE_ALTDRAG=@0x400/*_TBSTYLE_ALTDRAG*/
_TBSTYLE_FLAT=@0x800/*_TBSTYLE_FLAT*/
_TBSTYLE_LIST=@0x1000/*_TBSTYLE_LIST*/
_TBSTYLE_CUSTOMERASE=@0x2000/*_TBSTYLE_CUSTOMERASE*/
_TBSTYLE_REGISTERDROP=@0x4000/*_TBSTYLE_REGISTERDROP*/
_TBSTYLE_TRANSPARENT=@0x8000/*_TBSTYLE_TRANSPARENT*/ 
end intellisense**/



//imageList 图像索引列表
/************************************
Author      : lujjjh
Date        : 2010.9
************************************/

import win.image;
import com.picture;

namespace win {
    imageList = 
class {
        
ctor (v1 = 0, v2 = -1) {
            
if (v2 == -1) {
                
this.handle = v1;
                
var re, cx, cy = ::ImageList_GetIconSize(this.handle, 0, 0);
                
this.width = cx;
                
this.height = cy;
            }
            
else {
                
this.handle = ::ImageList_Create(v1, v2, 0x00000020 | 0x1/*_ILC_MASK*/, 0, 1);
                
this.width = v1;
                
this.height = v2;
            }
        };
        addBitmap = 
function(hbmp,color=0xff00ff){
            ::ImageList_AddMasked(
this.handle,hbmp, color); 
        };
        add = 
function (pic, color=0xff00ff) { 
            
var iPic = ..com.picture.load(pic);
            
if(!iPic)
                
error("加载图片失败",2)
                
            
var hbmp = iPic.handle; 
            ::ImageList_AddMasked(
this.handle, topointer(hbmp), color);
            ::DeleteObject(
topointer(hbmp));
            ..com.Release(iPic)
            
return this;
        };
        addIcon = 
function (iconData) {
            
var hIcon = ..win.image.createIconFromResource(iconData,this.width);
            ::ImageList_ReplaceIcon(
this.handle, -1, hIcon);
            
return this;
        };
        draw = 
function(i,hdc,x,y,fStyle=1/*_ILD_TRANSPARENT*/){
            ::ImageList_Draw(
this.handle,i,hdc,x,y,fStyle)
        }; 
        @_meta
    }
    imagelist = imageList;
}

namespace win.imageList {
    _meta = {
        _topointer = 
function(){ 
            
return owner.handle;
        } 
    }
    
    
/*intellisense(::)*/
    ::Comctl32 := ..raw.loadDll(
"Comctl32.dll");
    ::ImageList_Create := ::Comctl32.api(
"ImageList_Create""pointer(int cx, int cy, INT flags, int cInitial, int cGrow)");
    ::ImageList_AddMasked = ::Comctl32.api(
"ImageList_AddMasked""int(POINTER himl, pointer hbmImage, int crMask)");
    ::ImageList_GetIconSize = ::Comctl32.api(
"ImageList_GetIconSize","int(POINTER himl, int &cx, int &cy)");
    ::ImageList_ReplaceIcon = ::Comctl32.api(
"ImageList_ReplaceIcon","int(POINTER himl, int i, pointer hicon)");
    ::ImageList_Draw = ::Comctl32.api(
"ImageList_Draw","int(POINTER himl, int i, POINTER hdcDst,int x,int y,INT fStyle)"); 
    
/*end intellisense*/ 


/**intellisense(win)
imageList = 图像列表\n用于工具条、树形控件等
imageList(__/*句柄*/)  = 通过句柄创建一个 imageList
imageList(.(宽度,高度)  = 创建一个 imageList
end intellisense**/


/**intellisense()  
win.imageList() = !imageList.
!imagelist.addBitmap(.(位图句柄,透明色) = 添加位图,\n该函数会复制位图,不会接管或销毁传入的位图\n如果传入的位图句柄不再使用,应使用::DeleteObject销毁
!imagelist.add(.(图像路径,透明色) = 添加图片\n该函数返回当前win.imageList对象
!imagelist.draw(.(索引,hDC,x,y,fStyle) = 绘图
!imagelist.width = 宽度
!imagelist.height = 高度
end intellisense**/


 
/**intellisense()
_ILD_NORMAL=@0/*_ILD_NORMAL*/
_ILD_TRANSPARENT=@1/*_ILD_TRANSPARENT*/
_ILD_MASK=@0x10/*_ILD_MASK*/
_ILD_IMAGE=@0x20/*_ILD_IMAGE*/
_ILD_ROP=@0x40/*_ILD_ROP*/
_ILD_BLEND25=@2/*_ILD_BLEND25*/
_ILD_BLEND50=@4/*_ILD_BLEND50*/
_ILD_OVERLAYMASK=@0xF00/*_ILD_OVERLAYMASK*/
_ILD_PRESERVEALPHA=@0x1000/*_ILD_PRESERVEALPHA*/
_ILD_SCALE=@0x2000/*_ILD_SCALE*/
_ILD_DPISCALE=@0x4000/*_ILD_DPISCALE*/
_ILD_ASYNC=@0x8000/*_ILD_ASYNC*/
_ILS_NORMAL=@0/*_ILS_NORMAL*/
_ILS_GLOW=@1/*_ILS_GLOW*/
_ILS_SHADOW=@2/*_ILS_SHADOW*/
_ILS_SATURATE=@4/*_ILS_SATURATE*/
_ILS_ALPHA=@8/*_ILS_ALPHA*/
_ILC_MASK=@1/*_ILC_MASK*/
_ILC_COLOR=@0/*_ILC_COLOR*/
_ILC_COLORDDB=@0xFE/*_ILC_COLORDDB*/
_ILC_COLOR4=@4/*_ILC_COLOR4*/
_ILC_COLOR8=@8/*_ILC_COLOR8*/
_ILC_COLOR16=@0x10/*_ILC_COLOR16*/
_ILC_COLOR24=@0x18/*_ILC_COLOR24*/
_ILC_COLOR32=@0x20/*_ILC_COLOR32*/
_ILC_PALETTE=@0x800/*_ILC_PALETTE*/
_ILC_MIRROR=@0x2000/*_ILC_MIRROR*/
_ILC_PERITEMMIRROR=@0x8000/*_ILC_PERITEMMIRROR*/
end intellisense**/


阅读(4065) | 评论(0) | 转发(0) |
0

上一篇:窗口探测器winspy 源码

下一篇:没有了

给主人留下些什么吧!~~