change the default form's icon on a DLL

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AntoniLAuthor Commented:
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

Anthony PerkinsCommented:
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

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

AntoniLAuthor Commented:
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?

Anthony PerkinsCommented:
>>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,
AntoniLAuthor Commented:
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

Anthony PerkinsCommented:
>>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,
AntoniLAuthor Commented:
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

Anthony PerkinsCommented:
Thanks for closing your old open questions.  Hopefully someone will offer some help.

AntoniLAuthor Commented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.