change the default form's icon on a DLL

Posted on 2003-11-17
Last Modified: 2010-05-01
Hi lads, this is driving me nuts.
I'm trying to change the default windows icon that comes with a DLL's form. The thing is as soon as I press Alt-Tab to change to a different application, I can see the windows flag as an icon for my form. I found out that when I use an Active EXE project (with an icon selected), and take it to call a DLL's form (with an icon as well), my DLL's form shows its icon. My problem is that I'm calling this DLL from a word document, so my DLL seems to not recognize its 'parent', showing the ugly  windows default icon instead. Any idea on how to change and use one of my choice at design/run-time?

Thanks guys
Question by:AntoniL
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4

Accepted Solution

wsteegmans earned 250 total points
ID: 9767740
Maybe you can use some API-stuff to do your thing ...

I found that you can get the current icon with this MESSAGE: WM_GETICON

Maybe, this page helps:

Author Comment

ID: 9767902
Hi mate,
the thing about that example (tried a few days ago!!, cheers anyway) is that the icon gets disfigured with ICON_BIG and with ICON_SMALL the form remains as at the beginning ... any idea on how to fix that or any other way?

thanks wsteegmans

LVL 75

Expert Comment

by:Anthony Perkins
ID: 9768416
This is how it is done:
HOWTO: Associate a Custom Icon with a Formless Visual Basic Application;en-us;291569

Also, please maintain your old open questions:
1 09/07/2003 250 Refresh browser's frame content from VB  Open VB Controls
2 07/03/2003 250 call a DLL or EXE passing parameters  Open JavaScript
3 08/07/2003 500 Writing a PDF file with VB  Open VB Controls

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.


Author Comment

ID: 9770062
Hi acperkins,
this example is for Formless executables, so doesn't apply to my case. I tried to do the same as in the link you mentioned and doesn't work. Thanks anyway

Anybody else guys?

LVL 75

Expert Comment

by:Anthony Perkins
ID: 9771484
>>this example is for Formless executables, so doesn't apply to my case. <<
A dll is a "Formless" executable, in the sense that it does not have (or should not have) a form.

>>I tried to do the same as in the link you mentioned and doesn't work.
I do not know why it did not "work" for you, but on the other hand you do not appear to have any interest in maintaining your open questions, so I will move on.

Good luck,

Author Comment

ID: 9773133
Thanks for your input acperkins,
sorry but the example of 'formless executables' did work when I tried for an EXE but did not for a DLL, and what I'm looking for is for a DLL. I did a few tries but didn't find any way to get it working for a DLL.
I indeed have interest in my open questions, if they remain open is because I still have some hope for an answer. I'm not going to close them just in case. EE sends an email after a few months asking to close them up, and it's then when I'm 'forced' to do it. Of course it's up to you to move on. Thanks for your replies, honestly.

See you around

LVL 75

Expert Comment

by:Anthony Perkins
ID: 9773581
>>if they remain open is because I still have some hope for an answer.<<
The chances that someone will address a question that is at best two months old and at worse four months old are exactly 0. To put it mildly you are delluding yourself. Questions are considered technically abandoned after 21 days.

>>EE sends an email after a few months asking to close them up <<
That is not the way it works here.  Volunteers like myself are assigned abandoned questions and we recommend the outcome: Award points, Delete without a Refund or Delete and refund.  So basically you are saying that your questions will fall in the following category:

Abandon your question and leave the mess for someone else to clean up

>> it's then when I'm 'forced' to do it.<<
You are never forced to do anything, it is your responsibility as a member of this Community to keep up to date with your questions.

Thank you for your help,

Author Comment

ID: 9777208
Hi acperkins,
I didn't know after just 3 weeks the questions become technically 'dead'. Thanks for letting me know. I just opened a thread on the CleanUp Area asking for deletion for my 3 abandoned questions.
Any chance to get an answer in this, still, open question? ;-), really need to get it.

Thanks for your help lads

LVL 75

Expert Comment

by:Anthony Perkins
ID: 9784347
Thanks for closing your old open questions.  Hopefully someone will offer some help.


Author Comment

ID: 9786441
OK lads, I think I found the solution. The key thing here is have a couple of Picture controls, with an icon as their image. The first, Picture1, has an icon with just one format, 32x32, and the second, Picture2, has the small format, 16x16, or if you like, with all the formats, it doesn't matter. With the firsts lines of code, we set up the large icon for the Alt-Tab, and in the end, we change the icon to a small format, for the Task-Bar. Remember, the important thing is the one-format icon, 32x32.
Here is the code:

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

 Const GWL_HWNDPARENT = (-8)

 Const WM_GETICON = &H7F
 Const WM_SETICON = &H80
 Const ICON_BIG = 1

Private Sub Form_Load()
    Dim hIcon As Long
    Dim nRet As Long
    Dim nMainhWnd As Long
    nRet = GetWindowLong(Me.hWnd, GWL_HWNDPARENT)
    nMainhWnd = nRet
    nRet = GetWindowLong(nRet, GWL_HWNDPARENT)
    Me.Icon = Picture1.Picture
    hIcon = SendMessage(Me.hWnd, WM_GETICON, ICON_BIG, ByVal 0)
    SendMessage nMainhWnd, WM_SETICON, ICON_BIG, ByVal hIcon
    Me.Icon = Picture2.Picture
End Sub

The points go to wsteegmans for putting me on the right track.
Thanks to you all guys, see you around


Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question