import win;
namespace win.gdi


/*intellisense(win.gdi)*/ 
setfont = function(hwnd,font){ 
   if(type(font)== type.table ) {
   var  hFont = ::CreateFontIndirect( font); 
   assert(hFont,"创建字体失败!")
   ::SendMessage(hwnd,0x30/*_WM_SETFONT*/,topointer( hFont ) ,null);
   }
} 

RGBQUAD= class{ 
BYTE rgbBlue; 
BYTE rgbGreen; 
BYTE rgbRed; 
BYTE rgbReserved; 
}
   
RGB = function(r,g,b){ 
    //根据rgb值返回颜色数值
	var rgb = RGBQUAD();
	rgb.rgbRed = b;
	rgb.rgbGreen = g;
	rgb.rgbBlue = r;

    var colorref = {INT color}  
    ..raw.convert( rgb,colorref );

    return colorref.color;
}
/*end intellisense*/

/*intellisense()
RGBQUAD = @win.gdi.RGBQUAD;
RGB = @win.gdi.RGB( 0__,0,0)
end intellisense*/



 /*intellisense(::)*/ 
 ::Gdi32 := ..raw.loadDll("Gdi32.dll")
 
::LOGFONT = class{ 
	ctor(arg){
		for(k,v in arg){
 			this[k] = v;
		}
		//如果用户未设置的属性，设置为默认值
		this.name  := "MS Shell Dlg"; 
		this.h:= -11;
		this.weight := 400;
		this.charset:= 134;
		for(k,v in arg){
 			this[k] := 0;
		}
	}  
	
	int      h;//以逻辑单位指定字体字符元(character cell)或字符的高度
	int      w;//以逻辑单位指定字体字符的平均宽度
	int      esc;//以十分之一度为单位指定每一行文本输出时相对于页面底端的角度
	int      ori;//以十分之一度为单位指定字符基线相对于页面底端的角度
	int      weight;//指定字体重量
	BYTE      italic;//当lfItalic为TRUE时使用斜体
	BYTE      underline;//当lfUnderline为TRUE时给字体添加下划线
	BYTE      strike;//当lfStrikeOut为TRUE时给字体添加删除线
	BYTE      charset;//指定字符集
	BYTE      out;//指定输出精度
	BYTE      clip;//指定剪辑精度
	BYTE      quality;//定义输出质量
	BYTE      family;//指定字体的字符间距和族
	BYTE      name[32] ;
	//请参考： http://baike.baidu.com/view/2421591.htm?fr=ala0_1_1
 	
}

::SelectObject := Gdi32.api("SelectObject","pointer(POINTER hDc,pointer h)" )  
::DeleteObject := Gdi32.api("DeleteObject","int(pointer i)" )

::GetWindowDC := ::User32.api("GetWindowDC","pointer(int hwnd)" ) 
::DeleteDC := Gdi32.api("DeleteDC","int(POINTER hDc)" )
::GetDC := ::User32.api("GetDC","pointer(int hwnd)" ) 
::ReleaseDC := ::User32.api("ReleaseDC","int(int hwnd,POINTER hDc)" ) 
::CreateCompatibleDC := Gdi32.api("CreateCompatibleDC","pointer(pointer hDc )" )

::CreateSolidBrush = Gdi32.api("CreateSolidBrush","pointer(INT color)" )  
::CreateFontIndirect = Gdi32.api("CreateFontIndirectA","int(struct lplf)" )
::GetStockObject := Gdi32.api("GetStockObject","pointer(int i)" )
::CreatePatternBrush := Gdi32.api("CreatePatternBrush","pointer(pointer hbm)" ) 

::CreateCompatibleBitmap := Gdi32.api("CreateCompatibleBitmap","pointer(   POINTER hDc,   int cx,   int cy )" ) 
::BitBlt := Gdi32.api("BitBlt","int(  POINTER hDc,  int x,  int y,  int cx,  int cy,  POINTER hDcSrc,  int x1,  int y1,  INT rop)" ) 
::PatBlt := Gdi32.api("PatBlt","int(  POINTER hDc,  int x,  int y,  int cx,  int cy,  INT rop)" ) 

::SetBkMode = Gdi32.api("SetBkMode","INT(POINTER hDc,int mode)" ) 
::SetBkColor = Gdi32.api("SetBkColor","INT(POINTER hDc,INT color)" ) 
::SetTextColor = Gdi32.api("SetTextColor","INT(POINTER hDc,INT color)" ) 

::GetPixel := Gdi32.api("GetPixel","int( POINTER hDc,  int x,   int y )" ) 
::SetPixel := Gdi32.api("SetPixel","INT( POINTER hDc,  int x,  int y,  INT color)");

/*end intellisense*/ 

/*intellisense(win.gdi)*/
getPixel = function(x,y,hwnd = 0 ){ 
    //抓点
    var hdc = GetDC(hwnd); 
    if(hdc){
       var pix = GetPixel(hdc,x,y);
      
       ::ReleaseDC(hwnd,hdc); 
       return pix; 
    }
}
setPixel = function(x,y,color,hwnd = 0 ){ 
    //抓点
    var hdc = GetDC(hwnd); 
    if(hdc){
       var pix = SetPixel(hdc,x,y,color);
      
       ::ReleaseDC(hwnd,hdc); 
       return pix; 
    }
}
/*end intellisense*/

 /**intellisense()
_SRCCOPY=@0xCC0020/*_SRCCOPY*/
_SRCPAINT=@0xEE0086/*_SRCPAINT*/
_SRCAND=@0x8800C6/*_SRCAND*/
_SRCINVERT=@0x660046/*_SRCINVERT*/
_SRCERASE=@0x440328/*_SRCERASE*/
_NOTSRCCOPY=@0x330008/*_NOTSRCCOPY*/
_NOTSRCERASE=@0x1100A6/*_NOTSRCERASE*/
_MERGECOPY=@0xC000CA/*_MERGECOPY*/
_MERGEPAINT=@0xBB0226/*_MERGEPAINT*/
_PATCOPY=@0xF00021/*_PATCOPY*/
_PATPAINT=@0xFB0A09/*_PATPAINT*/
_PATINVERT=@0x5A0049/*_PATINVERT*/
_DSTINVERT=@0x550009/*_DSTINVERT*/
_BLACKNESS=@0x42/*_BLACKNESS*/
_WHITENESS=@0xFF0062/*_WHITENESS*/
end intellisense**/