|
-
May 14th, 2002, 07:45 PM
#1
Thread Starter
Lively Member
[vb.net] Need assistance with Icons, Treeview and the API... [RESOLVED]
I wish to place a Icon from a associated file into a picture control or a treeview control.......
the Api is wack in .net....
Heres the deal...
I get the associated program and icon index from the registry. Now I wish to extract the Icon and place it into a simple picturebox Seems simple enough, I've been fooling with this for the past 2 days... any help or suggestions???
The main result will be wanting to place the associated file in a treeview with the associated icon, but for now just to have it appear in a picturebox will show progress.
Thankx for any help on this...
[CODE]:
'--------------------------------------------------------------
'Declares
Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As Integer) As Integer
Declare Function DrawIcon Lib "user32" Alias "DrawIcon" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal hIcon As Integer) As Integer
' Create a button named "Button1" and a picturebox named "Picture1" on a form and add this code to the Button1_Click event
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Code to Grab Associated Program and Icon Index
Dim Extension As String
Dim ExtReg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
Dim AppReg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
Extension = ".vbp"
ExtReg = ExtReg.OpenSubKey(Extension)
Dim xStr As String = ExtReg.GetValue("")
AppReg = AppReg.OpenSubKey(xStr & "\DefaultIcon")
Dim MyIcon() As String
MyIcon = Split(AppReg.GetValue(""), ",")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Code to Extract Icon and Place inside a Picture Box
'(this is the bad code, everything executes fine but not icon is displayed in control)
Dim xHandle As Integer
xHandle = ExtractIcon(0, MyIcon(0), Int(MyIcon(1)))
MsgBox(xHandle) ' See if we have what looks to be a proper handle
With Picture1
Dim xInst As Integer = System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly. GetModules()(0)).ToInt32
xInst = DrawIcon(xInst, 0, 0, xHandle)
.Refresh()
End With
Last edited by Evad; Oct 28th, 2003 at 12:38 PM.
-
May 14th, 2002, 08:36 PM
#2
Thread Starter
Lively Member
Thankx Anyway...
.... I figured it out....
Once I got the handle...
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Code to Extract Icon and Place inside a Picture Box
'(this is the bad code, everything executes fine but not icon is displayed in control)
Dim xHandle As Integer
xHandle = ExtractIcon(0, MyIcon(0), Int(MyIcon(1)))
I just used the system.drawing.icon class to switch it over....
Code:
Picture1.Image = System.Drawing.Icon.FromHandle(IntPtr.op_Explicit(xHandle)).ToBitmap
Thankx anyway....
-
May 14th, 2002, 08:46 PM
#3
Thread Starter
Lively Member
Now into another problem...
Now that I have the icon I notice that its not like the original icon...
It seems not to be displaying any of the transparencys, to the icon doesn't look good when displayed. It kinda looks like the icons we added to the menu bars in VB6 with the API.
any thoughs suggestions?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|