@@ -20,6 +20,7 @@ public partial class ControlPanel : Form
2020 private AppController appController ; //Controller for list and apps.
2121 private TimeData timeData ; //The data of current aim.
2222 private bool isLoaded ; //Show the state of initialization.
23+ private bool isChangeable = true ;
2324
2425 public ControlPanel ( bool hide )
2526 {
@@ -80,6 +81,7 @@ private void ControlPanel_FormClosing(object sender, FormClosingEventArgs e)//
8081 if ( ! isClosable ) //隐藏窗口
8182 {
8283 e . Cancel = true ;
84+ DisableSet ( ) ;
8385 Hide ( ) ;
8486 }
8587 else //退出前关闭保护进程
@@ -221,11 +223,15 @@ private void AddTitleButton_Click(object sender, EventArgs e)
221223
222224 private void RemoveTitleButton_Click ( object sender , EventArgs e )
223225 {
224- if ( titleListBox . SelectedIndex >= 0 )
226+
227+ if ( CheckPassword ( ) && CheckStop ( ) )
225228 {
226- titleListBox . Items . RemoveAt ( titleListBox . SelectedIndex ) ;
229+ if ( titleListBox . SelectedIndex >= 0 )
230+ {
231+ titleListBox . Items . RemoveAt ( titleListBox . SelectedIndex ) ;
232+ }
233+ SaveTitles ( ) ;
227234 }
228- SaveTitles ( ) ;
229235 }
230236 private void SaveTitles ( )
231237 {
@@ -267,7 +273,7 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
267273
268274 private void ClearButton_Click ( object sender , EventArgs e )
269275 {
270- if ( PasswordCheck ( ) )
276+ if ( CheckPassword ( ) && CheckStop ( ) )
271277 {
272278 appController . RemoveAll ( ) ;
273279 }
@@ -282,7 +288,7 @@ private void AppAddButton_Click(object sender, EventArgs e)
282288 private void RemoveButton_Click ( object sender , EventArgs e )
283289 {
284290 //检测密码设置
285- if ( PasswordCheck ( ) )
291+ if ( CheckPassword ( ) && CheckStop ( ) )
286292 {
287293 appController . Remove ( ) ;
288294 }
@@ -306,11 +312,11 @@ private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
306312 } ;
307313 Process . Start ( process ) ;
308314 }
309- Process [ ] processes = Process . GetProcesses ( ) ;
315+ Process [ ] processes = Process . GetProcesses ( ) ;
310316 //Title Management
311317 foreach ( Process process in processes )
312318 {
313- if ( ! string . IsNullOrWhiteSpace ( process . MainWindowTitle ) )
319+ if ( ! string . IsNullOrWhiteSpace ( process . MainWindowTitle ) )
314320 {
315321 foreach ( string str in titleListBox . Items )
316322 {
@@ -322,7 +328,7 @@ private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
322328
323329 private void ResetButton_Click ( object sender , EventArgs e )
324330 {
325- if ( PasswordCheck ( ) )
331+ if ( CheckPassword ( ) )
326332 {
327333 appController . Reset ( ) ;
328334 }
@@ -395,15 +401,14 @@ private void UnloackPasswordSetButton_Click(object sender, EventArgs e)//保存
395401
396402 private void UnlockPasswordRemoveButton_Click ( object sender , EventArgs e )
397403 {
398- if ( PasswordCheck ( ) )
404+ if ( CheckPassword ( ) )
399405 {
400406 File . Delete ( TCFile . PassLocation ) ;
401407 unlockPasswordHash = "" ;
402408 unlockPasswordBox . Text = "" ;
403409 unlockPasswordBox . Enabled = true ;
404410 unlockPasswordSetButton . Enabled = true ;
405411 unlockPasswordRemoveButton . Enabled = false ;
406- removeTitleButton . Enabled = true ;
407412 removeBootButton . Enabled = true ;
408413 }
409414 }
@@ -414,11 +419,10 @@ private void PasswordSet()//密码设置后调用
414419 unlockPasswordBox . Enabled = false ;
415420 unlockPasswordSetButton . Enabled = false ;
416421 unlockPasswordRemoveButton . Enabled = true ;
417- removeTitleButton . Enabled = false ;
418422 removeBootButton . Enabled = false ;
419423 }
420424
421- private bool PasswordCheck ( ) //检测密码是否正确
425+ private bool CheckPassword ( ) //检测密码是否正确
422426 {
423427 if ( ! string . IsNullOrEmpty ( unlockPasswordHash ) )
424428 {
@@ -443,7 +447,58 @@ private void RemoveBootButton_Click(object sender, EventArgs e)
443447 {
444448 TaskSchedulerControl . RemoveBoot ( ) ;
445449 }
450+ private bool CheckStop ( )
451+ {
452+ if ( ! isChangeable )
453+ {
454+ IntPtr nowDesktop = Dllimport . GetThreadDesktop ( Dllimport . GetCurrentThreadId ( ) ) ;
455+ IntPtr newDesktop = Dllimport . CreateDesktop ( "Lock" , null , null , 0 , Dllimport . ACCESS_MASK . GENERIC_ALL , IntPtr . Zero ) ;
456+ Dllimport . SwitchDesktop ( newDesktop ) ;
457+ Task . Factory . StartNew ( ( ) =>
458+ {
459+ Dllimport . SetThreadDesktop ( newDesktop ) ;
460+ InterruptWindow interruptWindow = new InterruptWindow ( ) ;
461+ Application . Run ( interruptWindow ) ;
462+ } ) . Wait ( ) ;
463+ Dllimport . SwitchDesktop ( nowDesktop ) ;
464+ Dllimport . CloseDesktop ( newDesktop ) ;
465+ if ( InterruptWindow . result == DialogResult . OK )
466+ {
467+ return true ;
468+ }
469+ else return false ;
470+ }
471+ else return true ;
472+ }
473+ private void StopCheckBox_CheckedChanged ( object sender , EventArgs e )
474+ {
475+ if ( stopCheckBox . Checked )
476+ {
477+ stopCheckBox . Enabled = false ;
478+ }
479+ SettingsChanged ( sender , e ) ;
480+ }
481+ private void EnableButton_Click ( object sender , EventArgs e )
482+ {
483+ if ( CheckPassword ( ) && CheckStop ( ) )
484+ {
485+ removeBootButton . Enabled = true ;
486+ stopCheckBox . Enabled = true ;
487+ }
488+ }
489+ private void DisableSet ( )
490+ {
491+ if ( ! string . IsNullOrWhiteSpace ( unlockPasswordHash ) )
492+ {
493+ removeBootButton . Enabled = false ;
446494
495+ }
496+ if ( stopCheckBox . Checked )
497+ {
498+ stopCheckBox . Enabled = false ;
499+ isChangeable = false ;
500+ }
501+ }
447502 #endregion ProtectPage
448503
449504 #region DataPage
@@ -536,6 +591,7 @@ private void SettingsChanged(object sender, EventArgs e)
536591 {
537592 Settings . Default . AutoReset = autoResetBox . Checked ;
538593 Settings . Default . AutoRefresh = autoRefreshBox . Checked ;
594+ Settings . Default . StopBeforeSetting = stopCheckBox . Checked ;
539595 Settings . Default . Save ( ) ;
540596 }
541597 }
@@ -544,6 +600,11 @@ private void InitializeSettings()
544600 {
545601 autoResetBox . Checked = Settings . Default . AutoReset ;
546602 autoRefreshBox . Checked = Settings . Default . AutoRefresh ;
603+ stopCheckBox . Checked = Settings . Default . StopBeforeSetting ;
604+ if ( stopCheckBox . Checked )
605+ {
606+ isChangeable = false ;
607+ }
547608 }
548609
549610 private void DataDirButton_Click ( object sender , EventArgs e )
0 commit comments