摘要:電腦屏幕的多屏顯示功能正逐漸應(yīng)用到人們?nèi)粘5纳願(yuàn)蕵泛统鲂修k公中。該文介紹了兩種C#常用的實(shí)現(xiàn)多屏顯示方法——調(diào)用API和調(diào)用Screen類,并結(jié)合具體代碼實(shí)現(xiàn)該功能,并演示了Windows多窗體的設(shè)置步驟。
關(guān)鍵詞:多屏顯示;Screen類;API接口;動(dòng)態(tài)鏈接庫
中圖分類號:G424 文獻(xiàn)標(biāo)識碼:A 文章編號:1009-3044(2014)20-4724-02
C# Two Methods to Realize Multi Screen Display
HE Jia-lin
(The Zhengzhou Air Harbor Economic Comprehensive Experimentation Area (Zhengzhou Xinzheng Comprehensive Bonded Zone) Port Service Bureau, Zhengzhou 450000,China)
Abstract: Multi screen computer display function is gradually applied to people's daily life and entertainment and travel office. This paper introduces two kinds of commonly used C# to realize multi screen display method — called API and calls the Screen class, and the realization of the function of specific code, and demonstrates the setting step windows form.
Key words: multi screen display, Screen class, API interface, dynamic link library
Windows為了解決運(yùn)行復(fù)雜任務(wù)問題開發(fā)了擴(kuò)展屏幕功能,如今這種應(yīng)用已有了更廣泛的用途。家庭多媒體和液晶電視配備的VGA和HDMI接口為擴(kuò)展屏幕提供了很好的硬件支持。將電視轉(zhuǎn)換成顯示器不僅可以應(yīng)用到家庭娛樂上,在一些窗口性政府辦公場所以及銀行、醫(yī)院等地方也越來越多地用到了此功能。
要實(shí)現(xiàn)多屏顯示功能除了需要在操作系統(tǒng)里進(jìn)行桌面顯示設(shè)置外,還需要在代碼實(shí)現(xiàn)上調(diào)用Windows提供的API接口或相關(guān)的函數(shù)。
下面介紹兩種常用的用C#實(shí)現(xiàn)多屏顯示的方法。
1 調(diào)用API接口
調(diào)用API接口法,需要調(diào)用user32.dll動(dòng)態(tài)鏈接庫。user32.dll是Windows用戶界面相關(guān)應(yīng)用程序接口,用于包括Windows處理、基本用戶界面設(shè)置等功能的實(shí)現(xiàn),比如要?jiǎng)?chuàng)建窗口和發(fā)送消息時(shí)都需要調(diào)用里面的相應(yīng)函數(shù)。在VS開發(fā)工具中創(chuàng)建一個(gè)新的項(xiàng)目時(shí)會自動(dòng)引用user32.dll,因此在調(diào)用該函數(shù)時(shí)只需要加個(gè)外部引用即可。
多窗體顯示程序用到的接口函數(shù)為SetWindowPos,其功能是將一個(gè)窗口在三維空間中移動(dòng)。它可以改變一個(gè)窗口的位置,其中包括X軸、Y軸,甚至可以在Z軸上改變(Z軸決定了一個(gè)窗口和其它窗口的前后關(guān)系),另外它還可以改變窗口的尺寸?!?br>