Results 1 to 13 of 13

Thread: [2005] Photo Management

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Question [2005] Photo Management

    Hey everyone. I have decided I want to have a crack at making something that will manage photos. The first thing I want the app to do is
    to pick up when someone plugs their camera in to the usb port and the I want
    the program(which will be running in the task bar) to ask the user whethe he would like the photos to be uploaded to the program. and then for it to actually put the photos in the program

    Any ideas on how I could do that

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Photo Management

    Your first step is to write the code that detects the device being plugged in. You will need to use WMI for this. Do a search on RegisterDeviceNotification.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Photo Management

    Ok, found a sample:

    Code:
    here is a WinForm application to detect Human Input Devices (HID),
    including all kinds of mouse / keyboard / keypad / joystick / etc. If you
    want to detect all USB devices, uses GUID_DEVINTERFACE_USB_DEVICE =
    "A5DCBF10-6530-11D2-901F-00C04FB951ED" instead.
    
    ---- begin ---
    using System.Runtime.InteropServices;
    
    namespace WindowsApplication1
    {
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    
    public Form1()
    {
    InitializeComponent();
    RegisterHidNotification();
    }
    
    protected override void WndProc(ref Message m)
    {
    switch(m.Msg)
    {
    case Win32.WM_DEVICECHANGE: OnDeviceChange(ref m); break;
    }
    base.WndProc (ref m);
    }
    
    void OnDeviceChange(ref Message msg)
    {
    int wParam = (int)msg.WParam;
    if(wParam == Win32.DBT_DEVICEARRIVAL) label1.Text = "Arrival";
    else if(wParam == Win32.DBT_DEVICEREMOVECOMPLETE) label1.Text =
    "Remove";
    }
    
    void RegisterHidNotification()
    {
    Win32.DEV_BROADCAST_DEVICEINTERFACE dbi = new
    Win32.DEV_BROADCAST_DEVICEINTERFACE();
    int size = Marshal.SizeOf(dbi);
    dbi.dbcc_size = size;
    dbi.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE;
    dbi.dbcc_reserved = 0;
    dbi.dbcc_classguid = Win32.GUID_DEVINTERFACE_HID;
    dbi.dbcc_name = 0;
    IntPtr buffer = Marshal.AllocHGlobal(size);
    Marshal.StructureToPtr(dbi, buffer, true);
    IntPtr r = Win32.RegisterDeviceNotification(Handle, buffer,
    Win32.DEVICE_NOTIFY_WINDOW_HANDLE);
    if(r == IntPtr.Zero)
    label1.Text = Win32.GetLastError().ToString();
    }
    }
    
    class Win32
    {
    public const int
    WM_DEVICECHANGE = 0x0219;
    public const int
    DBT_DEVICEARRIVAL = 0x8000,
    DBT_DEVICEREMOVECOMPLETE = 0x8004;
    public const int
    DEVICE_NOTIFY_WINDOW_HANDLE = 0,
    DEVICE_NOTIFY_SERVICE_HANDLE = 1;
    public const int
    DBT_DEVTYP_DEVICEINTERFACE = 5;
    public static Guid
    GUID_DEVINTERFACE_HID = new
    Guid("4D1E55B2-F16F-11CF-88CB-001111000030");
    
    [StructLayout(LayoutKind.Sequential)]
    public class DEV_BROADCAST_DEVICEINTERFACE
    {
    public int dbcc_size;
    public int dbcc_devicetype;
    public int dbcc_reserved;
    public Guid dbcc_classguid;
    public short dbcc_name;
    }
    
    [DllImport("user32.dll", SetLastError=true)]
    public static extern IntPtr RegisterDeviceNotification(
    IntPtr hRecipient,
    IntPtr NotificationFilter,
    Int32 Flags);
    
    [DllImport("kernel32.dll")]
    public static extern int GetLastError();
    }
    }
    You will need to translate to VB.NET.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: [2005] Photo Management

    I will do that. C# isnt very different to vb.net is it?

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Photo Management

    Quote Originally Posted by tarik666
    I will do that. C# isnt very different to vb.net is it?
    Nope, not very different at all.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: [2005] Photo Management

    god this is hard. Can anyone help.

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Photo Management

    What do you find hard? Perhaps we can guide you through it.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: [2005] Photo Management

    Well i dont understand that code.

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Photo Management

    Try a converter. It'll be erroneous but most of it will be converted for you and you can convert the 'mistakes' to proper VB.NET code.

  10. #10
    Lively Member
    Join Date
    Jan 2006
    Posts
    111

    Re: [2005] Photo Management

    Used InstantVB to convert the code (Not sure how accurate / if it will work at all)

    Code:
    Imports Microsoft.VisualBasic
    Imports System.Runtime.InteropServices
    
    Namespace WindowsApplication1
    Public Class Form1
    	Inherits System.Windows.Forms.Form
    Private label1 As System.Windows.Forms.Label
    
    Public Sub New()
    InitializeComponent()
    RegisterHidNotification()
    End Sub
    
    Protected Overrides Sub WndProc(ByRef m As Message)
    Select Case m.Msg
    Case Win32.WM_DEVICECHANGE
    	OnDeviceChange(m)
    End Select
    MyBase.WndProc (m)
    End Sub
    
    Private Sub OnDeviceChange(ByRef msg As Message)
    Dim wParam As Integer = CInt(Fix(msg.WParam))
    If wParam = Win32.DBT_DEVICEARRIVAL Then
    	label1.Text = "Arrival"
    ElseIf wParam = Win32.DBT_DEVICEREMOVECOMPLETE Then
    	label1.Text = "Remove"
    End If
    End Sub
    
    Private Sub RegisterHidNotification()
    Dim dbi As New Win32.DEV_BROADCAST_DEVICEINTERFACE()
    Dim size As Integer = Marshal.SizeOf(dbi)
    dbi.dbcc_size = size
    dbi.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE
    dbi.dbcc_reserved = 0
    dbi.dbcc_classguid = Win32.GUID_DEVINTERFACE_HID
    dbi.dbcc_name = 0
    Dim buffer As IntPtr = Marshal.AllocHGlobal(size)
    Marshal.StructureToPtr(dbi, buffer, True)
    Dim r As IntPtr = Win32.RegisterDeviceNotification(Handle, buffer, Win32.DEVICE_NOTIFY_WINDOW_HANDLE)
    If r = IntPtr.Zero Then
    label1.Text = Win32.GetLastError().ToString()
    End If
    End Sub
    End Class
    
    Friend Class Win32
    Public Const WM_DEVICECHANGE As Integer = &H0219
    Public Const DBT_DEVICEARRIVAL As Integer = &H8000, DBT_DEVICEREMOVECOMPLETE As Integer = &H8004
    Public Const DEVICE_NOTIFY_WINDOW_HANDLE As Integer = 0, DEVICE_NOTIFY_SERVICE_HANDLE As Integer = 1
    Public Const DBT_DEVTYP_DEVICEINTERFACE As Integer = 5
    Public Shared GUID_DEVINTERFACE_HID As New Guid("4D1E55B2-F16F-11CF-88CB-001111000030")
    
    <StructLayout(LayoutKind.Sequential)> _
    Public Class DEV_BROADCAST_DEVICEINTERFACE
    Public dbcc_size As Integer
    Public dbcc_devicetype As Integer
    Public dbcc_reserved As Integer
    Public dbcc_classguid As Guid
    Public dbcc_name As Short
    End Class
    
    <DllImport("user32.dll", SetLastError:=True)> _
    Public Shared Function RegisterDeviceNotification(ByVal hRecipient As IntPtr, ByVal NotificationFilter As IntPtr, ByVal Flags As Int32) As IntPtr
    End Function
    
    <DllImport("kernel32.dll")> _
    Public Shared Function GetLastError() As Integer
    End Function
    End Class
    End Namespace

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: [2005] Photo Management

    alright. The code isnt running errors. Some I am going to test it out. Just as a thought. Does this detect cameras only or anything that is plugged into the usb port

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Photo Management

    Yes, it should detect if any device is plugged in to the USB port. "SHOULD" being the keyword here. I haven't actually used it myself

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: [2005] Photo Management

    Well I wonder if vb.net has a way of checking what sort of device it is. I want it to only alert me if its a camera

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width