//圆角无边框窗口支持库

import win.gdi;
import win.ui.menu;
namespace win.util; 

//可以把下面的类放到库里面
class round {

    ctor(winform,minx,miny){   
		this = winform
		//创建最大化参数  
		var x,y,cx,cy = winform.getPos();
		var minmaxinfo = MINMAXINFO(cx,cy);  
		roundRectRgn(winform);
		winform.wndproc = function (hWnd, message, wparam, lparam) {
			if( message == 0x14/*_WM_ERASEBKGND*/ )
				return 0;// 禁止窗口背景重画，导致闪烁
			elseif( message == 0x5 /*_WM_SIZE*/ )    // 改变窗口大小
				roundRectRgn(winform);
			elseif( message == 0x24/*_WM_GETMINMAXINFO*/ ) { 
				::CopyMemoryByStruct( topointer( lparam ), minmaxinfo, 40 ); 
				return 0;
			}
		}
		//创建弹出菜单

		var pop = ..win.ui.popmenu(winform);
		pop.add(
			'最大化',
			function(id){
				if( winform.hitmax() )
					winform.popmenu.setString(1,"还原" )
				else {
					winform.popmenu.setString(id,"最大化",0x0/*_MF_BYCOMMAND*/)
				}
					
			}
		);
		pop.add(
			'最小化',
			function(id){
				winform.hitmin()
			}
		);
		pop.add();//分隔线
		pop.add(
			'关闭',
			function(id){
				winform.close()
			}
		); 
		this.sysmenu = pop;
    }
}

namespace round{
	CreateRoundRectRgn := ::Gdi32.api( "CreateRoundRectRgn", "pointer(int, int, int, int, int, int)" );
	SetWindowRgn := ::User32.api("SetWindowRgn", "int(int hWnd, pointer hRgn, bool bRedraw)");
	
	roundRectRgn = function (winform) {
		var rc = winform.rect;
		var hRgn = CreateRoundRectRgn(
			0, 0, 
			rc.right - rc.left + 1, 
			rc.bottom - rc.top + 1,
			4, 4
		);
		SetWindowRgn( winform.hwnd, hRgn, 1 );
		::DeleteObject( hRgn );
	}
	
	class MINMAXINFO{
		ctor( minx=500,miny=300 ){
			var w = ::GetSystemMetrics(0x10/*_SM_CXFULLSCREEN*/); 
			var h = ::GetSystemMetrics(0x11/*_SM_CYFULLSCREEN*/)   
      			+ ::GetSystemMetrics(0x4/*_SM_CYCAPTION窗口标题的高度*/) ; 
		};
		struct ptReserved = ::POINT();
		struct ptMaxSize = ::POINT(w,h);
		struct ptMaxPosition = ::POINT();
		struct ptMinTrackSize = ::POINT(minx,miny);
		struct ptMaxTrackSize = ::POINT(w,h);
	}
}
 

/**intellisense()
win.util.round(__/*输入winform对象*/) = 创建一个圆角无边框窗口\n并自动创建sysmenu系统菜单
!roundform.sysmenu = !popmenu.
?win.util.round = !roundform.
win.util.round = 圆角无边框窗口支持库
end intellisense**/

// 系统菜单
/**
GetSystemMenu := ::User32.api("GetSystemMenu","int(int hwnd,int bRevert)");
TrackPopupMenuByNum = ::User32.api("TrackPopupMenu","int(int hMenu,int wFlags,int x,int y,int nReserved,int hwnd,int lprc)");
winform.hitMenu = function(){
    var hMenu = ::GetSystemMenu(winform.hwnd, 0);
    ::TrackPopupMenuByNum(hMenu, 0x0/*_TPM_LEFTALIGN*/, winform.left + 3, winform.top + 28, 0, winform.hwnd, 0);
}

需要在窗体处理消息中加下面的代码
elseif( message == 0x111/*_WM_COMMAND*/ )
    return ::SendMessageInt(hWnd, 0x112/*_WM_SYSCOMMAND*/, wparam, lparam);
**/
