No form how to write simple, monitoring site is inserted into the Delphi program

The basic framework of my so
The message loop,
begin
while(GetMessage(msg,0,0,0))do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end.
How to join the message queue, judge the insert and pull out the USB flash drive? ?

Online post is such, is used in the form of label,
Delphi capture U disk insert or pull out
Delphi capture U disk insert or pull out
In the USB port is the hot plug, the system will release the WM_DEVICECHANGE message to all programs, so as to capture this message can be realized on the U disc surveillance.
1, New project;
2, Put a Label in the form1;
3, The definition of a private procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMDeviceChange (var Msg: TMessage);
var
myMsg : String;
begin
Case Msg.WParam of
32768:
begin
myMsg :='The inserted U disk';
Label1.Caption:=myMsg
end;
32772:
begin
myMsg :='U disc pull out';
Label1.Caption:=myMsg;
end;
end;
end;
end.



I want to talk about the two together, how to achieve it? ?
Please heroes give me Inspirations.

Started by Adonis at February 07, 2016 - 5:42 PM

Why no form, no form is not a console application.
Procedures with the form, you hide the form does not have, if no form, where what message and the message loop.
If you want to judge whether a U disk insert and remove order, can through the WM_DEVICECHANGE message in lParam, lParam is a pointer, the structure that contains the data you want, including the insertion or removal of equipment type, equipment drive etc.

Posted by Kate at February 12, 2016 - 6:16 PM

Write a sample, you download to see

Posted by Kate at February 26, 2016 - 6:36 PM

Example you can insert a U disk, all along the sequence in the listbox sequence, and then casually pulled out can know the current drawn is a U disk which drive letter.
As for whether the window display, don't you think is a hidden form, if you want to display the new form will be a global hotkey to display recovery form.

Posted by Kate at March 07, 2016 - 6:44 PM

Create a hidden window by WIN32API, ShowWindow updatewindow can be removed, then processes the messages in the window callback process

Posted by Steward at March 13, 2016 - 6:58 PM

If the person is the insertion of a mobile hard disk.

Posted by Alexandra at March 24, 2016 - 7:26 PM

Upload resources that can be deleted, the curious point to delete to delete, sure enough. . . ,
Again

Example of using VCL, you should API SDK mode, according to the 4 floor, processing of WM_DEVICECHANGE messages in the window callback function,
But also many additional statement structure and constant.

Posted by Kate at March 30, 2016 - 8:08 PM

The form directly Hide off on it.

Posted by York at January 03, 2017 - 4:31 PM

How to judge the insertion of the USB device is a mobile phone? ? ?

How to judge the insertion of the USB device is a mobile phone? ? ?

Thank you. . .

Posted by Anastasia at January 05, 2017 - 5:11 PM