Jump to content
NabilG

changing AutoCAD Icon at runtime

Recommended Posts

NabilG

Dear experts, apologize if this question was already raised in the past, but I will be grateful if someone could tell me what I am doing wrong here:

 

  Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long

   Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Integer

Then I get a Handler on the ICON file I want to substitute the default AutoCAD with:

       Const IMAGE_ICON As Long = 1
       Const WM_SETICON As Long = &H80
       Const ICON_BIG As Long = 1
       Const ICON_SMALL As Long = 0
       Const LR_LOADFROMFILE As Long = &H10
       Dim A_ICON As Long = LoadImage(Nothing, "xp218.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE)

then I try to update the current active document HWND with:

             SendMessage(AcadApp.ActiveDocument.HWND, WM_SETICON, ICON_BIG, A_ICON)
               SendMessage(AcadApp.ActiveDocument.HWND, WM_SETICON, ICON_SMALL, A_ICON)

with AcadApp defined as:

AcadApp As Autodesk.AutoCAD.Interop.AcadApplication

Unfortunately it does not work.

In advance, thanks for your valuable help.

Edited by NabilG

Share this post


Link to post
Share on other sites
NabilG

Hi, indeed I think I found the issue, I was not pointing to the right HWND;

 

If instead I use:

AcadApp.GetType().InvokeMember("HWND", System.Reflection.BindingFlags.GetProperty, Nothing, AcadApp, Nothing)

to get the HWND, it works fine.

 

               SendMessage(AcadApp.GetType().InvokeMember("HWND", System.Reflection.BindingFlags.GetProperty, Nothing, AcadApp, Nothing), WM_SETICON, ICON_BIG, A_ICON)
               SendMessage(AcadApp.GetType().InvokeMember("HWND", System.Reflection.BindingFlags.GetProperty, Nothing, AcadApp, Nothing), WM_SETICON, ICON_SMALL, A_ICON)

SendMessage(AcadApp.GetType().InvokeMember("HWND", System.Reflection.BindingFlags.GetProperty, Nothing, AcadApp, Nothing), WM_SETICON, ICON_BIG, A_ICON)

it works and I get the correct icon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×