WPF 全屏时,程序运行和鼠标运动很慢的问题

<Window x:Class="WpfApp.Window1"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowState
="Maximized"
    Topmost
="True"
    WindowStyle
="None"
        AllowsTransparency
="True"
    Title
="Window1" Height="300" Width="300">
    
<Grid>
        
    
</Grid>
</Window>


 

启动动画,程序运行很慢,鼠标的运动很慢

 

 

解决方案 :

XAMLWindow属性中WindowStyle保留其默认值,

在窗口的加载响应函数里直接用了Win32 API函数来修改窗口的Style

 

这个是在网上找到的暂时解决方案


<Window x:Class="WpfApp.Window1"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    WindowState
="Maximized"
    Topmost
="True"
    Loaded
="OnMainLoad"

    Title
="Window1" Height="300" Width="300">
    
<Grid>
        
    
</Grid>
</Window>
private void OnMainLoad(object sender, RoutedEventArgs e)

{

int nStyle = Win32API.GetWindowLong(new WindowInteropHelper(this).Handle;,Win32API.GWL_STYLE);

nStyle 
&= ~Win32API.WS_CAPTION;

Win32API.SetWindowLong(
new WindowInteropHelper(this).Handle;, Win32API.GWL_STYLE, nStyle);

}

 

public class Win32API

{

     [DllImport(
"user32.dll")]

     
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int New);

       

     [DllImport(
"user32.dll")]

     
public  static extern int GetWindowLong(IntPtr hWnd, int nIndex);

}

 

public const int GWL_STYLE = -16;

public const int GWL_EXSTYLE = -20;       

public const int WS_CAPTION = 0x00C00000;

   

   


     

   

 

 

    

     

       

     

     

 

 

posted on 2009-06-03 13:37  imbob  阅读(865)  评论(0编辑  收藏  举报

导航