SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST+SHCNF_FLUSH, 0, 0);
| TBrowseInfo = packed record hwndOwner: HWND; pidlRoot: PItemIDList; pszDisplayName: PChar; lpszTitle: PChar; ulFlags: UINT; lpfn: TFNBFFCallBack; lParam: LPARAM; iImage: Integer; end; |
| //在對話框中會包含一個狀態區,回調函數可以通過向對話框發送消息來設定狀態 BIF_STATUSTEXT //只允許選擇標準文件系統,若選了非標準的文件夾如打印機,確認按鈕會變灰 BIF_RETURNONLYFSDIRS = $0001; //不選擇網絡文件夾 BIF_DONTGOBELOWDOMAIN = $0002; // 給狀態條留出空白 BIF_STATUSTEXT = $0004; // 只選擇文件系統的上級目錄 BIF_RETURNFSANCESTORS = $0008; //只選擇計算機 BIF_BROWSEFORCOMPUTER = $1000; //只選擇打印機 BIF_BROWSEFORPRINTER = $2000; //包括文件也可以選 BIF_BROWSEINCLUDEFILES = $4000; |
| TFNBFFCallBack = function(DialogHandle: HWND; MessageID: UINT; PIDL: PItemIDList; Data: LPARAM):Integer; stdcall; |
| BFFM_INITIALIZED = 1; // 對話框將要顯示 BFFM_SELCHANGED = 2; // 用戶選中了某項 |
| function BrowseForFolderCallback(DialogHandle: HWND; MessageID: UINT; PIDL: PItemIDList; Data: LPARAM): Integer; begin //響應對話框的通知消息 case (MessageID) of BFFM_INITIALIZED: DialogInitialized(DialogHandle, Data); BFFM_SELCHANGED: HandleNewSelection(DialogHandle, PIDL, Data); end; Result := 0; // 總返回0. end; |
| // 改變對話框的狀態信息 BFFM_SETSTATUSTEXT = WM_USER + 100; //控制確定按鈕失效與否 BFFM_ENABLEOK = WM_USER + 101; //改變選擇的文件夾 BFFM_SETSELECTION = WM_USER + 102; |
|
| function ShellAbout(Owner: HWND; ApplicationName: PChar; OtherText: PChar; IconHandle: HICON): Integer; stdcall; |


| function SHFormatDrive(Owner: HWND; Drive: UINT; FormatID: UINT; OptionFlags: UINT): DWORD; stdcall; |
| SHFMT_OPT_FULL = $0001; // 快速格式化 SHFMT_OPT_SYSONLY = $0002; // 復制系統文件 |
| SHFMT_NOFORMAT = $FFFFFFFD; // 驅動器無法格式化 SHFMT_CANCEL = $FFFFFFFE; //格式化被取消了 SHFMT_ERROR = $FFFFFFFF; //其他錯誤 |

| function PickIconDlg(Owner: HWND; FileName: Pointer; MaxFileNameChars: DWORD; var IconIndex: DWORD):LongBool; stdcall; |

| procedure RunFileDlg(Owner: HWND; IconHandle: HICON; WorkPath: Pointer; Caption: Pointer; Description: Pointer; Flags: UINT); stdcall; |
| RFF_NOBROWSE = $01; // 移去瀏覽按鈕 RFF_NODEFAULT = $02; // 無缺省的選項 RFF_CALCDIRECTORY = $04; // 由文件名確定工作路徑 RFF_NOLABEL = $08; // 去掉編輯框標簽 RFF_NOSEPARATEMEM = $20; // 去掉在單獨的內存空間運行的復選框 (只對NT有效) |
| TNM_RunFileDlg = packed record hdr: TNMHdr; lpFile: Pointer; lpDirectory: Pointer; nShow: LongBool; end; |
| TNMHdr = packed record hwndFrom: HWND; idFrom: UINT; code: UINT; end; |
| var FileToRun: String; ... if TheMessage.Msg = WM_NOTIFY then if PNMHdr(TheMessage.LParam).code = RFN_VALIDATE then WideCharToStrVar(PNM_RUNFILEDLG( TheMessage.LParam).lpFile, FileToRun); ... |
| RF_OK = $00; //允許程序運行 RF_CANCEL = $01; //取消操作,關閉對話框 RF_RETRY = $02; //取消操作,對話框仍然打開 |

| function SHFindFiles(SearchRoot: PItemIDList; SavedSearchFile: PItemIDList): LongBool; stdcall; |
| function SHFindComputer(Reserved1: PItemIDList; Reserved2: PItemIDList): LongBool; stdcall; |
| function GetFileNameFromBrowse(Owner: HWND; FileName: Pointer; MaxFileNameChars: DWORD; InitialDirectory: Pointer; DefaultExtension: Pointer; Filter: Pointer; Caption: Pointer): LongBool; stdcall; |

| function SHObjectProperties(Owner: HWND; Flags: UINT; ObjectName: Pointer; InitialTabName: Pointer):LongBool; stdcall; |
| //打印機 OPF_PRINTERNAME = $01; //路徑 OPF_PATHNAME = $02; |

| function SHNetConnectionDialog(Owner: HWND; ResourceName: Pointer; ResourceType: DWORD): DWORD; stdcall; |
| function SHStartNetConnectionDialog(Owner: HWND; ResourceName: PWideChar; ResourceType: DWORD):DWORD; stdcall; |

| procedure ExitWindowsDialog(Owner: HWND); stdcall; function RestartDialog(Owner: HWND; Reason: Pointer; ExitType: UINT): DWORD; stdcall; |
| EWX_LOGOFF = $00; EWX_SHUTDOWN = $01; EWX_REBOOT = $02; EW_RESTARTWINDOWS = $42; EW_REBOOTSYSTEM = $43; EW_EXITANDEXECAPP = $44; |
| function SHOutOfMemoryMessageBox(Owner: HWND; Caption: Pointer; Style: UINT): Integer; stdcall; |

| procedure SHHandleDiskFull(Owner: HWND; Drive: UINT); stdcall; |
| function ShellMessageBoxA(Module: THandle; Owner: HWND; Text: PChar; Caption: PChar; Style: UINT; Parameters: array of Pointer): Integer; cdecl; |
| function ShellMessageBoxW(Module: THandle; Owner: HWND; Text: PWideChar; Caption: PWideChar; Style: UINT; Parameters: array of Pointer): Integer; cdecl; |
首先,先簡單介紹一下MD5
MD5的全稱是message-digest algorithm 5(信息-摘要算法,在90年代初由mit laboratory for computer science和rsa data security inc的ronald l. rivest開發出來, 經md2、md3和md4發展而來。
MD5具有很好的安全性(因為它具有不可逆的特征,加過密的密文經過解密后和加密前的東東相同的可能性極小)
引用
using System.Security.Cryptography;
using System.Text;
具體代碼如下(寫在按鈕的Click事件里):
byte[] result = Encoding.Default.GetBytes(this.tbPass.Text.Trim()); //tbPass為輸入密碼的文本框
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
this.tbMd5pass.Text = BitConverter.ToString(output).Replace("-",""); //tbMd5pass為輸出加密文本的文本框
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/lykycs/archive/2006/06/16/802873.aspx
再談異常――談C++與Object Pascal中的構造函數與異常
作者:Nicrosoft(nicrosoft@sunistudio.com) 2001.9.15
個人主頁:http://www.sunistudio.com/nicrosoft/
東日文檔:http://www.sunistudio.com/asp/sunidoc.asp
我們知道,類的構造函數是沒有返回值的,如果構造函數構造對象失敗,不可能依靠返回錯誤代碼。那么,在程序中如何標識構造函數的失敗呢?最“標準”的方法就是:拋出一個異常。
構造函數失敗,意味著對象的構造失敗,那么拋出異常之后,這個“半死不活”的對象會被如何處理呢?這就是本文的主題。
在C++中,構造函數拋出異常后,析構函數不會被調用。這是合理的,因為此時對象并沒有被完整構造。也就是說,如果構造函數已經做了一些諸如分配內存、
打開文件等操作的話,那么類需要有自己的成員來記住做過哪些動作。在C++中,經典的解決方案是使用STL的標準類auto_ptr,這在每一本經典
C++著作中都有介紹,我在這里就不多說了。在這里,我想再介紹一種“非常規”的方式,其思想就是避免在構造函數中拋出異常。我們可以在類中增加一個
Init(); 以及 UnInit();成員函數用于進行容易產生錯誤的資源分配工作,而真正的構造函數中先將所有成員置為NULL,然后調用
Init(); 并判斷其返回值(或者捕捉 Init()拋出的異常),如果Init();失敗了,則在構造函數中調用 UnInit();
并設置一個標志位表明構造失敗。UnInit()中按照成員是否為NULL進行資源的釋放工作。示例代碼如下:
class A
{
private:
char* str;
int failed;
public:
A();
~A();
int Init();
int UnInit();
int Failed();
};
A::A()
{
str = NULL;
try
{
Init();
failed = 0;
}
catch(...)
{
failed = 1;
UnInit();
}
}
A::~A()
{
UnInit();
}
int A::Init()
{
str = new char[10];
strcpy(str, "ABCDEFGHI");
throw 10;
return 1;
}
int A::UnInit()
{
if (!str)
{
delete []str;
str = NULL;
}
printf("Free Resource
");
return 1;
}
int A::Failed()
{
return failed;
}
int main(int argc, char* argv[])
{
A* a = new A;
if ( a->Failed() )
printf("failed
");
else
printf("succeeded
");
delete a;
getchar();
return 0;
}
你會發現,在int A::Init()中包含了throw 10;的代碼(產生一個異常,模擬錯誤的發生),執行結果是:
Free Resource
failed
Free Resource
雖然 UnInit();被調用了兩次,但是由于UnInit();中做了判斷(if (!str)),因此不會發生錯誤。而如果沒有發生異常(去掉 int A::Init()中的throw 10;代碼),執行結果是:
Succeeded
Free Resource
和正常的流程沒有任何區別。
在Object Pascal(Delphi/VCL)中,這個問題就變得非常的簡單了,因為 OP
對構造函數的異常的處理與C++不同,在Create時拋出異常后,編譯器會自動調用析構函數Destroy,并且會判斷哪些資源被分配了,實行自動回
收。因此,其代碼也變得非常簡潔,如下:
type
A = class
private
str : PChar;
public
constructor Create();
destructor Destroy(); override;
end;
constructor A.Create();
begin
str := StrAlloc(10);
StrCopy(str, 'ABCDEFGHI');
raise Exception.Create('error');
end;
destructor A.Destroy();
begin
StrDispose(str);
WriteLn('Free Resource');
end;
var oa : A;
i : integer;
begin
try
oa := A.Create();
WriteLn('Succeeded');
oa.Free();
except
oa := nil;
WriteLn('Failed');
end;
Read(i);
end.
在這段代碼中,如果構造函數拋出異常(即Create中含有raise Exception.Create('error');),執行的結果是:
Free Resource
Failed
此時的“Free Resource”輸出是由編譯器自動調用析構函數所產生的。而如果構造函數正常返回(即不拋出異常),則執行結果是:
Succeeded
Free Resource
此時的“Free Resource”輸出是由 oa.Free()的調用產生的。
綜上,C++與Object Pascal對于構造函數拋出異常后的不同處理方式,其實正是兩種語言的設計思想的體現。C++秉承C的風格,注重效率,一切交給程序員來掌握,編譯器不 作多余動作。Object Pascal繼承Pascal的風格,注重程序的美學意義(不可否認,Pascal代碼是全世界最優美的代碼),編譯器幫助程序員完成復雜的工作。兩種語 言都有存在的理由,都有存在的必要!而掌握它們之間的差別,能讓你更好地控制它們,達到自由的理想王國。
串口通訊中的DCB結構
typedef struct _DCB {// dcb
DWORD DCBlength; // sizeof(DCB)
DORD BaudRate; // current baud rate 指定當前的波特率
DWORD fBinary: 1; // binary mode, no EOF check 指定是否允許二進制模式WIN95中須為TRUE
DWORD fParity: 1; // enable parity checking 指定奇偶校驗是否允許
DWORD fOutxCtsFlow:1; // CTS output flow control 指定CTS是否用于檢測發送控制。當為TRUE是CTS為OFF,發送將被掛起。
DWORD fOutxDsrFlow:1; // DSR output flow control
DWORD fDtrControl:2; // DTR flow control type
DTR_CONTROL_DISABLE 值將DTR置為OFF,DTR_CONTROL_ENABLE值將DTR置為ON,
DTR_CONTROL_HANDSHAKE 允許DTR"握手",
DWORD fDsrSensitivity:1;// DSR sensitivity 當該值為TRUE時DSR為OFF時接收的字節被忽略
DWORD fTXContinueOnXoff:1; // XOFF continues Tx
DWORD fOutX: 1; // XON/XOFF out flow control
DWORD fInX: 1; // XON/XOFF in flow control
DWORD fErrorChar: 1; // enable error replacement
DWORD fNull: 1; // enable null stripping TRUE時,接收時去掉空(0值)字節
DWORD fRtsControl:2; // RTS flow control
DWORD fAbortOnError:1; // abort reads/writes on error TRUE時,有錯誤發生時中止讀和寫操作RTS_CONTROL_DISABLE時,RTS置為OFFRTS_CONTROL_ENABLE時, RTS置為ON
RTS_CONTROL_HANDSHAKE時,當接收緩沖區小于半滿時RTS為ON當接收緩沖區超過四分之三滿時RTS為OFF
RTS_CONTROL_TOGGLE時,當接收緩沖區仍有剩余字節時RTS為ON ,否則缺省為OFF
DWORD fDummy2:17; // reserved 未使用
WORD wReserved; // not currently used 未使用,必須為0
WORD XonLim; // transmit XON threshold
WORD XoffLim; // transmit XOFF threshold
BYTE ByteSize; // number of bits/byte, 4-8 指定端口當前使用的數據位
BYTE Parity; // 0-4=no,odd,even,mark,space 指定端口當前使用的奇偶校驗方法,可能為:
StopBits;
char XonChar; // Tx and Rx XON character 指定用于發送和接收字符XON的值
char XoffChar; // Tx and Rx XOFF character 指定用于發送和接收字符XOFF值
char ErrorChar; // error replacement character本字符用來代替接收到的奇偶校驗發生錯誤時的值
char EofChar; // end of input character 當沒有使用二進制模式時,本字符可用來指示數據的結束
char EvtChar; // received event character 當接收到此字符時,會產生一個事件
WORD wReserved1; // reserved; do not use 未使用
} DCB;
CSS切換皮膚切換代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<html xmlns=" <head>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<meta name="generator" content="" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="robots" content="index, follow" />
<meta name="googlebot" content="index, follow" />
<title> </title>
<link rel="stylesheet" type="text/css" href="code/changestyle/styles1.css" title="styles1" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="code/changestyle/styles2.css" title="styles2" media="screen" />
<link rel="alternate stylesheet" type="text/css" href="code/changestyle/styles3.css" title="styles3" media="screen" />
<script type="text/javascript">
window.onload=function(){ var c = readCookie('style');
if (c) switchStylestyle(c);
};
function switchStylestyle(styleName)
{ aa=document.styleSheets;
for(i=0;i<aa.length;i++)
{
aa[i].disabled = true;
if (aa[i].title== styleName){aa[i].disabled = false;}
};
createCookie('style', styleName, 365);
}
function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name)
{
createCookie(name,"",-1);
}
// /cookie functions
</script>
</head>
<body id="">
<div id="wrapper">
<ul>
<li><a href="javascript:void(0);" onclick="switchStylestyle('styles1')">styles1</a></li>
<li><a href="javascript:void(0);" onclick="switchStylestyle('styles2')">styles2</a></li>
<li><a href="javascript:void(0);" onclick="switchStylestyle('styles3')">styles3</a></li>
</ul
</div>
</body>
</html>
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
|---|---|---|---|---|---|---|---|---|---|
| 31 | 1 | 2 | 3 | 4 | 5 | 6 | |||
| 7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
| 28 | 29 | 30 | 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
