2017-06-19 7 views
0

私は、スクリーンセーバーが実行中で、ウィンドウがタイマーオブジェクトによってウィンドウをポップアップするためにShowDialogを使用したときに、とても奇妙なシーンのように見えるWPFフレームワークを使用したシステムを維持しました。これはポップアップウィンドウが表示されませんでした任意のテキスト、ボタン、および別のコントロール、その全体のビューは空白です。スクリーンセーバーが実行されないと、ポップアップウィンドウが表示されます。 スクリーンセーバーが動作しているときにポップアップウィンドウをレンダリングできないのはなぜですか?

私は、スクリーンセーバーが実行されているときにポップアップウィンドウに表示の問題があることを意味します。スクリーンセーバーが実行されない場合、ポップアップは正常に機能します。 enter image description here

この問題は、自分の開発環境ではローカルでは再生できません。それは特定のPC(Windows 8.1の埋め込み版)のために実行されます

私は直接ShowDialogウィンドウの前にスクリーンセーバーを中断する解決するために経路を考え出しました。これらは以下のように含まれます。

  • a。マウスを動かす(user32のmouse_event apiを使用)
  • b。送信キー(user32のapiも使用)
  • c。スクリーンセーバープロセスを終了します。
  • d。フレームワークにアップグレード4.6.2

上記の方法を参照してください上記の方法は、すべて私のローカル(Windows 10)ではうまくいくが、その特定のPC(Windows 8.1の組み込みバージョン) 確かに。私は知りませんでした https://www.codeproject.com/Articles/17067/Controlling-The-Screen-Saver-With-C

https://support.microsoft.com/en-us/help/140723/how-to-force-a-screen-saver-to-close-once-started-in-windows-nt,-windows-2000,-and-windows-server-2003

How to interrupt Screen-saver under windows 8

私はこの割り込みスクリーンセーバの道をあきらめた、私はこの問題を解決するために、別のキーポイントを見て期待し、だがに焦点を当てるべきですコードのどの部分。私に何か提案がありますか?ありがとうございます。私は以下のようにデモを書いたために、元のプロジェクトのこの部分のロジックによると、

メインウィンドウのコード

using OutdoorCentral.WPF.UI; 
using System; 
using System.Configuration; 
using System.Diagnostics; 
using System.Runtime.InteropServices; 
using System.Threading; 
using System.Windows; 
using System.Windows.Input; 

namespace WpfApplication1 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     private static object inactivityLockObject = "InactivityLockObject"; 
     protected delegate void func(); 
     private static Timer checkActivityTimer; 
     public MessageDialog msg = new MessageDialog(); 

     public enum MessageWindowType 
     { 
      OK, 
      OKCancel, 
      YesNo, 
      YesNoCancel 
     } 

     public MainWindow() 
     { 
      InitializeComponent(); 
      this.Title = "test"; 
      AutoResetEvent autoResetEvent = new AutoResetEvent(false); 
      checkActivityTimer = new Timer(CheckActivityCallback, autoResetEvent, new TimeSpan(0, 2, 0), new TimeSpan(0, 2, 0)); 
     } 

     private void CheckActivityCallback(object stateInfo) 
     { 
      CheckActivity(); 
     } 

     private void CheckActivity() 
     { 
      lock (inactivityLockObject) 
      { 
       InvokeOnUiThread(ForceLogout); 
      } 
     } 

     protected void InvokeOnUiThread(func method) 
     { 
      Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, method); 
     } 

     private void ForceLogout() 
     { 
      checkActivityTimer.Dispose(); 
      msg.TitleLabel.Content = Title; 
      msg.Topmost = true; 
      msg.Message = "test focus on message missed"; 
      msg.MessageWindowType = MessageWindowType.OK; 
      msg.ShowDialog(); 
     } 
    } 
} 

using System.Diagnostics; using Microsoft.Win32; using System.Windows; using System; using System.Threading; using System.Runtime.InteropServices; using WpfApplication1; using static WpfApplication1.MainWindow; namespace OutdoorCentral.WPF.UI { /// <summary> /// Interaction logic for MessageDialog.xaml /// </summary> public partial class MessageDialog : Window { public MessageDialog() { InitializeComponent(); Loaded += new RoutedEventHandler(MessageDialog_Loaded); } public bool? MessageResult { get; set; } void MessageDialog_Loaded(object sender, RoutedEventArgs e) { SetWindowType(); } new string Title { get { return TitleLabel.Content.ToString(); } set { TitleLabel.Content = value; } } public string Message { get { return MessageText.Text; } set { MessageText.Text = value; } } private MessageWindowType messageWindowType; public MessageWindowType MessageWindowType { get { return messageWindowType; } set { messageWindowType = value; SetWindowType(); } } private void SetWindowType() { switch (MessageWindowType) { case MessageWindowType.OKCancel: CancelButton.Visibility = Visibility.Visible; break; case MessageWindowType.YesNo: OKButton.Content = "Yes"; NoButton.Visibility = Visibility.Visible; break; case MessageWindowType.YesNoCancel: OKButton.Content = "Yes"; CancelButton.Visibility = Visibility.Visible; NoButton.Visibility = Visibility.Visible; break; } } private void Done(object sender, RoutedEventArgs e) { this.DialogResult = true; MessageResult = true; } private void NoSelection(object sender, RoutedEventArgs e) { this.DialogResult = false; MessageResult = false; } public void Canceled(object sender, RoutedEventArgs e) { MessageResult = null; this.Close(); } private void Window_LostFocus(object sender, RoutedEventArgs e) { this.Focus(); } } } 

以下のようにポップアップウィンドウのコードがありました

実際、以下のコードは非常に簡単です。私にいくつか提案してください。前もって感謝します。

+1

は、Googleが翻訳使用しましたか?私はあなたの質問がほとんど判読できないと感じます。 –

+0

お返事ありがとうございます、私は再度説明を改訂しました。もう一度見ていただけますか? –

+0

これを参照してください、関連する可能性があります:https://www.codeproject.com/Answers/187206/WPF-Application-windows-does-notfully--refreshed-a#answer1 – grek40

答えて

0

SPI_GETSCREENSAVERRUNNINGパラメータを使用してSystemParametersInfo()にクエリを実行してスクリーンセーバーが実行されているかどうかを確認することができます(「スクリーンセーバーのオン/オフ」などのイベントはありません)。したがって、スクリーンセーバーがアクティブであることを検出すると、スクリーンセーバーがオフになるまでポップアップを延期することができます。

[DllImport("user32.dll", CharSet=CharSet.Auto)] 
public static extern int SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int fuWinIni); 

const int SPI_GETSCREENSAVERRUNNING = 114; 
int screenSaverRunning = -1; 

// is the screen saver running? 

int ok = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref screenSaverRunning, 0); 

if (ok == 0) 
{ 
    Console.WriteLine("Call to SystemParametersInfo failed."); 
} 

if (screenSaverRunning != 0) 
{ 
    // screen saver is running 
    ... do something ... 
} 
else 
{ 
    // screen saver is NOT running 
    ... do other thing ... 
} 

オリジナルリンク:https://bytes.com/topic/c-sharp/answers/261540-detecting-screensaver-state

+0

ありがとうございます。私もこのリンクを見ていましたが、Windows 10では動作しませんでした –

+0

私はもっと多くの専門家がこの問題に答えることを願っています。私は皆さんに助けを必要とします。 –

+0

誰かが私に答えますか? –

関連する問題