|
 |
全ドライブの情報取得
|
|
|
 |
全ドライブのタイプを取得し、リストボックスに結果を格納するプログラムのソースです。
Delphi3 で作成しました。エラーを無視すれば、Delphi2 でも利用できると思います。
HTML に書き換えるのが、面倒だったのでファイルで提供します。
コメントはありませんが、大体分かると思います。
もし分からないところがあれば、メール下さい。
ソースはここ (4.80kb)からダウンロードして下さい。
|
|
Tips Index |
|
 |
ショートカットの作成,Windows 再起動時にファイルを削除
|
|
|
 |
「ショートカットの作成」と「 Windows 再起動時にファイルを削除」を簡単に行うための関数を DLL にしました。
セットアッププログラムを、ご自分で作成するのに使えると思います。
また、配布ファイルには、Delphi での使い方を含めた簡単なサンプルプログラムを用意しています。
これで、DLL の動的リンクの方法も分かると思います。
DLL はここ (118kb)からダウンロードして下さい。
説明はここです。
サンプルプログラムの画面イメージはここ (4.80kb)です。
|
|
Tips Index |
|
 |
タイトルバーの右クリックで Popup メニューの表示方法
|
|
|
 |
タイトルバーを右クリックしたときに、ポップアップメニューを表示したいときには、
以下のようにしてみて下さい。
- ...
-
- uses ..., ShellAPI;
-
- ...
-
- private
- procedure WMNCRButtonDown(var Msg: TWMNCHitMessage); message WM_NCRButtonDown;
-
- ...
-
- procedure TForm1.WMNCRButtonDown(var Msg: TWMNCHitMessage);
- begin
- PopupMenu1.Popup(Msg.XCursor, Msg.YCursor)
- end;
また、左クリックのときには R を L にするだけです。
|
|
Tips Index |
|
 |
ShowMessage よりサイズの小さくなる ShowMessage_ 関数の作成方法
|
|
|
 |
ShowMessage ですが、以下の ShowMessage_ 関数を使うと、実行ファイルのサイズが小さくなりました。
- ...
-
- uses ..., ShellAPI;
-
- ...
-
- private
- procedure ShowMessage_(mes: string);
-
- ...
-
- procedure TForm1.ShowMessage_(mes: string);
- begin
- MessageBox(Handle, PChar(mes), 'タイトル', MB_OK)
- end;
|
|
Tips Index |
|
 |
タスクトレイでの Popup メニューの利用方法
|
|
|
 |
タスクトレイでクリックしたときに表示されるメニューですが、
- ...
-
- private
- procedure FormNotifyMessage(var Msg: TMessage); message WM_NotifyMessage;
-
- ...
-
- procedure TForm1.FormNotifyMessage(var Msg: TMessage);
- var
- Point: TPoint;
- begin
- Msg.Result := 0;
- GetCursorPos(Point);
- case Msg.lParam of
- WM_RBUTTONDOWN: PopupMenu1.Popup(Point.X, Point.Y);
- end
- end;
以上のようにポップアップメニューを使います。
タスクトレイについては、「タスクトレイを利用する方法」を参考にして下さい。
|
|
Tips Index |
|
 |
他のソフトからの D'nD の方法(改良版)
|
|
|
 |
「他のソフトからの D'nD の方法」についてですが、
- ...
-
- private
- procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
-
- ...
-
- Application.OnMessage := AppMessage;
-
- ...
-
- procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
- begin
- with Msg do
- if (hwnd = Application.Handle) and (message = WM_DROPFILES) then begin
- Perform(WM_DROPFILES, wParam, LParam);
- Application.Restore;
- Handled := True;
- end;
- end;
以上の部分が必要ありません。
この部分があると、このソフトは全ての Windows メッセージを取得します。
その為、パフォーマンスがおちてしまう?のです。
違っていたらメール下さい。
|
|
|
 |
Delphi でプログラムを何個か作ってみて思ったんですが、あまり Delphi の関数を使わず、
Windows API を使った方がいいのかもしれませんね。
そうすることにより、他の言語を使うようになったとき、比較的簡単に対応できるのかも知れません。
|
|
Tips Index |
|
 |
タスクトレイの利用方法,タスクバーに表示しない方法
|
|
|
 |
タスクトレイを利用する方法は
- ...
-
- const
- WM_NotifyMessage = WM_USER + 100;
-
- uses ..., ShellAPI;
-
- ...
-
- type
- ...
- private
- procedure NotifyMessage(var Msg: TMessage); message WM_NotifyMessage;
-
- ...
-
- var
- NotifyIcon: PNotifyIconDataA;
-
- ...
-
- {タスクトレイにアイコン追加}
- New(NotifyIcon);
- NotifyIcon.cbSize := SizeOf(TNotifyIconDataA);
- NotifyIcon.Wnd := Handle;
- NotifyIcon.uID := 1;
- NotifyIcon.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
- NotifyIcon.uCallbackMessage := WM_NotifyMessage;
- NotifyIcon.hIcon := Application.Icon.Handle;
- NotifyIcon.szTip := 'タスクトレイのアイコンにマウスを合わせると表示される文字列';
- Shell_NotifyIcon(NIM_ADD, NotifyIcon);
-
- {タスクトレイからアイコン削除}
- NotifyIcon.cbSize := SizeOf(TNotifyIconDataA);
- NotifyIcon.Wnd := Handle;
- NotifyIcon.uID := 1;
- Shell_NotifyIcon(NIM_DELETE, NotifyIcon);
- Dispose(NotifyIcon);
-
- procedure TForm1.NotifyMessage(var Msg: TMessage);
- begin
- case Msg.lParam of
- WM_RBUTTONDOWN: Close;
- end;
- end;
とします。あまり自信がありません。
|
|
|
 |
タスクバーに表示しない方法は
- ...
-
- uses ..., ShellAPI;
-
- ...
-
- ShowWindow(Application.Handle, SW_HIDE);
とします。
|
|
Tips Index |
|
 |
他のソフトからの D'nD の方法,このとき押されているキー取得方法
|
|
|
 |
D'nD の方法は、以下の通りです。
- ...
-
- uses ..., ShellAPI;
-
- type
- ...
- private
- procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
- procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
-
- ...
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DragAcceptFiles(Handle, True);
- DragAcceptFiles(Application.Handle, True);
- Application.OnMessage := AppMessage;
- end;
-
- procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
- begin
- with Msg do
- if (hwnd = Application.Handle) and (message = WM_DROPFILES) then begin
- Perform(WM_DROPFILES, wParam, LParam);
- Application.Restore;
- Handled := True;
- end;
- end;
-
- procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
- var
- FileName: array [0..255] of char;
- i, num: word;
- begin
- num := DragQueryFile(Msg.Drop, word(-1), nil, 0);
- for i:=0 to num-1 do begin
- DragQueryFile(Msg.Drop, i, FileName, SizeOf(FileName));
- Caption := StrPas(FileName)
- end;
- DragFinish(Msg.Drop)
- end;
|
|
|
 |
WMDropFiles 関数の最初に
- if (GetKeyState(VK_CONTROL) and $80) = $80 then
- ctrl_check := true;
とすると Ctrl キーが押されている場合 ctrl_check が true となります。
今までは、Windows メッセージで、キーチェックをしようとしていました。分かってみれば、簡単ですね。
|
|
Tips Index |
|
 |
Unlha32.dll を Delphi で使う方法(動的リンク)
|
|
|
 |
「Unlha32.dll を Delphi で使う方法(静的リンク)」ですが、
この方法は、プログラムを実行したときに Unlha32.dll がなければ、
プログラムが終了してしまう、静的リンクです。
これでは不便ですので、動的リンクの方法を簡単に書いておきます。
- ...
-
- var
- Form1: TForm1;
- UnlhaChk: boolean;
- UnlhaHandle: THandle;
- Unlha: function(const _hwnd: HWND; _szCmdLine: pchar; _szOutput: pchar;
- const _wSize: longint): integer; stdcall;
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- h: THandle;
- p: TFarProc;
- begin
- h := LoadLibrary('UNLHA32.DLL');
- if h < HINSTANCE_ERROR then UnlhaChk := false
- else begin
- UnlhaChk := true;
- p := GetProcAddress(h, 'Unlha');
- if p <> nil then @Unlha := p;
- UnlhaHandle := h;
- end;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if UnlhaChk = true then FreeLibrary(UnlhaHandle);
- end;
以上のようにすると Unlha32.dll がある場合は、UnlhaChk = true となります。たぶん?
|
|
Tips Index |
|
 |
Unlha32.dll を Delphi で使う方法(静的リンク)
|
|
|
 |
Unlha32.dll を Delphi で使うには、
- unit UnlhaLib;
-
- interface
-
- uses Windows;
-
- function Unlha(const _hwnd: HWND; _szCmdLine: pchar; _szOutput: pchar; const _wSize: longint): integer; stdcall;
- function UnlhaCheckArchive(_szFileName: PChar; const _iMode: integer): boolean; stdcall
-
- implementation
-
- function Unlha; external 'unlha32.dll' name 'Unlha';
- function UnlhaCheckArchive; external 'unlha32.dll' name 'UnlhaCheckArchive';
-
- end.
と記述したファイルを使うといいみたい。違ったらごめんなさい。
他の関数も増やしたらメールで送ってくれるとうれしいです。
|
|
Tips Index |
|
|