borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (retrieve a file creation date)Next Topic (how to read and show the content in a rich textbox of the doc file by vb) New Topic New Poll Post Reply
AndreaVB Forum : API : Saving picture box from extracted icon
Poster Message
TechHead
Level: Guest


icon Saving picture box from extracted icon

Hello techies out there!!! and thank you in advanced. I've been trying to save the icons from a dll file. I can extract the icon to a picture box but when I I save the it from the picture box as an icon, it seems that it is only saving what picture box itself(with the gray background) but not the icon image. Am I doing something wrong? I have included the code below:


      Option Explicit
      Private Const MAX_PATH = 260

      Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
      "GetSystemDirectoryA" (ByVal lpBuffer As String, _
                             ByVal nSize As Long) As Long

      Private Declare Function ExtractIcon Lib "shell32.dll" Alias _
      "ExtractIconA" (ByVal hInst As Long, _
                      ByVal lpszExeFileName As String, _
                      ByVal nIconIndex As Long) As Long

      Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, _
      ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long

      Dim path as string
      Dim nIcon As Long

      Private Sub Command1_Click()
          Dim hIcon As Long

          hIcon = ExtractIcon(App.hInstance, path, nIcon)
          Set Picture1.Picture = LoadPicture("") ' Clear the picture box
          Picture1.AutoRedraw = True
          Call DrawIcon(Picture1.hdc, 0, 0, hIcon)
          Picture1.AutoRedraw = False
          Picture1.Refresh

          SavePicture Picture1.picture, "c:\" & nIcon & ".ico" 'save the icon from the picture box and here my problem starts.

          nIcon = nIcon + 1 'proceed to the next icon inside the dll

      End Sub

      Private Sub Form_Load()
      ' Store the full path to the file containing the icon(s).
          path = Space(MAX_PATH)
          Call GetSystemDirectory(path, MAX_PATH)
          path = Trim(path) ' Trim trailing blanks & Null terminator
          path = Left(path, Len(path) - 1) & "\Shell32.dll"
          nIcon = 0
      End Sub

26-02-2004 at 04:21 PM
| Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: Saving picture box from extracted icon

try changing it this way:

SavePicture Picture1.Image, "c:\" & nIcon & ".ico"


use Picture1.Image instead of  .Picture

you can also try to set the AutoRedraw to true for the picturebox

____________________________
AndreaVB

26-02-2004 at 04:54 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : API : Saving picture box from extracted icon
Previous Topic (retrieve a file creation date)Next Topic (how to read and show the content in a rich textbox of the doc file by vb) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder