Icon.FromHandle(..) not working?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iwdu15

    #1

    Icon.FromHandle(..) not working?

    hi, im attempting to get an applications Icon by using the method
    Icon.FromHandle () and passing in a windows handle, yet nothing works ive
    tried two different things and neither work. Ive been googleing this to no
    avail....code:


    Protected Overrides Sub WndProc(ByRef m As Message)

    MyBase.WndProc( m)

    If m.Msg = WM_SYSCOMMAND Then

    Select Case m.WParam.ToInt3 2

    Case 1000

    Dim tray As New NotifyIcon(Me.c omponents)


    tray.Icon = Icon.FromHandle (m.HWnd)

    ''tried using Me.Handle to see if that would work but no
    'tray.Icon = Icon.FromHandle (Me.Handle)
    tray.Visible = True

    AddHandler tray.DoubleClic k, AddressOf
    NotifyIcon1_Dou bleClick

    SendMessage(m.H Wnd.ToInt32, 0, Nothing, Nothing)

    End Select

    End If

    End Sub


    i set a breakpoint and step through, the method returns something, but
    apparently not an Icon like the MSDN documentation says...any idea how i can
    get this working? thanks

    --
    -iwdu15
  • Herfried K. Wagner [MVP]

    #2
    Re: Icon.FromHandle (..) not working?

    "iwdu15" <jmmgoalsteraty ahoodotcomschri eb:
    hi, im attempting to get an applications Icon by using the method
    Icon.FromHandle () and passing in a windows handle
    You will have to pass in an icon handle ('HICON').

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • iwdu15

      #3
      Re: Icon.FromHandle (..) not working?

      so then if i get a windows handle, how can i get either a)its icon handle or
      b) its icon? thanks for your help
      --
      -iwdu15

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Icon.FromHandle (..) not working?

        "iwdu15" <jmmgoalsteraty ahoodotcomschri eb:
        so then if i get a windows handle, how can i get either a)its icon handle
        or
        b) its icon?
        PInvoke with 'SendMessage' + 'WM_GETICON' (see documentation).

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • iwdu15

          #5
          Re: Icon.FromHandle (..) not working?

          Great, thanks!
          --
          -iwdu15

          Comment

          • iwdu15

            #6
            Re: Icon.FromHandle (..) not working?

            i cant seem to figre this out....google hasnt helped either....heres what i
            have

            Protected Overrides Sub WndProc(ByRef m As Message)

            MyBase.WndProc( m)

            If m.Msg = WM_SYSCOMMAND Then

            Select Case m.WParam.ToInt3 2

            Case 1000

            SendMessage(m.H Wnd, WM_GETICON, Nothing, Nothing)

            Dim tray As New NotifyIcon

            Dim x As IntPtr = DefWindowProcA( m.HWnd, WM_GETICON,
            Nothing, Nothing)

            tray.Icon = Icon.FromHandle (x)
            tray.Visible = True

            AddHandler tray.DoubleClic k, AddressOf
            NotifyIcon1_Dou bleClick

            SendMessage(m.H Wnd, 0, Nothing, Nothing)

            End Select

            End If

            End Sub


            yet the DefWindowProcA doesnt return a windows handle....i couldnt find any
            documentation of how to get a specific message on MSDN or AllApi etc....thanks

            --
            -iwdu15

            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Icon.FromHandle (..) not working?

              "iwdu15" <jmmgoalsteraty ahoodotcomschri eb:
              >i cant seem to figre this out....google hasnt helped either....heres what i
              have
              'SendMessage''s return value is the icon handle you can pass to
              'Icon.FromHandl e'.

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              • iwdu15

                #8
                Re: Icon.FromHandle (..) not working?

                SendMessage() was returning 0, so i found a way around it. I iterated through
                each process comparing that handle to the handle i already have, if theyre
                the same i get the main module file name and extract the icon....thanks
                though Herfried!
                --
                -iwdu15

                Comment

                Working...