SOUI 实现分屏效果【4,6,9,16,24】类似监控效果

网上找了一圈 没看到类似的例子用C++来实现 多半是C#的例子;这里花了点时间弄了一下

想了一个比较费力的方法来实现,办法很原始;

思路:根据最大的分屏数量 来设计窗口的数量 然后通过不同的分屏方式 来进行窗口的“显示”与“隐藏”;最后就是一个体力活了 

先上XML 看看

<?xml version="1.0"?>
<SOUI name="mainWindow" title="@string/title" bigIcon="ICON_LOGO:32" smallIcon="ICON_LOGO:16" width="1920" height="1060" margin="20,5,5,5" resizable="1" wndType="appMain" appWnd="1" translucent="1">
	<root skin="_skin.sys.wnd.bkgnd" cache="1">
		<window pos="0,[0,-1,-1">
			<window pos="0,0,-1,30">
				<button pos="0,0,@96, @30" colorText="#000000" skin="_skin.sys.btn.normal" name="btn_test4">4</button>
				<button pos="[,{,@96, @30" colorText="#000000" skin="_skin.sys.btn.normal" name="btn_test6">6</button>
				<button pos="[,{,@96, @30" colorText="#000000" skin="_skin.sys.btn.normal" name="btn_test9">9</button>
				<button pos="[,{,@96, @30" colorText="#000000" skin="_skin.sys.btn.normal" name="btn_test16">16</button>
				<button pos="[,{,@96, @30" colorText="#000000" skin="_skin.sys.btn.normal" name="btn_test24">24</button>
				<imgbtn name="btn_close" skin="_skin.sys.btn.close" pos="-45,0" tip="close" animate="1" />
			</window>
			<realwnd pos="14,48,@300, @230" name="wnd_1" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="1" />
			<realwnd pos="[20,{,@300, @230" name="wnd_2" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="2" />
			<realwnd pos="[20,{,@300, @230" name="wnd_3" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="3" />
			<realwnd pos="[20,{,@300, @230" name="wnd_4" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="4" />
			<realwnd pos="[20,{,@300, @230" name="wnd_5" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="5" />
			<realwnd pos="[20,{,@300, @230" name="wnd_6" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="6" />
			<realwnd pos="14,[20,@300, @230" name="wnd_7" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="7" />
			<realwnd pos="[20,{,@300, @230" name="wnd_8" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="8" />
			<realwnd pos="[20,{,@300, @230" name="wnd_9" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="9" />
			<realwnd pos="[20,{,@300, @230" name="wnd_10" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="10" />
			<realwnd pos="[20,{,@300, @230" name="wnd_11" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="11" />
			<realwnd pos="[20,{,@300, @230" name="wnd_12" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="12" />
			<realwnd pos="14,[20,@300, @230" name="wnd_13" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="13" />
			<realwnd pos="[20,{,@300, @230" name="wnd_14" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="14" />
			<realwnd pos="[20,{,@300, @230" name="wnd_15" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="15" />
			<realwnd pos="[20,{,@300, @230" name="wnd_16" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="16" />
			<realwnd pos="[20,{,@300, @230" name="wnd_17" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="17" />
			<realwnd pos="[20,{,@300, @230" name="wnd_18" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="18" />
			<realwnd pos="14,[20,@300, @230" name="wnd_19" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="19" />
			<realwnd pos="[20,{,@300, @230" name="wnd_20" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="20" />
			<realwnd pos="[20,{,@300, @230" name="wnd_21" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="21" />
			<realwnd pos="[20,{,@300, @230" name="wnd_22" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="22" />
			<realwnd pos="[20,{,@300, @230" name="wnd_23" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="23" />
			<realwnd pos="[20,{,@300, @230" name="wnd_24" wndclass="" id="" wndname="" colorBkgnd="#1aaaaa" text="24" />
		</window>
	</root>
</SOUI>

通过这个配置文件 得到了 24个真实窗口(带句柄) 需要真正使用的时候 wndClass属性需要带上对应的值,这里演示思路 故没加

上面有五个按钮 分别对应的 是 4 , 6, 9, 16, 24 分屏的操作

看实现的代码

//4分屏实现
void CMainDlg::OnTest4()
{
	SRealWnd *pWnd = NULL;
	for (int i = 5; i < 25; ++i)
	{
		pWnd = FindChildByName2<SRealWnd>(SStringT().Format(L"wnd_%d", i));
		SASSERT(pWnd);
		pWnd->Move(0, 0, 0, 0);
	}

	int width = 940;
	int height = 495;
	int tag = 10;

	CRect r1(14, 38, 14+width, 38+height);
	CRect r2(r1.right + tag, r1.top, r1.right + tag + width,r1.bottom);
	CRect r3(r1.left,r1.bottom+tag,r1.left + width, r1.bottom + tag + height);
	CRect r4(r3.right + tag, r3.top, r3.right + tag + width, r3.bottom);

	m_pWnd1->Move(r1.left, r1.top, width, height);
	m_pWnd2->Move(r2.left, r2.top, width, height);
	m_pWnd3->Move(r3.left, r3.top, width, height);
	m_pWnd4->Move(r4.left, r4.top, width, height);

}

//6分屏实现
void CMainDlg::OnTest6()
{
	SRealWnd *pWnd = NULL;
	for (int i = 7; i < 25; ++i)
	{
		pWnd = FindChildByName2<SRealWnd>(SStringT().Format(L"wnd_%d", i));
		SASSERT(pWnd);
		pWnd->Move(0, 0, 0, 0);
	}

	int width = 625;
	int height = 495;
	int tag = 10;

	CRect r1(14, 38, 14 + width, 38 + height);
	CRect r2(r1.right + tag, r1.top, r1.right + tag + width, r1.bottom);
	CRect r3(r2.right + tag, r1.top, r2.right + tag + width, r2.bottom);

	CRect r4(r1.left, r1.bottom + tag, r1.left + width, r1.bottom + tag + height);
	CRect r5(r4.right + tag, r4.top, r4.right + tag + width, r4.bottom);
	CRect r6(r5.right + tag, r5.top, r5.right + tag + width, r5.bottom);

	m_pWnd1->Move(r1.left, r1.top, width, height);
	m_pWnd2->Move(r2.left, r2.top, width, height);
	m_pWnd3->Move(r3.left, r3.top, width, height);
	m_pWnd4->Move(r4.left, r4.top, width, height);
	m_pWnd5->Move(r5.left, r5.top, width, height);
	m_pWnd6->Move(r6.left, r6.top, width, height);
}

void CMainDlg::OnTest9()
{
	SRealWnd *pWnd = NULL;
	for (int i = 10; i < 25; ++i)
	{
		pWnd = FindChildByName2<SRealWnd>(SStringT().Format(L"wnd_%d", i));
		SASSERT(pWnd);
		pWnd->Move(0, 0, 0, 0);
	}

	int width = 625;
	int height = 325;
	int tag = 10;

	CRect r1(14, 38, 14 + width, 38 + height);
	CRect r2(r1.right + tag, r1.top, r1.right + tag + width, r1.bottom);
	CRect r3(r2.right + tag, r1.top, r2.right + tag + width, r2.bottom);

	CRect r4(r1.left, r1.bottom + tag, r1.left + width, r1.bottom + tag + height);
	CRect r5(r4.right + tag, r4.top, r4.right + tag + width, r4.bottom);
	CRect r6(r5.right + tag, r5.top, r5.right + tag + width, r5.bottom);

	CRect r7(r4.left, r4.bottom + tag, r4.left + width, r4.bottom + tag + height);
	CRect r8(r7.right + tag, r7.top, r7.right + tag + width, r7.bottom);
	CRect r9(r8.right + tag, r8.top, r8.right + tag + width, r8.bottom);

	m_pWnd1->Move(r1.left, r1.top, width, height);
	m_pWnd2->Move(r2.left, r2.top, width, height);
	m_pWnd3->Move(r3.left, r3.top, width, height);
	m_pWnd4->Move(r4.left, r4.top, width, height);
	m_pWnd5->Move(r5.left, r5.top, width, height);
	m_pWnd6->Move(r6.left, r6.top, width, height);
	m_pWnd7->Move(r7.left, r7.top, width, height);
	m_pWnd8->Move(r8.left, r8.top, width, height);
	m_pWnd9->Move(r9.left, r9.top, width, height);
}

void CMainDlg::OnTest16()
{
	SRealWnd *pWnd = NULL;
	for (int i = 17; i < 25; ++i)
	{
		pWnd = FindChildByName2<SRealWnd>(SStringT().Format(L"wnd_%d", i));
		SASSERT(pWnd);
		pWnd->Move(0, 0, 0, 0);
	}

	int width = 465;
	int height = 240;
	int tag = 10;

	CRect r1(14, 38, 14 + width, 38 + height);
	CRect r2(r1.right + tag, r1.top, r1.right + tag + width, r1.bottom);
	CRect r3(r2.right + tag, r1.top, r2.right + tag + width, r2.bottom);
	CRect r4(r3.right + tag, r1.top, r3.right + tag + width, r3.bottom);

	CRect r5(r1.left, r1.bottom + tag, r1.left + width, r1.bottom + tag + height);
	CRect r6(r5.right + tag, r5.top, r5.right + tag + width, r5.bottom);
	CRect r7(r6.right + tag, r6.top, r6.right + tag + width, r6.bottom);
	CRect r8(r7.right + tag, r7.top, r7.right + tag + width, r7.bottom);

	CRect r9(r5.left, r5.bottom + tag, r5.left + width, r5.bottom + tag + height);
	CRect r10(r9.right + tag, r9.top, r9.right + tag + width, r9.bottom);
	CRect r11(r10.right + tag, r10.top, r10.right + tag + width, r10.bottom);
	CRect r12(r11.right + tag, r11.top, r11.right + tag + width, r11.bottom);

	CRect r13(r9.left, r9.bottom + tag, r9.left + width, r9.bottom + tag + height);
	CRect r14(r13.right + tag, r13.top, r13.right + tag + width, r13.bottom);
	CRect r15(r14.right + tag, r14.top, r14.right + tag + width, r14.bottom);
	CRect r16(r15.right + tag, r15.top, r15.right + tag + width, r15.bottom);

	m_pWnd1->Move(r1.left, r1.top, width, height);
	m_pWnd2->Move(r2.left, r2.top, width, height);
	m_pWnd3->Move(r3.left, r3.top, width, height);
	m_pWnd4->Move(r4.left, r4.top, width, height);
	m_pWnd5->Move(r5.left, r5.top, width, height);
	m_pWnd6->Move(r6.left, r6.top, width, height);
	m_pWnd7->Move(r7.left, r7.top, width, height);
	m_pWnd8->Move(r8.left, r8.top, width, height);
	m_pWnd9->Move(r9.left, r9.top, width, height);
	m_pWnd10->Move(r10.left, r10.top, width, height);
	m_pWnd11->Move(r11.left, r11.top, width, height);
	m_pWnd12->Move(r12.left, r12.top, width, height);
	m_pWnd13->Move(r13.left, r13.top, width, height);
	m_pWnd14->Move(r14.left, r14.top, width, height);
	m_pWnd15->Move(r15.left, r15.top, width, height);
	m_pWnd16->Move(r16.left, r16.top, width, height);
}

void CMainDlg::OnTest24()
{
	int width = 307;
	int height = 240;
	int tag = 10;

	CRect r1(14, 38, 14 + width, 38 + height);
	CRect r2(r1.right + tag, r1.top, r1.right + tag + width, r1.bottom);
	CRect r3(r2.right + tag, r1.top, r2.right + tag + width, r2.bottom);
	CRect r4(r3.right + tag, r1.top, r3.right + tag + width, r3.bottom);
	CRect r5(r4.right + tag, r1.top, r4.right + tag + width, r4.bottom);
	CRect r6(r5.right + tag, r1.top, r5.right + tag + width, r5.bottom);

	CRect r7(r1.left, r1.bottom + tag, r1.left + width, r1.bottom + tag + height);
	CRect r8(r7.right + tag, r7.top, r7.right + tag + width, r7.bottom);
	CRect r9(r8.right + tag, r8.top, r8.right + tag + width, r8.bottom);
	CRect r10(r9.right + tag, r9.top, r9.right + tag + width, r9.bottom);
	CRect r11(r10.right + tag, r10.top, r10.right + tag + width, r10.bottom);
	CRect r12(r11.right + tag, r11.top, r11.right + tag + width, r11.bottom);

	CRect r13(r7.left, r7.bottom + tag, r7.left + width, r7.bottom + tag + height);
	CRect r14(r13.right + tag, r13.top, r13.right + tag + width, r13.bottom);
	CRect r15(r14.right + tag, r14.top, r14.right + tag + width, r14.bottom);
	CRect r16(r15.right + tag, r15.top, r15.right + tag + width, r15.bottom);
	CRect r17(r16.right + tag, r16.top, r16.right + tag + width, r16.bottom);
	CRect r18(r17.right + tag, r17.top, r17.right + tag + width, r17.bottom);

	CRect r19(r13.left, r13.bottom + tag, r13.left + width, r13.bottom + tag + height);
	CRect r20(r19.right + tag, r19.top, r19.right + tag + width, r19.bottom);
	CRect r21(r20.right + tag, r20.top, r20.right + tag + width, r20.bottom);
	CRect r22(r21.right + tag, r21.top, r21.right + tag + width, r21.bottom);
	CRect r23(r22.right + tag, r22.top, r22.right + tag + width, r22.bottom);
	CRect r24(r23.right + tag, r23.top, r23.right + tag + width, r23.bottom);

	m_pWnd1->Move(r1.left, r1.top, width, height);
	m_pWnd2->Move(r2.left, r2.top, width, height);
	m_pWnd3->Move(r3.left, r3.top, width, height);
	m_pWnd4->Move(r4.left, r4.top, width, height);
	m_pWnd5->Move(r5.left, r5.top, width, height);
	m_pWnd6->Move(r6.left, r6.top, width, height);
	m_pWnd7->Move(r7.left, r7.top, width, height);
	m_pWnd8->Move(r8.left, r8.top, width, height);
	m_pWnd9->Move(r9.left, r9.top, width, height);
	m_pWnd10->Move(r10.left, r10.top, width, height);
	m_pWnd11->Move(r11.left, r11.top, width, height);
	m_pWnd12->Move(r12.left, r12.top, width, height);
	m_pWnd13->Move(r13.left, r13.top, width, height);
	m_pWnd14->Move(r14.left, r14.top, width, height);
	m_pWnd15->Move(r15.left, r15.top, width, height);
	m_pWnd16->Move(r16.left, r16.top, width, height);
	m_pWnd17->Move(r17.left, r17.top, width, height);
	m_pWnd18->Move(r18.left, r18.top, width, height);
	m_pWnd19->Move(r19.left, r19.top, width, height);
	m_pWnd20->Move(r20.left, r20.top, width, height);
	m_pWnd21->Move(r21.left, r21.top, width, height);
	m_pWnd22->Move(r22.left, r22.top, width, height);
	m_pWnd23->Move(r23.left, r23.top, width, height);
	m_pWnd24->Move(r24.left, r24.top, width, height);
}

这里是通过“蛮力”的方式 来计算位置 根据第一个位置 以及设置好的宽高 来计算后面的位置;使用的时候根据自己的需要设置对应的【起始坐标】【宽】【高】【窗口间距】 上面的变量 m_pWndxx 这个就是对应的 SRealWnd 的指针 通过这个值 来控制窗口的位置和大小

 

最后看实现效果:

实现效果

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值