扩展屏幕不是问题,通过以下代码就能搞定:
1 class MFCScreenExtensionDLL 2 { 3 // nMode:enum {DISPLAY_TYPE_SINGLE=8,DISPLAY_TYPE_CLONE=2,DISPLAY_TYPE_EXTEND=4}; 4 [DllImport("MFCScreenExtension.dll", EntryPoint = "SetDisplayMode", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] 5 public static extern int SetDisplayMode(int nMode); 6 7 8 [DllImport("MFCScreenExtension.dll", EntryPoint = "GetDisplayMode", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)] 9 public static extern int GetDisplayMode(); 10 }
现在的关键是如何从WPF窗口中分离出WindowsFormsHost并显示在另一个屏幕上,实际上如果能够分离出WindowsFormsHost,然后适当设置它的位置,就会显示在另一个屏幕上了。
1 <Window x:Class="ScreenExtensionDemo.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="350" Width="525"> 5 <Grid> 6 <Grid.RowDefinitions> 7 <RowDefinition></RowDefinition> 8 <RowDefinition></RowDefinition> 9 <RowDefinition></RowDefinition> 10 </Grid.RowDefinitions> 11 12 <Grid.ColumnDefinitions> 13 <ColumnDefinition></ColumnDefinition> 14 <ColumnDefinition></ColumnDefinition> 15 <ColumnDefinition></ColumnDefinition> 16 </Grid.ColumnDefinitions> 17 18 <WindowsFormsHost x:Name="form1" Grid.Column="1"> 19 <ElementHost> 20 <Image Source="./1.jpg"></Image> 21 </ElementHost> 22 </WindowsFormsHost> 23 24 <WindowsFormsHost x:Name="form2" Grid.Row="1"> 25 <ElementHost> 26 <Image Source="./2.jpg"></Image> 27 </ElementHost> 28 </WindowsFormsHost> 29 30 <WindowsFormsHost x:Name="form3" Grid.Row="2" Grid.Column="1"> 31 <ElementHost> 32 <Image Source="./3.png"></Image> 33 </ElementHost> 34 </WindowsFormsHost> 35 36 <Button x:Name="btnExtendScreen" Grid.Row="1" Grid.Column="2" Content="Extend Screen" Click="Button_Click"></Button> 37 </Grid> 38 </Window>
求各路大神指路,我如果没有表达清楚,随时call 我。时别一年多后再次回归博客园,园豆不多。请海涵。希望能够打响第一炮。
手机:13552351806
QQ:1352288123