Win32 API 日本語リファレンス
ホームUI.Controls › LoadIconWithScaleDown

LoadIconWithScaleDown

関数
指定サイズに縮小してアイコンを読み込む。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// COMCTL32.dll
#include <windows.h>

HRESULT LoadIconWithScaleDown(
    HINSTANCE hinst,   // optional
    LPCWSTR pszName,
    INT cx,
    INT cy,
    HICON* phico
);

パラメーター

名前方向説明
hinstHINSTANCEinoptional

読み込むアイコンを含む DLL または実行可能ファイル (.exe) のモジュールへのハンドル。詳細については、GetModuleHandle を参照してください。

定義済みのシステムアイコンまたはスタンドアロンのアイコンファイルを読み込むには、このパラメーターを NULL に設定します。

pszNameLPCWSTRin

読み込むアイコンの位置情報を含む、null で終わる Unicode バッファーへのポインター。

hinstNULL 以外の場合、pszName はアイコンリソースを名前または序数で指定します。この序数は MAKEINTRESOURCE マクロを使用してパッケージ化する必要があります。

hinstNULL の場合、pszName は読み込む定義済みシステムアイコンの識別子 (IDI_ プレフィックスで始まる)を指定します。

cxINTinアイコンの希望する幅 (ピクセル単位)。
cyINTinアイコンの希望する高さ (ピクセル単位)。
phicoHICON*outこの関数が戻るとき、読み込まれたアイコンのハンドルへのポインターが格納されます。

戻り値の型: HRESULT

公式ドキュメント

アイコンを読み込みます。アイコンが標準サイズでない場合、この関数は小さい画像を拡大するのではなく、より大きい画像を縮小します。

戻り値

型: HRESULT

成功した場合は S_OK を返します。それ以外の場合は、次を含むエラー値を返します。

戻り値 説明
E_INVALIDARG
pszName が指すバッファーの内容が、想定されるいずれの解釈にも適合しません。

解説(Remarks)

この関数は、まずアイコンファイル内でまったく同じサイズのアイコンを検索します。一致するものが見つからない場合、cxcy の両方が標準アイコンサイズ (16、32、48、または 256 ピクセル) のいずれかに一致しない限り、次に大きいアイコンが選択され、希望するサイズに縮小されます。たとえば、呼び出し側アプリケーションが x 方向の寸法が 40 ピクセルのアイコンを要求した場合、48 ピクセルのアイコンが使用され、40 ピクセルに縮小されます。これに対して、LoadImage 関数は 32 ピクセルのアイコンを選択し、40 ピクセルに拡大します。

より大きいアイコンを見つけられない場合、この関数は次に小さいアイコンを見つけて希望するサイズに拡大するという標準の動作にフォールバックします。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// COMCTL32.dll
#include <windows.h>

HRESULT LoadIconWithScaleDown(
    HINSTANCE hinst,   // optional
    LPCWSTR pszName,
    INT cx,
    INT cy,
    HICON* phico
);
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern int LoadIconWithScaleDown(
    IntPtr hinst,   // HINSTANCE optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszName,   // LPCWSTR
    int cx,   // INT
    int cy,   // INT
    IntPtr phico   // HICON* out
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function LoadIconWithScaleDown(
    hinst As IntPtr,   ' HINSTANCE optional
    <MarshalAs(UnmanagedType.LPWStr)> pszName As String,   ' LPCWSTR
    cx As Integer,   ' INT
    cy As Integer,   ' INT
    phico As IntPtr   ' HICON* out
) As Integer
End Function
' hinst : HINSTANCE optional
' pszName : LPCWSTR
' cx : INT
' cy : INT
' phico : HICON* out
Declare PtrSafe Function LoadIconWithScaleDown Lib "comctl32" ( _
    ByVal hinst As LongPtr, _
    ByVal pszName As LongPtr, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal phico As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LoadIconWithScaleDown = ctypes.windll.comctl32.LoadIconWithScaleDown
LoadIconWithScaleDown.restype = ctypes.c_int
LoadIconWithScaleDown.argtypes = [
    wintypes.HANDLE,  # hinst : HINSTANCE optional
    wintypes.LPCWSTR,  # pszName : LPCWSTR
    ctypes.c_int,  # cx : INT
    ctypes.c_int,  # cy : INT
    ctypes.c_void_p,  # phico : HICON* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
LoadIconWithScaleDown = Fiddle::Function.new(
  lib['LoadIconWithScaleDown'],
  [
    Fiddle::TYPE_VOIDP,  # hinst : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # pszName : LPCWSTR
    Fiddle::TYPE_INT,  # cx : INT
    Fiddle::TYPE_INT,  # cy : INT
    Fiddle::TYPE_VOIDP,  # phico : HICON* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn LoadIconWithScaleDown(
        hinst: *mut core::ffi::c_void,  // HINSTANCE optional
        pszName: *const u16,  // LPCWSTR
        cx: i32,  // INT
        cy: i32,  // INT
        phico: *mut *mut core::ffi::c_void  // HICON* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("COMCTL32.dll")]
public static extern int LoadIconWithScaleDown(IntPtr hinst, [MarshalAs(UnmanagedType.LPWStr)] string pszName, int cx, int cy, IntPtr phico);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_LoadIconWithScaleDown' -Namespace Win32 -PassThru
# $api::LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
#uselib "COMCTL32.dll"
#func global LoadIconWithScaleDown "LoadIconWithScaleDown" sptr, sptr, sptr, sptr, sptr
; LoadIconWithScaleDown hinst, pszName, cx, cy, phico   ; 戻り値は stat
; hinst : HINSTANCE optional -> "sptr"
; pszName : LPCWSTR -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; phico : HICON* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "COMCTL32.dll"
#cfunc global LoadIconWithScaleDown "LoadIconWithScaleDown" sptr, wstr, int, int, sptr
; res = LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
; hinst : HINSTANCE optional -> "sptr"
; pszName : LPCWSTR -> "wstr"
; cx : INT -> "int"
; cy : INT -> "int"
; phico : HICON* out -> "sptr"
; HRESULT LoadIconWithScaleDown(HINSTANCE hinst, LPCWSTR pszName, INT cx, INT cy, HICON* phico)
#uselib "COMCTL32.dll"
#cfunc global LoadIconWithScaleDown "LoadIconWithScaleDown" intptr, wstr, int, int, intptr
; res = LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
; hinst : HINSTANCE optional -> "intptr"
; pszName : LPCWSTR -> "wstr"
; cx : INT -> "int"
; cy : INT -> "int"
; phico : HICON* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procLoadIconWithScaleDown = comctl32.NewProc("LoadIconWithScaleDown")
)

// hinst (HINSTANCE optional), pszName (LPCWSTR), cx (INT), cy (INT), phico (HICON* out)
r1, _, err := procLoadIconWithScaleDown.Call(
	uintptr(hinst),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszName))),
	uintptr(cx),
	uintptr(cy),
	uintptr(phico),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function LoadIconWithScaleDown(
  hinst: THandle;   // HINSTANCE optional
  pszName: PWideChar;   // LPCWSTR
  cx: Integer;   // INT
  cy: Integer;   // INT
  phico: Pointer   // HICON* out
): Integer; stdcall;
  external 'COMCTL32.dll' name 'LoadIconWithScaleDown';
result := DllCall("COMCTL32\LoadIconWithScaleDown"
    , "Ptr", hinst   ; HINSTANCE optional
    , "WStr", pszName   ; LPCWSTR
    , "Int", cx   ; INT
    , "Int", cy   ; INT
    , "Ptr", phico   ; HICON* out
    , "Int")   ; return: HRESULT
●LoadIconWithScaleDown(hinst, pszName, cx, cy, phico) = DLL("COMCTL32.dll", "int LoadIconWithScaleDown(void*, char*, int, int, void*)")
# 呼び出し: LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
# hinst : HINSTANCE optional -> "void*"
# pszName : LPCWSTR -> "char*"
# cx : INT -> "int"
# cy : INT -> "int"
# phico : HICON* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "comctl32" fn LoadIconWithScaleDown(
    hinst: ?*anyopaque, // HINSTANCE optional
    pszName: [*c]const u16, // LPCWSTR
    cx: i32, // INT
    cy: i32, // INT
    phico: ?*anyopaque // HICON* out
) callconv(std.os.windows.WINAPI) i32;
proc LoadIconWithScaleDown(
    hinst: pointer,  # HINSTANCE optional
    pszName: WideCString,  # LPCWSTR
    cx: int32,  # INT
    cy: int32,  # INT
    phico: pointer  # HICON* out
): int32 {.importc: "LoadIconWithScaleDown", stdcall, dynlib: "COMCTL32.dll".}
pragma(lib, "comctl32");
extern(Windows)
int LoadIconWithScaleDown(
    void* hinst,   // HINSTANCE optional
    const(wchar)* pszName,   // LPCWSTR
    int cx,   // INT
    int cy,   // INT
    void* phico   // HICON* out
);
ccall((:LoadIconWithScaleDown, "COMCTL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Int32, Int32, Ptr{Cvoid}),
      hinst, pszName, cx, cy, phico)
# hinst : HINSTANCE optional -> Ptr{Cvoid}
# pszName : LPCWSTR -> Cwstring
# cx : INT -> Int32
# cy : INT -> Int32
# phico : HICON* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t LoadIconWithScaleDown(
    void* hinst,
    const uint16_t* pszName,
    int32_t cx,
    int32_t cy,
    void* phico);
]]
local comctl32 = ffi.load("comctl32")
-- comctl32.LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
-- hinst : HINSTANCE optional
-- pszName : LPCWSTR
-- cx : INT
-- cy : INT
-- phico : HICON* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('COMCTL32.dll');
const LoadIconWithScaleDown = lib.func('__stdcall', 'LoadIconWithScaleDown', 'int32_t', ['void *', 'str16', 'int32_t', 'int32_t', 'void *']);
// LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
// hinst : HINSTANCE optional -> 'void *'
// pszName : LPCWSTR -> 'str16'
// cx : INT -> 'int32_t'
// cy : INT -> 'int32_t'
// phico : HICON* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("COMCTL32.dll", {
  LoadIconWithScaleDown: { parameters: ["pointer", "buffer", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.LoadIconWithScaleDown(hinst, pszName, cx, cy, phico)
// hinst : HINSTANCE optional -> "pointer"
// pszName : LPCWSTR -> "buffer"
// cx : INT -> "i32"
// cy : INT -> "i32"
// phico : HICON* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t LoadIconWithScaleDown(
    void* hinst,
    const uint16_t* pszName,
    int32_t cx,
    int32_t cy,
    void* phico);
C, "COMCTL32.dll");
// $ffi->LoadIconWithScaleDown(hinst, pszName, cx, cy, phico);
// hinst : HINSTANCE optional
// pszName : LPCWSTR
// cx : INT
// cy : INT
// phico : HICON* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Comctl32 extends StdCallLibrary {
    Comctl32 INSTANCE = Native.load("comctl32", Comctl32.class);
    int LoadIconWithScaleDown(
        Pointer hinst,   // HINSTANCE optional
        WString pszName,   // LPCWSTR
        int cx,   // INT
        int cy,   // INT
        Pointer phico   // HICON* out
    );
}
@[Link("comctl32")]
lib LibCOMCTL32
  fun LoadIconWithScaleDown = LoadIconWithScaleDown(
    hinst : Void*,   # HINSTANCE optional
    pszName : UInt16*,   # LPCWSTR
    cx : Int32,   # INT
    cy : Int32,   # INT
    phico : Void*   # HICON* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef LoadIconWithScaleDownNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Int32, Int32, Pointer<Void>);
typedef LoadIconWithScaleDownDart = int Function(Pointer<Void>, Pointer<Utf16>, int, int, Pointer<Void>);
final LoadIconWithScaleDown = DynamicLibrary.open('COMCTL32.dll')
    .lookupFunction<LoadIconWithScaleDownNative, LoadIconWithScaleDownDart>('LoadIconWithScaleDown');
// hinst : HINSTANCE optional -> Pointer<Void>
// pszName : LPCWSTR -> Pointer<Utf16>
// cx : INT -> Int32
// cy : INT -> Int32
// phico : HICON* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function LoadIconWithScaleDown(
  hinst: THandle;   // HINSTANCE optional
  pszName: PWideChar;   // LPCWSTR
  cx: Integer;   // INT
  cy: Integer;   // INT
  phico: Pointer   // HICON* out
): Integer; stdcall;
  external 'COMCTL32.dll' name 'LoadIconWithScaleDown';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "LoadIconWithScaleDown"
  c_LoadIconWithScaleDown :: Ptr () -> CWString -> Int32 -> Int32 -> Ptr () -> IO Int32
-- hinst : HINSTANCE optional -> Ptr ()
-- pszName : LPCWSTR -> CWString
-- cx : INT -> Int32
-- cy : INT -> Int32
-- phico : HICON* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let loadiconwithscaledown =
  foreign "LoadIconWithScaleDown"
    ((ptr void) @-> (ptr uint16_t) @-> int32_t @-> int32_t @-> (ptr void) @-> returning int32_t)
(* hinst : HINSTANCE optional -> (ptr void) *)
(* pszName : LPCWSTR -> (ptr uint16_t) *)
(* cx : INT -> int32_t *)
(* cy : INT -> int32_t *)
(* phico : HICON* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)

(cffi:defcfun ("LoadIconWithScaleDown" load-icon-with-scale-down :convention :stdcall) :int32
  (hinst :pointer)   ; HINSTANCE optional
  (psz-name (:string :encoding :utf-16le))   ; LPCWSTR
  (cx :int32)   ; INT
  (cy :int32)   ; INT
  (phico :pointer))   ; HICON* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $LoadIconWithScaleDown = Win32::API::More->new('COMCTL32',
    'int LoadIconWithScaleDown(HANDLE hinst, LPCWSTR pszName, int cx, int cy, HANDLE phico)');
# my $ret = $LoadIconWithScaleDown->Call($hinst, $pszName, $cx, $cy, $phico);
# hinst : HINSTANCE optional -> HANDLE
# pszName : LPCWSTR -> LPCWSTR
# cx : INT -> int
# cy : INT -> int
# phico : HICON* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。