[Lazarus] Recognize a "disk"

cobines cobines at gmail.com
Wed Dec 16 18:46:52 CET 2009


2009/12/16 "ArĂ­ Ricardo Ody" <aro52 at gmx.com>:
> I have no idea how I can capture the mentioned message. Could you send an
> example, please?

I have attached a few functions, but it's not complete example. I
don't have access to windows right now.

Call SetMyWndProc() with a handle of your main form to hook into
message queue and add code to handle WM_DEVICECHANGE in MyWndProc().


--
cobines
-------------- next part --------------
var
  OldWProc: WNDPROC;

function MyWndProc(hWnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
  case uiMsg of
    WM_DEVICECHANGE:
      if (wParam = DBT_DEVICEARRIVAL) or (wParam = DBT_DEVICEREMOVECOMPLETE) then
        begin
	  // Device added or removed detected.
	  // Add handling code here.
	  
	  Exit(TRUE);
        end;
  end;
  Result := CallWindowProc(OldWProc, hWnd, uiMsg, wParam, lParam);
end;

procedure SetMyWndProc(Handle : THandle);
begin
  OldWProc := WNDPROC(SetWindowLong(Handle, GWL_WNDPROC, LONG_PTR(@MyWndProc)));
end;

// Somewhere in OnCreate of your main form.
procedure TMainForm.FormCreate(Sender: TObject);
begin
  SetMyWndProc(Handle);
end;


More information about the Lazarus mailing list