File: u_displayicon.sru
Size: 3359
Date: Mon, 31 Dec 2018 21:14:38 +0100
$PBExportHeader$u_displayicon.sru
forward
global type u_displayicon from userobject
end type
end forward

global type u_displayicon from userobject
integer width = 146
integer height = 128
boolean enabled = false
long backcolor = 79741120
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
event redraw pbm_ncpaint
end type
global u_displayicon u_displayicon

type prototypes
Function long ExtractIcon ( &
   long hInst, &
   string lpszExeFileName, &
   ulong nIconIndex &
   ) Library "shell32.dll" Alias For "ExtractIconA"

Function boolean DestroyIcon ( &
   long hIcon &
   ) Library "user32.dll"

Function integer DrawIcon ( &
   long hDC, &
   long xpos, &
   long ypos, &
   long hIcon &
   ) Library "user32.dll"

Function long GetDC ( &
   long hWnd &
   ) Library "user32.dll"

Function integer ReleaseDC ( &
   long hWnd, &
   long hDC &
   ) Library "user32.dll"

Function long GetModuleFileName ( &
   long hModule, &
   ref string lpFileName, &
   long nSize &
   ) Library "kernel32.dll" Alias For "GetModuleFileNameA"

end prototypes
type variables
Application ia_app
Long il_handle

end variables

forward prototypes
public subroutine of_loadicon (string as_filename)
public subroutine of_drawicon ()
public subroutine of_loadicon ()
public subroutine of_loadicon (string as_filename)
public subroutine of_drawicon ()
public subroutine of_loadicon ()
public subroutine of_loadicon (string as_filename, unsignedlong aul_index)
public function long of_iconcount (string as_filename)
end prototypes

event redraw;// draw the icon
Post of_DrawIcon()

end event

public subroutine of_loadicon (string as_filename);// load first icon from file
of_LoadIcon(as_filename, 0)

end subroutine

public subroutine of_drawicon ();// draw the current icon

Long ll_hDC

ll_hDC = GetDC(Handle(This))

DrawIcon(ll_hDC, 0, 0, il_handle)

ReleaseDC(Handle(This), ll_hDC)

end subroutine

public subroutine of_loadicon ();// load icon from current exe

String ls_module
Long ll_rc

ls_module = Space(256)

ll_rc = GetModuleFileName(Handle(ia_app), ls_module, 256)
If ll_rc > 0 Then
   of_LoadIcon(ls_module)
End If

end subroutine

public subroutine of_loadicon (string as_filename, unsignedlong aul_index);// load icon from file

// release icon handle
If il_handle > 0 Then
   DestroyIcon(il_handle)
End If

// extract icon from file and load into memory
il_handle = ExtractIcon(Handle(ia_app), as_filename, aul_index)

// erase the background
BackColor = BackColor

// draw the icon
of_DrawIcon()

end subroutine

public function long of_iconcount (string as_filename);// return count of icons within the file

Long ll_count

ll_count = ExtractIcon(Handle(ia_app), as_filename, -1)

Return ll_count

end function

on u_displayicon.create
end on

on u_displayicon.destroy
end on

event destructor;// release icon handle
If il_handle > 0 Then
   DestroyIcon(il_handle)
End If

end event

event constructor;// set backcolor to match parent window

Window lw_parent
UserObject lu_parent

choose case GetParent().TypeOf()
   case UserObject!
      lu_parent = GetParent()
      this.BackColor = lu_parent.BackColor
   case Window!
      lw_parent = GetParent()
      this.BackColor = lw_parent.BackColor
end choose

ia_app = GetApplication()

end event