資源簡介
領導經常視察,所以決定動手做個隱藏/顯示打開的窗口及任務欄,查了許多資料,終于完成,其中涉及了:自定義熱鍵、讀寫注冊表、讀寫文本文件等技巧。希望能對有需要的同仁有所幫助。(用的是VS2008)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Runtime.InteropServices;
using?Microsoft.Win32;
using?System.IO;
namespace?MyPro
{
????public?partial?class?Form1?:?Form
????{
????????private?const?int?SWP_HIDEWINDOW?=?0x80;
????????private?const?int?SWP_SHOWWINDOW?=?0x40;
????????[DllImport(“user32.dll“)]
????????public?static?extern?bool?SetWindowPos(
????????int?hWnd???????????????????????????//???handle???to???window?????
????????int?hWndInsertAfter?????//???placement-order???handle?????
????????short?X???????????????????????????????????//???horizontal???position?????
????????short?Y???????????????????????????????????//???vertical???position?????
????????short?cx?????????????????????????????????//???width?????
????????short?cy?????????????????????????????????//???height?????
????????uint?uFlags?????????????????????????//???window-positioning???options?????
????????);
????????[DllImport(“user32.dll“)]
????????public?static?extern?int?FindWindow(
????????string?lpClassName?????//???class???name?????
????????string?lpWindowName?????//???window???name?????
????????);
????????[DllImport(“user32.dll“?SetLastError?=?true)]
????????public?static?extern?bool?RegisterHotKey(
????????????IntPtr?hWnd????????????????//要定義熱鍵的窗口的句柄?
????????????int?id?????????????????????//定義熱鍵ID(不能與其它ID重復)???????????
????????????KeyModifiers?fsModifiers???//標識熱鍵是否在按Alt、Ctrl、Shift、Windows等鍵時才會生效?
????????????Keys?vk?????????????????????//定義熱鍵的內容?
????????????);
????????[DllImport(“user32.dll“?SetLastError?=?true)]
????????public?static?extern?bool?UnregisterHotKey(
????????????IntPtr?hWnd????????????????//要取消熱鍵的窗口的句柄?
????????????int?id??????????????????????//要取消熱鍵的ID?
????????????);
????????[Flags()]
????????public?enum?KeyModifiers
????????{
????????????None?=?0
????????????Alt?=?1
????????????Ctrl?=?2
????????????Shift?=?4
????????????WindowsKey?=?8
????????}
????????public?Form1()
????????{
????????????InitializeComponent();
????????????//注冊熱鍵Shift+S,Id號為100。HotKey.KeyModifiers.Shift也可以直接使用數字4來表示。?
????????????RegisterHotKey(Handle?100?KeyModifiers.Alt?Keys.Z);
????????}
????????private?void?Form1_Activated(object?sender?EventArgs?e)
????????{
????????????//注冊熱鍵Shift+S,Id號為100。HotKey.KeyModifiers.Shift也可以直接使用數字4來表示。?
????????????RegisterHotKey(Handle?100?KeyModifiers.Alt?Keys.Z);
????????}?
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????myTaskbar();
????????}
????????private?void?ToggleDesktop()
????????{
????????????System.Diagnostics.Process?Myprocess;
????????????try
????????????{
????????????????Myprocess?=?new?System.Diagnostics.Process();
????????????????//打開MyDesktop.scf
????????????????Myprocess.StartInfo.FileName?=?“MyDesktop.scf“;
????????????????Myprocess.Sta
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????76??2008-10-24?17:41??MyPro\MyPro\bin\Debug\MyDesktop.scf
?????文件?????823808??2008-10-24?20:06??MyPro\MyPro\bin\Debug\老板鍵.exe
?????文件??????28160??2008-10-24?20:06??MyPro\MyPro\bin\Debug\老板鍵.pdb
?????文件??????14328??2008-10-24?20:06??MyPro\MyPro\bin\Debug\老板鍵.vshost.exe
?????目錄??????????0??2008-10-24?20:06??MyPro\MyPro\bin\Debug
?????文件?????????77??2008-10-24?19:40??MyPro\MyPro\bin\Release\MyDesktop.scf
?????文件??????14328??2008-10-24?19:54??MyPro\MyPro\bin\Release\MyPro.vshost.exe
?????文件????????490??2007-07-21?01:33??MyPro\MyPro\bin\Release\MyPro.vshost.exe.manifest
?????文件?????823808??2008-10-24?20:06??MyPro\MyPro\bin\Release\老板鍵.exe
?????文件??????26112??2008-10-24?20:06??MyPro\MyPro\bin\Release\老板鍵.pdb
?????文件??????14328??2008-10-24?20:05??MyPro\MyPro\bin\Release\老板鍵.vshost.exe
?????文件????????490??2007-07-21?01:33??MyPro\MyPro\bin\Release\老板鍵.vshost.exe.manifest
?????目錄??????????0??2008-10-24?20:06??MyPro\MyPro\bin\Release
?????目錄??????????0??2008-10-24?18:53??MyPro\MyPro\bin
?????文件?????323590??2006-05-07?03:58??MyPro\MyPro\browser.ico
?????文件?????323590??2006-05-07?03:58??MyPro\MyPro\bug.ico
?????文件?????323590??2006-05-07?03:58??MyPro\MyPro\cookie.ico
?????文件???????9361??2008-10-24?20:04??MyPro\MyPro\Form1.cs
?????文件???????5064??2008-10-24?20:03??MyPro\MyPro\Form1.Designer.cs
?????文件?????977275??2008-10-24?20:03??MyPro\MyPro\Form1.resx
?????文件???????3882??2008-10-24?20:05??MyPro\MyPro\MyPro.csproj
?????文件???????1620??2008-10-24?20:06??MyPro\MyPro\obj\Debug\MyPro.csproj.FileListAbsolute.txt
?????文件????????847??2008-10-24?20:06??MyPro\MyPro\obj\Debug\MyPro.csproj.GenerateResource.Cache
?????文件?????648048??2008-10-24?20:06??MyPro\MyPro\obj\Debug\MyPro.Form1.resources
?????文件????????180??2008-10-24?20:06??MyPro\MyPro\obj\Debug\MyPro.Properties.Resources.resources
?????目錄??????????0??2008-10-24?18:53??MyPro\MyPro\obj\Debug\Refactor
?????目錄??????????0??2008-10-24?18:53??MyPro\MyPro\obj\Debug\TempPE
?????文件?????823808??2008-10-24?20:06??MyPro\MyPro\obj\Debug\老板鍵.exe
?????文件??????28160??2008-10-24?20:06??MyPro\MyPro\obj\Debug\老板鍵.pdb
?????目錄??????????0??2008-10-24?20:06??MyPro\MyPro\obj\Debug
............此處省略24個文件信息
- 上一篇:一個用C#繪制的動態時鐘自定義控件
- 下一篇:ASP.NET寫的轉盤抽獎程序
評論
共有 條評論