Sign in to follow this  
Followers 0
hounder

WinAPI Draw Icon Help

14 posts in this topic

#1 ·  Posted (edited)

heres my current code,

$pIcon = @WindowsDir & '\system32\cmd.exe'
$iconStruct = DllStructCreate("int Handle")
_WinAPI_ExtractIconEx($pIcon, 0, 0, DllStructGetPtr($iconStruct), 1)
$hIcon = DllStructGetData($iconStruct, "Handle", 1)
_WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)

cant quite seem to figure out how to draw one of my own icons, instead of grabbing another icon from an .exe.

IE. i want to draw "favicon.ico".

help anyone?

Edited by hounder

Share this post


Link to post
Share on other sites

What is $hDC?

$hDC = _WinAPI_GetDC($GuiMain)

Share this post


Link to post
Share on other sites

hounder you need to do different things. Like here:

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $hGui = GUICreate("")
Global $hDC = _WinAPI_GetDC($hGui)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX


$pIcon = @WindowsDir & '\system32\cmd.exe'
$iconStruct = DllStructCreate("int Handle")
_WinAPI_ExtractIconEx($pIcon, 0, 0, DllStructGetPtr($iconStruct), 1)
$hIcon = DllStructGetData($iconStruct, "Handle", 1)
;_WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
GUIRegisterMsg($WM_PAINT, "_Draw")
GUISetState()

While GUIGetMsg() <> -3
WEnd

Func _Draw()
    _WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)
EndFunc
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

hounder you need to do different things. Like here:

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $hGui = GUICreate("")
Global $hDC = _WinAPI_GetDC($hGui)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX


$pIcon = @WindowsDir & '\system32\cmd.exe'
$iconStruct = DllStructCreate("int Handle")
_WinAPI_ExtractIconEx($pIcon, 0, 0, DllStructGetPtr($iconStruct), 1)
$hIcon = DllStructGetData($iconStruct, "Handle", 1)
;_WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
GUIRegisterMsg($WM_PAINT, "_Draw")
GUISetState()

While GUIGetMsg() <> -3
WEnd

Func _Draw()
    _WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)
EndFunc
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

alright, now how do i go about using winapi_drawiconex to draw a standalone icon file? ive got an icon in my script folder that i want it to draw, lets say its called "favicon.ico".

Share this post


Link to post
Share on other sites

alright, now how do i go about using winapi_drawiconex to draw a standalone icon file? ive got an icon in my script folder that i want it to draw, lets say its called "favicon.ico".

What exactly is the problem?

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

What exactly is the problem?

heres my current code,

$pIcon = @WindowsDir & '\system32\cmd.exe'
$iconStruct = DllStructCreate("int Handle")
_WinAPI_ExtractIconEx($pIcon, 0, 0, DllStructGetPtr($iconStruct), 1)
$hIcon = DllStructGetData($iconStruct, "Handle", 1)
_WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)

cant quite seem to figure out how to draw one of my own icons, instead of grabbing another icon from an .exe.

IE. i want to draw "favicon.ico".

help anyone?

Share this post


Link to post
Share on other sites

I was warned recently to stay on topic in threads like this.

Lucky you.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

When you say "draw", do you mean

  • create it from scratch
  • copy it from a existing icon
  • extract it from an EXE that already exist
  • use the icon file that already exist and tie it to a file so when I look at it, this is the icon it uses.
  • none of the above - Please re-read my last post
Edited by Volly

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

When you say "draw", do you mean

  • create it from scratch
  • copy it from a existing icon
  • extract it from an EXE that already exist
  • use the icon file that already exist and tie it to a file so when I look at it, this is the icon it uses.
  • none of the above - Please re-read my last post

let me know if this makes more sense of what im trying to do,

Posted Image

Edited by hounder

Share this post


Link to post
Share on other sites

#13 ·  Posted

OK, this is for a compiles script. Simple. when you go to compile your script, you tell the compiler what icon to use.

look at my cokelocker script when compiled and running.

heres my script, it doesnt use the standard GUI so i cant set an icon file the normal way. hence why im using the winapi draw functions to create the rest of the gui, im only assuming i can draw the icon aswell.

#NoTrayIcon
#include <WinAPI.au3>
#include <String.au3>
#include <Array.au3>
#include <file.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIButton.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>
#include <FontConstants.au3>

Global Const $SC_DRAGMOVE = 0xF012
Opt("MouseCoordMode", 2)
Local $tMsg
Opt("TrayMenuMode", 1)

$frmMain = GUICreate("frmMain", 472, 329, 192, 124, $WS_POPUP, 0)
GUISetBkColor(0xc2c2c2,$frmMain)
GUISetState(@SW_SHOW)
$rgn = _WinAPI_CreateRoundRectRgn(0, 0, 472, 329, 3, 3)
_WinAPI_SetWindowRgn($frmMain, $rgn)
DrawBar()

While 1
    $tMsg = TrayGetMsg()
    Switch $tMsg
        Case $TRAY_EVENT_PRIMARYDOWN
            GUISetState(@SW_SHOW)
            DrawBar()
            WinSetState("frmMain", "", @SW_RESTORE)
            Opt("TrayIconHide", 1)
    EndSwitch

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            $mPos = MouseGetPos()
            If $mPos[1] <= 20 Then
                If $mPos[0] >= 432 And $mPos[0] <= 444 Then
                    GUISetState(@SW_HIDE)
                    Opt("TrayIconHide", 0)
                ElseIf $mPos[0] >= 445 And $mPos[0] <= 471 Then
                    Exit
                Else
                    _SendMessage($frmMain, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
                EndIf
            EndIf
    EndSwitch
WEnd




Func Hwid()
    $OSLang = StringLeft(@OSLang, 3)
    $OSVersion = StringRight(@OSVersion, 2)
    $Id = ($OSLang & "-" & $OSVersion & "-" & @OSBuild & "-" & @OSArch)
    Return _StringEncrypt(1, $ID, @UserName)
    ;MsgBox(0, "Unique ID", Hwid())
EndFunc

Func DrawBar()
    Local $aDim = WinGetClientSize($frmMain)
    Local $hDC = _WinAPI_GetDC($frmMain)
    ; Bar
    Local $hBrush = _WinAPI_CreateSolidBrush(0xe6e6e6)
    Local $hRect = DllStructCreate($tagRECT)
    DllStructSetData($hRect,"Left",0)
    DllStructSetData($hRect,"Top",0)
    DllStructSetData($hRect,"Right",$aDim[0])
    DllStructSetData($hRect,"Bottom",20)
    _WinAPI_FillRect($hDC,DllStructGetPtr($hRect),$hBrush)
    _WinAPI_DeleteObject($hBrush)
    ; Title
    $hFont = _WinAPI_CreateFont(17, 0, 0, 0, 700, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Verdana')
    $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
    _WinAPI_SetTextColor($hDC, 0x33383e)
    _WinAPI_SetBkMode($hDC, $TRANSPARENT)
    _WinAPI_DrawText($hDC, "      NOD", $hRect, $DT_LEFT)
    ; Icon
    $pIcon = @WindowsDir & '\system32\cmd.exe'
    $iconStruct = DllStructCreate("int Handle")
    _WinAPI_ExtractIconEx($pIcon, 0, 0, DllStructGetPtr($iconStruct), 1)
    $hIcon = DllStructGetData($iconStruct, "Handle", 1)
    _WinAPI_DrawIconEx($hDC, 7, 1, $hIcon, 16, 16)
    ; Minimize
    $hBrush = _WinAPI_CreateSolidBrush(0x33383e)
    DllStructSetData($hRect,"Left",$aDim[0]-37)
    DllStructSetData($hRect,"Top",12)
    DllStructSetData($hRect,"Right",$aDim[0]-28)
    DllStructSetData($hRect,"Bottom",14)
    _WinAPI_FillRect($hDC,DllStructGetPtr($hRect),$hBrush)
    _WinAPI_DeleteObject($hBrush)
    ; Close
    Local $hPen = _WinAPI_CreatePen($PS_SOLID,2,0x33383e)
    Local $hSelected = _WinAPI_SelectObject($hDC,$hPen)
    _WinAPI_DrawLine($hDC,$aDim[0]-20, 5, $aDim[0]-11, 14)
    _WinAPI_DrawLine($hDC,$aDim[0]-20, 14, $aDim[0]-11, 5)
    _WinAPI_SelectObject($hDC,$hSelected)
    _WinAPI_DeleteObject($hPen)
    $hBrush = _WinAPI_CreateSolidBrush(0xd8ded3)
    ; Frame Edge
    $hBrush = _WinAPI_CreateSolidBrush(0xe6e6e6)
    DllStructSetData($hRect,"Left",$aDim[0]-2)
    DllStructSetData($hRect,"Top",20)
    DllStructSetData($hRect,"Right",$aDim[0])
    DllStructSetData($hRect,"Bottom",$aDim[1])
    _WinAPI_FillRect($hDC,DllStructGetPtr($hRect),$hBrush)
    DllStructSetData($hRect,"Left",0)
    DllStructSetData($hRect,"Top",20)
    DllStructSetData($hRect,"Right",1)
    DllStructSetData($hRect,"Bottom",$aDim[1])
    _WinAPI_FillRect($hDC,DllStructGetPtr($hRect),$hBrush)
    DllStructSetData($hRect,"Left",0)
    DllStructSetData($hRect,"Top",$aDim[1]-1)
    DllStructSetData($hRect,"Right",$aDim[0])
    DllStructSetData($hRect,"Bottom",$aDim[1]-2)
    _WinAPI_FillRect($hDC,DllStructGetPtr($hRect),$hBrush)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($frmMain,$hDC)
    AdlibRegister("DrawBar")
EndFunc

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

OK, now I see your problem. I compiled your script and used a different Icon. For the EXE I see the Icon I used. When I ran your script, I see the command prompt icon in the upper corner. OK, I will have to see what can be done about this.

Edited by Volly

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
Sign in to follow this  
Followers 0