File: u_displayicon.sru
Size: 3861
Date: Mon, 27 Jul 2020 11:39:44 +0200
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 "ExtractIconW"

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 "GetModuleFileNameW"

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, unsignedlong aul_index)
public function long of_iconcount (string as_filename)
public function string of_pbvmname ()
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
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
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

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

public function string of_pbvmname ();// This function returns the name of the PowerBuilder VM.

Environment le_env
String ls_vmname
Integer li_major


li_major = le_env.PBMajorRevision
If li_major = 6 Then
   ls_vmname = "pbvm" + String(li_major) + "0.dll"
   choose case le_env.PBMinorRevision
      case 5
         ls_vmname = "pbvm" + String(li_major) + "5.dll"
      case 6
         ls_vmname = "pbvm" + String(li_major) + "6.dll"
      case else
         ls_vmname = "pbvm" + String(li_major) + "0.dll"
   end choose
End If

Return ls_vmname

end function

on u_displayicon.create
end on

on u_displayicon.destroy
end on

event destructor;// release icon handle
If il_handle > 0 Then
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