2010年12月17日 星期五

使用 php winbinder 寫一個計算檔案的 MD5 碼

< ?php
include "winbinder.php";
define("IDC_STATUSWIN", 101);
define("IDC_TEXTWIN", 102);
define("ID_OPEN" , 201);
define("ID_CLOSE", 202);
function process_main($window, $id)
{
switch($id) {
case ID_OPEN:
$filename = wb_sys_dlg_open($window, "Choose a file", array(array("All files", "*.*")) );
if(file_exists($filename) )
{
$sn="S/N: ".md5_file($filename);
wb_set_text(wb_get_control($window,IDC_TEXTWIN) , $filename);
wb_set_text(wb_get_control($window,IDC_STATUSWIN), $sn );
}
break;
case IDCLOSE : // IDCLOSE is predefined
case ID_CLOSE: wb_destroy_window($window); break;
}
}
$mainwin = wb_create_window(null, AppWindow,"PHP " . PHP_VERSION, WBC_CENTER, WBC_CENTER,500,100);
wb_create_control($mainwin, Menu,
array(iconv('big5','utf-8',"檔案-&File"),
array(ID_OPEN ,iconv('big5','utf-8',"開啟-&Open") , NULL, "" ,"Ctrl+O"), null,
array(ID_CLOSE,iconv('big5','utf-8',"關閉-&Close"), NULL, "" ,"Ctrl+X")
)
);
wb_create_control($mainwin, Label ,"Choose a file" ,1, 10, 290, 80, IDC_TEXTWIN);
wb_create_control($mainwin, StatusBar,"MD5:" ,0, 0, 0, 0, IDC_STATUSWIN);
wb_set_handler($mainwin, "process_main");
wb_main_loop();
?>

沒有留言: