Results 1 to 34 of 34

Thread: [RESOLVED] Using Icon as Image in Image control.

  1. #1

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Resolved [RESOLVED] Using Icon as Image in Image control.

    Hello.
    I want to display a icon in an image control. For this I'm writing code as:

    Code:
    ImgPreview.Picture = LoadPicture(CmDialog.FileName, vbLPCustom, , 28, 28)
    But it says, the picture is invalid.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  2. #2
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Using Icon as Image in Image control.

    Have you tried supplying the color depth?

    Also, is the icon 32 bit?

  3. #3

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    What if icon is not 32-bit??
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  4. #4

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    I supplied color dept as VbLPDefualt. It still says, Invalid Picture.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Using Icon as Image in Image control.

    Can you upload the icon?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Actually, the icon is not fixed. The user selects icon at the runtime and I want to show its preview under image control. The icons source may be (*.ico, *.exe and *.dll).
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  7. #7

  8. #8

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    So, what can I do to make the preview of those icon files under an image control??
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  9. #9

  10. #10

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Research the PE structure.
    I didn't get it. What does PE means??
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  11. #11
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: Using Icon as Image in Image control.

    Hello, look this user control, can help.

    http://www.leandroascierto.com.ar/ca...lphaIcon32.php
    leandroascierto.com Visual Basic 6 projects

  12. #12
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Using Icon as Image in Image control.

    Quote Originally Posted by rajbdilip View Post
    I didn't get it. What does PE means??
    Portable executable.

    It's the file format for a Windows executable.

    It includes the resource fork(like if you add resource files to your EXE), which includes an ICON fork.

    Typically they're stored unobfuscated.

    More here: http://www.wotsit.org/list.asp?al=E

  13. #13

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    @LeandroA:
    Well, I didn't understand the language used in the site. I downloaded it. But what must be me doing with it? I didn't get any clues. Also, I can't upload icons.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  14. #14

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    @FireXtol:
    I guess, that doesn't help me.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  15. #15
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Using Icon as Image in Image control.

    Time to use your friends (yahoo, google, ask, answers bing) and search for vb6 extracticonex. When you retrieve your results, make sure you check out both thescarms and vbaccelerator 's example programs...



    Good Luck
    Option Explicit should not be an Option!

  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Using Icon as Image in Image control.

    In my signature below (Icon Organizer), you can find code to extract icons from an exe, dll, ocx.

    Any 32bpp icon will never load in VB via LoadPicture; you cannot assign a 32bpp icon to any .Picture or .Icon property -- they are not supported.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Any 32bpp icon will never load in VB via LoadPicture; you cannot assign a 32bpp icon to any .Picture or .Icon property -- they are not supported.
    Then, can it be converted to other supported formats at runtime??
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  18. #18

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Ok. You've managed to load those pictures to your form. Can you write a function to convert the icon to supported image??
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  19. #19
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Using Icon as Image in Image control.

    Easy to do, but quality will suffer. One can convert 32bpp to 24bpp which is supported. But 32bpp are generally alphablended giving you nice blended shadows for example. Converting to 24bpp means those shadows will no longer be blended, but solid, and will result in poor quality. The real answer is to not convert those icons for .Picture/.Icon properties but to draw them directly on the form/picturebox using the DrawIconEx API and you will get the best quality; but this does require some more code. The Image Control is a convenient tool, but not for modern graphics. Also, 32bpp icons are supported in XP and above only.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  20. #20

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Ok, I'm now gonna use picturebox instead of ImageBOx. Can you show me an API declaration and the code to draw icon to picturebox?
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  21. #21
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Using Icon as Image in Image control.

    Look at the Icon Organizer link in my signature and sample code is in post #1 in that link: Bonus Code #2.

    Another answer is to not use 32bpp icons or remove them from the icon file/resource. But if your users can pick any icon, then that may not be so easy as the icon may only consist of 32bpp formats.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  22. #22

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    I have no idea what you are doing there. Can you simplify it?
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  23. #23
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Using Icon as Image in Image control.

    Ok, in order to us the DrawIconEx API, you will need an hIcon handle. There are a few ways to get that handle
    1) Read the bytes into an array using VB & Binary file mode. Use the sample code I mentioned and create an Icon from the first icon in the file. (example given in that link)
    2) Use other APIs like LoadImage (example given in that link)
    3) Manually parse the icon file which I don't think you want to do

    The only thing not given in that link is an example of DrawIconEx. It is so easy to use.
    If you create an icon, you must remember to destroy it at some point else memory leaks can occur.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    I guess I'm getting it now. I will try those codes with my projects. If any problem occurs I will be back right here.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  25. #25

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Alright. The function DrawIconEx works well. I'm using transparent frame and the area where icon is to be drawn is covered by the same frame. But after drawing, the icon doesn't appear.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  26. #26
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Using Icon as Image in Image control.

    Quote Originally Posted by rajbdilip View Post
    Alright. The function DrawIconEx works well. I'm using transparent frame and the area where icon is to be drawn is covered by the same frame. But after drawing, the icon doesn't appear.
    What code are you using for making the frame transparent ? Try calling that sub/function, which will make the frame transparent, after drawing the icon.
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  27. #27

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Actually, I'm not making the frame transparent. I'd downloaded an transparent frame control (.ocx) and used in my project.
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  28. #28
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Using Icon as Image in Image control.

    Try refreshing the frame control after drawing.
    Code:
    Frame1.Refresh
    Or, try hiding and showing that frame control, after drawing.

    Example:
    Code:
    Frame1.Visible=False
    DrawICON
    Frame1.Visible=True
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  29. #29

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    This control doesn't support REFRESH method. And about the next idea, it failed. What do I do next??
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  30. #30
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Using Icon as Image in Image control.

    Can you send me a sample to work out ? Try to include the transparent OCX also. I will experiment it...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  31. #31

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Here is my project.
    Attached Files Attached Files
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  32. #32
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Using Icon as Image in Image control.

    I have tried it, but it looks like the Transparent Frame control use to paint the background on app loading only. I have tried assigning the transparency property at runtime. But that too doesn't show any effect.
    May be you should display the picture somewhere else.

    If you want to display the icon in a picturebox, you can try this in DrawIconEx line:
    Code:
    DrawIconEx Picture1.hdc, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  33. #33

    Thread Starter
    Hyperactive Member rajbdilip's Avatar
    Join Date
    Feb 2010
    Location
    Kathmandu, Nepal
    Posts
    263

    Re: Using Icon as Image in Image control.

    Alright. Now I've placed picturebox set its border style to none. It works as I had wanted.

    Thanks a lot!!!
    A Young Self-Taught Programmer || VB6 | VB.NET (Visual Studio 2010) | Java |CSS | JavaScript | PHP | MySQL

  34. #34
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Using Icon as Image in Image control.

    Quote Originally Posted by rajbdilip View Post
    Alright. Now I've placed picturebox set its border style to none. It works as I had wanted.

    Thanks a lot!!!
    You're welcome...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

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