Delphi開發的小程序

Delphi開發的小程序,全代碼實現友好界面,具有增量備份功能


//文件 mini_pe.dpr
uses
  {$IFDEF WIN32} Windows {$ELSE} WinProcs {$ENDIF},Messages,shellapi,tlhelp32,SysUtils,dateutils,winSock;

const
  MI_ICONEVENT = WM_USER + 1;
  szAppName : PChar = 'demoWindow 1.0';
  txtFile1 = '2008.txt';
  txtFile2 = 'info.txt';
  ID_SYS1 = 8001;

  ID_Open = 4001;
  ID_Save = 4002;
  ID_Close = 4003;

  ID_NEW1 = 4008;

var
  wc: WNDCLASS;
  RichWnd, hwndCombox, hwndtooltip1, hwndtooltip2, hwndtooltip3, hwndtooltip4, hwndtooltip5, hwndtooltip6, hwndtooltip7, hwndtooltip8, hwndtooltip9, image1, image2, image3, Button1, Button2, Button3, Button4,Imsctls_statusbar32, IImsctls_statusbar32, Label0, Label1, Label2, Label3, Label4, Edit1, Edit2, Edit3,HMainWnd, Font: HWND;
  i, tmpInt1, BufPro, WinLong1: integer;
  dc, dc1, dc2: HDC;
  mainRect, Rect1 : TRect;
  nid: TnotifyIcondata;
  ficon1 : HICON;
  H1, H2 : HBitmap;
  winTBit1 : windows.TBitmap;
  debfile1: textfile;
  pt : TPoint;
  pointer1 : POINTER;
  pm1, pm2 : HMENU;
  ProPChar1, StrPasmText, className, R1 : PChar;
  lpText1 : PansiChar;
  AMsg : MSG;

//{$R fr.res}
//往一個窗口寫標題
procedure WriteCaption(hwnd:hwnd;text:pchar); stdcall;
begin
sendmessage(hwnd,WM_SETTEXT,0,integer(text));
end;
//從一個窗口讀標題
procedure ReadCaption(hwnd:hwnd;text:pchar); stdcall;
begin
sendmessage(hwnd,WM_GETTEXT,400,integer(text));
end;

Procedure ontimer; stdcall;
begin
DrawFrameControl(DC1, Rect1, DFCS_CAPTIONMIN or DFCS_BUTTON3STATE or DFCS_BUTTONPUSH, DFC_CAPTION);
lpText1 := '定時器已運作';
TextOut(GetWindowDC(0), 380, 310, lpText1, length(lpText1)); //能在桌面上顯示文字
WriteCaption(HMainWnd, '定時器');
end;

Procedure ico(char1 : PansiChar); stdcall;
Begin
Shell_NotifyIcon(NIM_DELETE,@nid);
StrPCopy(nid.szTip, char1);
shell_notifyicon(nim_add, @nid);
end;

Procedure SaveInfo(str: string); stdcall;
var i : integer;
Begin
if fileexists(txtFile1) then
  begin
  SetFileAttributes(txtFile1, FILE_ATTRIBUTE_NORMAL);
  assignfile(debfile1, txtfile1);
  append(debfile1);
  writeln(debfile1, str);
  closefile(debfile1);
  SetFileAttributes(txtFile1, FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM);
  end
  else begin
        i := filecreate(txtFile1);
        FileClose(i);
        assignfile(debfile1, txtfile1);
        append(debfile1);
        write(debfile1, str);
        closefile(debfile1);
        end;
end;

Function WndProc(AWnd:HWND; message:UINT; wp:WPARAM; lp:LPARAM):LRESULT;stdcall;
var
 tmpStr1, ch, PrvChar : string;
 tmpPChar1 : PChar;
 tmpInt1, tmpInt2, cxClient, cyClient, hdcClient, hdcWindow, n, iShift, iCapital, iNumLock : integer;
 ps: PAINTSTRUCT;
 phPalette : hPalette;
begin
  Result := 0;
  case message of
    WM_Move : InvalidateRect(AWnd, PRECT(0), true);
    WM_SIZE: Begin
      cxClient := LOWORD(lP);
      cyClient := HIWORD(lP);
      InvalidateRect(AWnd, PRECT(0), true);
      End;
    WM_TIMER: ontimer;
    WM_NCRBUTTONDOWN: begin
      GetCursorPos(pt);
      tmpWnd1 := GetSystemMenu(AWnd, true);
      TrackPopupMenu(pm2, (TPM_BottomAlign or TPM_RightAlign or TPM_LEFTALIGN or TPM_RIGHTBUTTON), pt.x, pt.y, 0, HMainWnd, Nil)// then GetWindowText(tmpWnd1, tmpChar, 256);
      end;
    WM_COMMAND: Begin
      if (HWND(lP) = Button1) or (wP = 13) then
        begin
          GetMem(ProPChar1, 512);
          SendMessage(Edit1, WM_GETTEXTLENGTH, 0, 0);
          Bufpro := LongInt(ProPChar1);
          SendMessage(Edit1, WM_GETTEXT, 512, Bufpro);
          Edit1Text := StrPas(ProPChar1);
          SendMessage(Edit2, WM_GETTEXTLENGTH, 0, 0);
          SendMessage(Edit2, WM_GETTEXT, 512, Bufpro);
          Edit2Text := StrPas(ProPChar1);
        ShellExecute(Button1, 'open', Pansichar('cmd'), Pansichar(' /K xcopy ' + Edit1text + ' ' + Edit2text + ' /D /E /H /Y'), '', SW_SHOWNORMAL);
        tmpInt1 := SetTimer(awnd, 100, 6000, nil);  //句柄 未知 延時 指針
        end;
      case HWND(wP) of
        ID_Open: begin
          MessageBox(HMainWnd, '你點擊了菜單“打開”!', '信息', MB_ICONINFORMATION + MB_OK);
          GetObject(H1, sizeof(winTBit1),@winTBit1);
          windows.TextOut(DC1, 380, 310, szAppName, length(szAppName)); //在桌面上顯示文字
          windows.DrawIcon(DC1, 380, 240, ficon1);//在桌面上顯示 Ico圖標
          Exit;
        end;
        ID_NEW1: begin
          ShellExecute(HMainWnd, 'open', Pansichar('"C:/Program Files/Chinatelecom C+W/C+WClient.exe"'), Pansichar(''), '', SW_NORMAL);
          SaveInfo(' ** 已經打開“中國電信無線客戶端” ** ' + #13 + '開始上網時間: '+ Datetimetostr(now));
          Exit;
        end;
        ID_SYS1: begin
          ShellExecute(HMainWnd, 'open', Pansichar('TTPlayer.exe'), Pansichar(''), '', Windows.SW_SHOWNORMAL);
          Exit;
        end;
         ID_Close: begin
          AnimateWindow(HmainWND, 1000, AW_HIDE or AW_SLIDE or AW_HOR_POSITIVE);
          MessageBoxA(HMainWnd, lpText1, 'demoWindow將自動退出,再見', MB_OK);
          DestroyMenu(pm1);
          Shell_NotifyIcon(NIM_DELETE,@nid);
          ExitProcess(HMainWnd);
        end;
        end;
      End;
    WM_KEYDOWN: Begin
      GetCursorPos(pt);
      TrackPopupMenu(pm1, (TPM_BottomAlign or TPM_RightAlign or TPM_LEFTALIGN or TPM_RIGHTBUTTON), pt.x, pt.y, 0, HMainWnd, Nil);
      End;
    WM_Destroy: Begin
                DeStroyMenu(pm1);
                Shell_NotifyIcon(NIM_DELETE,@nid);
                PostQuitMessage(0);
                end
    else Result := DefWindowProc(AWnd, message, wp, lp);
  end;
end;

Function GdiProc1(AWnd:HWND; mes:UINT; wp:WPARAM; lp:LPARAM):LRESULT;stdcall;
begin
  Result := 0;
  case mes of
    WM_NCLBUTTONDOWN: begin
      GetCursorPos(pt);
      tmpWnd1 := GetSystemMenu(AWnd, true);
      TrackPopupMenu(pm1, (TPM_BottomAlign or TPM_RightAlign or TPM_LEFTALIGN or TPM_RIGHTBUTTON), pt.x, pt.y, 0, HMainWnd, Nil)// then GetWindowText(tmpWnd1, tmpChar, 256);
      end;
    WM_NCRBUTTONDOWN: begin
      GetCursorPos(pt);
      tmpWnd1 := GetSystemMenu(AWnd, true);
      TrackPopupMenu(pm2, (TPM_BottomAlign or TPM_RightAlign or TPM_LEFTALIGN or TPM_RIGHTBUTTON), pt.x, pt.y, 0, HMainWnd, Nil)// then GetWindowText(tmpWnd1, tmpChar, 256);
      end;
    WM_Destroy: Begin
                PostQuitMessage(0);
                halt;
                end
    else Result := DefWindowProc(AWnd, mes, wp, lp);
  end;
end;

Begin
nid.szTip := '迷你工具箱 V1.0 EMAIL: [email protected]';
lpText1 := '“安達”IT 服務中心' + #13#10
            + '迷你工具箱 V1.0 by 丁師傅' + #13#10
            + '版權所有 (C) 2009';
pm1 := CreatePopupMenu;
AppendMenu(pm1, MF_STRING, ID_Open, '打開(&Open)');
AppendMenu(pm1, mf_Separator, 0, Nil);
AppendMenu(pm1, 0, ID_Close, '退出(&Exit)');
pm2 := CreatePopupMenu;
AppendMenu(pm2, MF_STRING, ID_new1, '無線上網(&WI3G)');
ficon1 := ExtractIcon(0, PChar('ficon1.ico'), 0);
with wc do begin
    style := CS_VREDRAW or CS_HREDRAW;
    lpfnWndProc := @WndProc;
    cbClsExtra := 0;
    cbWndExtra := 0;
    nid.cbsize := sizeof(nid);
    hCursor := LoadCursor(0, IDC_ARROW);//  ;
    hbrBackground := GetSysColorBrush( windows.COLOR_INFOBK );//HBRUSH(GetStockObject(windows.GRAY_BRUSH));
    hInstance := HInstance;
    nid.uid := 1;
    nid.uflags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    nid.uCallbackMessage := MI_ICONEVENT;
    lpszMenuName := nil;
    lpszClassName := szAppName;
    hIcon := ficon1;
    end;
windows.RegisterClass(wc);
HMainWnd := CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT), HWND_DESKTOP, 0, HInstance, nil);
nid.hicon := ficon1;
nid.wnd := HMainWnd;
ico(lptext1);
image3 := CreateWindow('#32770', '迷你工具箱 V1.0 can not close', WS_VISIBLE or WS_TILED, 88, 28, 590, 398, 0, 0, 0, nil);
image1 := CreateWindow('Static' ,'image1', WS_VISIBLE or SS_BITMAP or WS_SIZEBOX or WS_CHILDWINDOW, 500, 2, 400, 300, image3, 0, 0, nil);
Label0 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT, 0, 0, 129, 160, image3, pm1, HInstance, nil);
Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT, 28, 38, 88, 28, image3, pm1, HInstance, nil);
                                                                    //left top width height
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or WS_BORDER, 128, 30, 288, 28, image3, pm1, HInstance, nil);
Label2 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT, 28, 66, 88, 28, image3, pm1, HInstance, nil);
Edit2 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', Pchar(DatetimetoStr(now)), WS_CHILD or WS_VISIBLE or WS_BORDER, 128, 58, 288, 28, image3, pm1, HInstance, nil);
Label3 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT, 28, 94, 88, 28, image3, pm1, HInstance, nil);
Edit3 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', Pchar(timetoStr(time)), WS_CHILD or WS_VISIBLE or WS_BORDER, 128, 88, 288, 28, image3, pm1, HInstance, nil);
Label4 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT, 28, 122, 88, 28, image3, pm1, HInstance, nil);
Button1 := CreateWindow('Button', '備份', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT, 421, 2, 128, 28, HMainWnd, pm1, hInstance, nil);
Button2 := CreateWindow('Button', '關閉', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT, 420, 32, 128, 28, HMainWnd, pm1, hInstance, nil);
Button3 := CreateWindow('Button', 'click', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT, 420, 80, 128, 28, HMainWnd, pm1, hInstance, nil);
RichWnd := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', 'RichEdit1', WS_VISIBLE or WS_CHILD or WS_VSCROLL or ES_MULTILINE or ES_NOHIDESEL or ES_WANTRETURN or WS_TABSTOP, 128, 118, 288, 180, image3, pm1, HInstance, nil);
hwndtooltip2 := CreateWindowEx(WS_EX_CLIENTEDGE, szAppName, '懸浮窗', WS_VISIBLE or WS_TILEDWINDOW, 680, 58, 88, 88, image3, 0, 0, nil);
hwndtooltip3 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Static', '子窗口3', WS_VISIBLE or SS_BITMAP or WS_SIZEBOX or WS_CHILDWINDOW, 2, 2, 288, 128, hwndtooltip2, 0, 0, nil);
Postmessage(image1, WM_SYSCOMMAND, SC_MAXIMIZE, 0);//最大化
hwndtooltip5 := CreateWindowEx(WS_EX_CLIENTEDGE, 'ToolbarWindow32', 'win任務欄', WS_VISIBLE or WS_CHILDWINDOW, Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), 800,Integer(CW_USEDEFAULT), image3, 0, 0, nil);
Imsctls_statusbar32 := CreateWindowEx(WS_EX_CLIENTEDGE, 'msctls_statusbar32', '狀態條1', WS_VISIBLE or WS_CHILD, 2, Integer(CW_USEDEFAULT), 788, 68, image3, 0, 0, nil);
hwndtooltip6 := CreateWindowEx(WS_EX_APPWINDOW, 'msctls_statusbar32', '狀態欄', WS_VISIBLE or WS_CHILD, Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT), DeskWnd, 0, 0, nil);
//用自定義的窗口過程替換編輯框的窗口過程,並保存老的窗口過程
SetWindowLong(image3, GWL_WNDPROC ,LongInt(MakeProcInstance(@GdiProc1, 0)));
H1 := LoadImage(0, 'ed.bmp', IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE or LR_CREATEDIBSECTION);
SendMessage(image1, STM_SETIMAGE, IMAGE_BITMAP, LParam(H1));
SendMessage(hwndtooltip3, STM_SETIMAGE, IMAGE_BITMAP, LParam(H1));
SendMessage(RichWnd, WM_SETTEXT, 0, lParam(lpText1));
SetWindowText(Label1, '文件路徑:');
SetWindowText(Label2, '目標路徑:');
SetWindowText(Label3, '開始時間:');
SetWindowText(Edit1, 'C:/TDDOWNLOAD/*.*');
SetWindowText(Edit2, '"D:/delphi app"/bak');
InvalidateRect(image1, PRECT(0), true);

while GetMessage(AMsg, 0, 0, 0) do begin
  TranslateMessage(AMsg);
  DispatchMessage(AMsg);
end;

end.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章