Dim cxClient
Dim cyClient
Dim BORDER_WIDTH
Dim cxOffset
Dim cyOffset
Dim strCurAccount
Dim strLongNick
Dim strCurStatus
Dim strSuffix
Dim bShowAdFrame
Dim FrameADHeight
Dim BORDER_WIDTH_T
FrameADHeight = 52


sub Window_OnInit()
	BORDER_WIDTH = 3
	BORDER_WIDTH_T = 2
	cxOffset = 44
	cyOffset = 194
	window.titleHeight = title.height
	bShowAdFrame = true
end sub

sub Window_OnSizeDraw()
	Window.LockPaint()
	
	'头部
	title.width = cxClient
	TitleMiddle.left = TtileLeft.width
        TitleMiddle.width = cxClient - TtileLeft.width - TitleRight.width        
	TitleRight.left = cxClient - TitleRight.width

	minBtn.left = cxClient - 65
	maxBtn.left = minBtn.left + minBtn.width +1
	origBtn.left = minBtn.left + minBtn.width + 1
	closeBtn.left = maxBtn.left + maxBtn.width + 1

	titleText.width = minBtn.left - titleText.left
	
		
	'系统菜单
	SysMenu.left = BORDER_WIDTH_T
	sysMenu.top = title.top + title.height + 1
	SysMenu.width = cxClient - BORDER_WIDTH_T * 2 
	
        menuBar.height = sysMenu.height
	menuBar.width = SysMenu.width
	menuBtmLine.top = sysMenu.top + sysMenu.height
	menuBtmLine.width = sysMenu.width

	'主面板的边框
	MainFrameLeftLine.Height = cyClient - MainFrameLeftLine.top - MainFrameBottomLine.height
	
	MainFrameRightLine.left = cxClient - BORDER_WIDTH
	MainFrameRightLine.Height = MainFrameLeftLine.Height

	MainFrameBottomLine.width = cxClient
	MainFrameBottomLine.top = cyClient - MainFrameBottomLine.height

	'用户状态指示区
	Indicator.left = BORDER_WIDTH_T
	Indicator.top = sysMenu.top + sysMenu.height
	Indicator.width = cxClient - BORDER_WIDTH_T * 2
	IndicatorBkg_Mid.width = Indicator.width - IndicatorBkg_Left.width - IndicatorBkg_Right.width
	IndicatorBkg_Right.left = IndicatorBkg_Mid.left + IndicatorBkg_Mid.width

	if Indicator.left + Indicator.width - 2 - CurStatus.left > CurStatus.textlength + 20 Then
           CurStatus.width = CurStatus.textlength + 20
        else
           CurStatus.width = Indicator.left + Indicator.width - 2 - CurStatus.left 
        end if

	'广告
	FrameAD.left = MainFrameLeftLine.left + MainFrameLeftLine.width 
	FrameAD.width = MainFrameRightLine.left - FrameAD.left

	if bShowAdFrame then 
	   FrameAD.height = FrameADHeight
	   FrameAD.top =  MainFrameBottomLine.top - FrameAD.height	
	else
	   FrameAD.height = 0
	end if	
	
	'显示提示信息的窗口
	HintArea.top = Indicator.top + Indicator.height
	HintArea.left = MainFrameLeftLine.left + MainFrameLeftLine.width
	HintArea.width = MainFrameRightLine.left - HintArea.left

	'背景贴图
	If HintArea.visible Then
		MainFrameBkg.top = HintArea.top + HintArea.height
	Else
	MainFrameBkg.top = Indicator.top + Indicator.height
	End If
	
	MainFrameBkg.left = BORDER_WIDTH
	MainFrameBkg.width = cxClient - BORDER_WIDTH * 2

	if bShowAdFrame then 
	MainFrameBkg.height = FrameAD.top - MainFrameBkg.top
	else
	MainFrameBkg.height = MainFrameBottomLine.top - MainFrameBkg.top
	end if

	If HintArea.visible Then
		SideBarBtns.top = HintArea.top + HintArea.height
	Else
	SideBarBtns.top = Indicator.top + Indicator.height
	End If
	
	PanelRightLine.top = SideBarBtns.top + QQBar_RightTopLine.height
	PanelRightLine.left = MainFrameRightLine.left - PanelRightLine.width 

	if bShowAdFrame then 
	PanelRightLine.height = FrameAD.top - 2 - PanelRightLine.top
	else
	PanelRightLine.height = MainFrameBottomLine.top  - 2 - PanelRightLine.top	
	end if

	'QQ Bar
	QQBar_MidTopLine.left = SideBarBtns.left + SideBarBtns.width - 1
	QQBar_MidTopLine.top = SideBarBtns.top
	QQBar_MidTopLine.width = PanelRightLine.left - QQBar_MidTopLine.left
	QQBar_RightTopLine.left = PanelRightLine.left
	QQBar_RightTopLine.top = QQBar_MidTopLine.top 

	QuickFunc.left = SideBarBtns.left + SideBarBtns.width - 2

	if bShowAdFrame then 
	QuickFunc.top = FrameAD.top - 2 - QuickFunc.height
	else
	QuickFunc.top = MainFrameBottomLine.top - 2 - QuickFunc.height
	end if

	QuickFunc.width = PanelRightLine.left - QuickFunc.left
	AddFriend.width = QuickFunc.width - 1
	QuickFuncBkg.width = QuickFunc.width
	QuickFunc_TopLine.width = QuickFunc.width + 2

	QQBar.left = SideBarBtns.left + SideBarBtns.width - 1
	QQBar.top = QQBar_MidTopLine.top + QQBar_MidTopLine.height
	QQBar.width = QQBar_MidTopLine.left + QQBar_MidTopLine.width - QQBar.left + 2
	QQBar.height = QuickFunc.top - QQBar.top
    
	Bar1.width = QQBar.width
	Bar1.height = QQBar.height

    'QQBar边线        
	PanelLeftLine.left = SideBarBtns.left + SideBarBtns.width - 3
	PanelLeftLine.top = SideBarBtns.top + SideBarBtns.height
	PanelLeftLine.height = QuickFunc.top + QuickFunc.height - PanelLeftLine.top
 
	PanelBottomLeftLine.left = PanelLeftLine.left
	PanelBottomLeftLine.top = QuickFunc.top + QuickFunc.height - PanelBottomLeftLine.height
	PanelBottomRightLine.left = PanelRightLine.left + PanelRightLine.width - PanelBottomRightLine.width
	PanelBottomRightLine.top = PanelBottomLeftLine.top 
	PanelBottomMidLine.left = PanelBottomLeftLine.left + PanelBottomLeftLine.width	
	PanelBottomMidLine.width = PanelBottomRightLine.left - PanelBottomLeftLine.left - PanelBottomLeftLine.width
	PanelBottomMidLine.top = PanelBottomLeftLine.top
	
	'动态创建的界面窗口请将位置调整代码放在最后：
	FrameADWnd.width = FrameAD.width
	FrameADWnd.height = FrameAD.height	

	PersonalImageWnd.width = 44
	PersonalImageWnd.height = 44

	'提示区域窗口大小
	If HintArea.visible Then
		HintAreaWnd.width = HintArea.width
		HintAreaWnd.height = HintArea.height
	Else
		HintAreaWnd.width = 0
		HintAreaWnd.height = 0
	End If

	Window.ExeCommand 29, CStr( QuickFunc.left ) + "," + CStr( QuickFunc.top )

	window.UnLockPaint()

end sub

sub Window_OnSize(cx,cy)
    cxClient = cx
    cyClient = cy
 
    Window_OnSizeDraw()
end sub

sub MainFrameSize(cx,cy)
	Window.LockPaint()
	Window.ExeCommand  12, CLng(cx)
	Window.ExeCommand  13, CLng(cy)
	Window.UnLockPaint()
end sub

Sub Window_onClick(code, Name)
	Window.LockPaint()		
	result =  Window.ExeCommand(code,CStr(Name))
	if result then
		Window.DisableBar CStr(Name)
	end if

	Window.UnLockPaint()
End sub

sub Window_OnNotify(code ,var)
	if code = 1 then
		'设置当前的Uin
                strCurAccount = var
		CurStatus.SplitterText strCurAccount, strLongNick, strSuffix, strCurStatus, 0, 2
		Window_OnSizeDraw()
	elseif code = 62 then
		'设置当前的Uin
                strSuffix = var
		CurStatus.SplitterText strCurAccount, strLongNick, strSuffix, strCurStatus, 0, 2
		Window_OnSizeDraw()
	elseif code = 63 then
		'设置当前的Uin
                strLongNick = var
		CurStatus.SplitterText strCurAccount, strLongNick, strSuffix, strCurStatus, 0, 2
		Window_OnSizeDraw()
 	elseif code = 4 then
		'设置那个Bar在最前
		Window_onClick 2,var
	elseif code = 5 then
		'设置当前的状态。
		if var = 10 Then			
			UseStatus = "(在线)"
		elseif var = 20 Then			
			UseStatus = "(离线)"
		elseif var = 30 Then			
			UseStatus = "(离开)"
		elseif var = 40 Then			
			UseStatus = "(隐身)"	
		elseif var = 50 Then
			UseStatus = "(未验证)"
			strColor = "1C24EA"			
		end if
                strCurStatus = UseStatus
		CurStatus.PutColor strColor
		CurStatus.SplitterText strCurAccount, strLongNick, strSuffix, strCurStatus, 0, 2
		Window_OnSizeDraw()
    elseif code = 9 then
        cyClient = var / 10000 
        cxClient = var Mod 10000  
  
    elseif  code = 16 then
        cxClient = (var / 10000) + cxOffset
        cyClient = (var Mod 10000) + cyOffset
        MainFrameSize cxClient,cyClient
    elseif code = 18 then
	Window_onAddPanel
    elseif code = 19 then '双击标题栏的消息响应
	if maxBtn.visible then
		maxBtn_onClick
	else
		origBtn_onClick
	end if
    elseif code = 20 then '设置性别头像
	if var = 1 then
		FriendBar.ico = "tabicon_face.ico"
	else
		FriendBar.ico = "tabicon_face_female.ico"
	end if
    elseIf code = 21 then '设置TITLE标志
        	titleText.value = Var
    elseif code = 100 then '改变EMail的提示
		dim nPreLen
		nPreLen= Email.TextLength

		Email.Label = "(" + CStr(var) + ")" 

		dim nOffset
		nOffset= Email.TextLength - nPreLen
		Email.width = Email.TextLength + 2
	        if nOffset > 0	then
			TMSpace.left = TMSpace.left + nOffset
	       		TocCorp.left = TocCorp.left + nOffset
		end if
    elseif code = 66 then	'显示space图标
		TMSpace.width = 45
		TocCorp.left = TMSpace.left + TMSpace.width  + 8
    elseif code = 99 then
		bShowAdFrame = Var
		Window_OnSizeDraw()

	' 注意：从 200 到 220 的 code 被 HintArea 预定了		
	elseif code = 200 Then '显示或者隐藏 Hint
		HintArea.visible = Var
		Window_OnSizeDraw()
	ElseIf code = 201 Then '调节 Hint 区域的高度
		HintArea.height = Var
		Window_OnSizeDraw()

    end if

end sub

sub minBtn_onClick()
	Window.ExeCommand 1,2
end sub

sub maxBtn_onClick()
	Window.ExeCommand 1,4
	origBtn.visible = True
	maxBtn.visible = False
end sub

sub origBtn_onClick()
	Window.ExeCommand 1,5
	origBtn.visible = False
	maxBtn.visible = True             
end sub

sub closeBtn_onClick()
	Window.ExeCommand 1,3
end sub

sub CurStatus_onClick()
	Window.LockPaint
	Window.ExeCommand 9,0
	Window.UnLockPaint()
end sub

sub Assistant_onClick()
	Window.LockPaint
	Window.ExeCommand 15,0
	Window.UnLockPaint()
end sub 

sub Email_onClick()
	Window.LockPaint
	Window.ExeCommand 7,1
	Window.UnLockPaint()
end sub 

sub SMS_onClick()
	Window.LockPaint
	Window.ExeCommand 4,2
	Window.UnLockPaint()
end sub 

sub TocCorp_onClick()
	Window.LockPaint
	Window.ExeCommand 23,0
	Window.UnLockPaint()
end sub
 
sub TMSpace_onClick()
	Window.LockPaint
	Window.ExeCommand 28,0
	Window.UnLockPaint()
end sub 

Sub AddFriend_onClick()
	Window.LockPaint
	Window.ExeCommand 25,0
	Window.UnLockPaint()
end sub    

Sub SwitchBtn_onClick()

	Window.LockPaint
	Window.ExeCommand 27,0
	if bShowAdFrame = true then
		MainFrameSize cxClient,cyClient - FrameAD.height
		bShowAdFrame = false
	else
		MainFrameSize cxClient,cyClient + FrameAD.height
		bShowAdFrame = true
	end if
	Window_OnSizeDraw()	
	Window.UnLockPaint()

end sub  

'Sub SearchFriend_onClick()
'	Window.LockPaint
'	Window.ExeCommand 25,0
'	Window.UnLockPaint()
'end sub    

Sub Window_onAddPanel()
	Window_OnSizeDraw()
	if QQBar.height < SideBarBtns.height then
		cyClient = cyClient + SideBarBtns.height - QQBar.height
		MainFrameSize cxClient, cyClient
	end if
End sub