Jump to content

Recommended Posts

Posted (edited)

Hello,

I've been reading through the forum for the last week trying to figure out how to launch an external app with a custom icon. My goal is to customize the title bar completely. WinSetTitle, easy. When it comes to changing the icon, I'm a bit lost or maybe way lost..? From what i have read in other posts, Zedna stated, "You need just WinGetHandle() + LoadIcon and SendMessage (WM_SETICON) API functions". A link provided in that topic, http://support.microsoft.com/kb/259673/en-us?fr=1 refers to a VB.exe. The app I'm testing with is VB6. I would like it if what I'm trying to accomplish will work with any app, but if that's not possible, so be it. I've tried three different resource editors with no luck. The icon must be an embedded resource. Any help would be great. Thanks.

Windows 7

AutoIt v3.3.12

SciTE v3.4.4

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
;#include <APIConstants.au3>
#include <SendMessage.au3>

   Run ("C:\Users\lowbred\Desktop\Software\rtmkvcm.exe")
   WinWait("[CLASS:ThunderRT6FormDC]", "", 10)
   ;WinWait("[CLASS:ThunderRT6Main]", "", 10)

   Local $hWnd = WinGetHandle("[CLASS:ThunderRT6FormDC]")
   ;Local $hWnd = WinGetHandle("[CLASS:ThunderRT6Main]")
   Local $Icon = ("C:\Users\lowbred\Pictures\Icons\test.ico")

  If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle.")
        Exit
  EndIf

  MsgBox($MB_SYSTEMMODAL, "", $hWnd)

  Func GetWindowLong($hWnd)
    Local $nVal = DllCall("user32.dll", "int", $hWnd, "int")
    ;Return $WM_SETICON["ICON_SMALL"]
    Return $WM_SETICON[0]
  EndFunc   ;==>GetWindowLong

  Func LoadIcon($Icon)
    _SendMessage ($hWnd, $WM_SETICON, "GetWindowLong")
  EndFunc   ;==>LoadIcon
Edited by lowbred
Posted (edited)

Here is small working example to start with ...

#NoTrayIcon
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>

Const $ICON_BIG = 1
Const $ICON_SMALL = 0

Run("C:\WINDOWS\notepad.exe ")
WinWait("[CLASS:Notepad]", "", 10)
$hWnd = WinGetHandle("[CLASS:Notepad]")
If @error Then
    MsgBox(0, "", "An error occurred when trying to retrieve the window handle.")
    Exit
EndIf

$hIcon = _WinAPI_LoadImage(0, "c:\Program Files\AutoIt3\Aut2Exe\Icons\AutoIt_Old1.ico", $IMAGE_ICON, 0, 0, $LR_LOADFROMFILE)
$hIcon_orig = _SendMessage($hWnd, $WM_SETICON, $ICON_BIG, $hIcon)

; uncomment this to restore original icon ...
;Sleep(3000)
;_SendMessage($hWnd, $WM_SETICON, $ICON_BIG, $hIcon_orig)
Edited by Zedna
Posted

Zedna, thanks.

The script you provided works perfectly with every program I tried except for the first initial VB6 one.

I ran the VB6 program sandboxed and found that it creates 3 temp files. Loading one of them into a hex editor, I noticed the icon drawn (smiley-face).

http://imgbox.com/pDzi5xWp

I'm thinking there is no icon to be replaced, as it is drawn when the program is ran..? The 3 files are as follows but the names change every time the program is ran.

~DF56D4328509EB6990.tmp - icon
MBX@DD8@2A0FD0.### -

                                          | - relates to, I think, MapBasic... color is always a shade of blue but icon is yellow..?
MBX@DD8@2A0FE0.### -

If you can wrap your brain around that, CHEERS! If not, thanks again.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...