Jump to content

Recommended Posts

Posted (edited)

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
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...