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

PathCompactPathA

関数
指定のピクセル幅に収まるよう、パス文字列を省略記号で短縮する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL PathCompactPathA(
    HDC hDC,   // optional
    LPSTR pszPath,
    DWORD dx
);

パラメーター

名前方向
hDCHDCinoptional
pszPathLPSTRinout
dxDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL PathCompactPathA(
    HDC hDC,   // optional
    LPSTR pszPath,
    DWORD dx
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool PathCompactPathA(
    IntPtr hDC,   // HDC optional
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszPath,   // LPSTR in/out
    uint dx   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PathCompactPathA(
    hDC As IntPtr,   ' HDC optional
    <MarshalAs(UnmanagedType.LPStr)> pszPath As System.Text.StringBuilder,   ' LPSTR in/out
    dx As UInteger   ' DWORD
) As Boolean
End Function
' hDC : HDC optional
' pszPath : LPSTR in/out
' dx : DWORD
Declare PtrSafe Function PathCompactPathA Lib "shlwapi" ( _
    ByVal hDC As LongPtr, _
    ByVal pszPath As String, _
    ByVal dx As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathCompactPathA = ctypes.windll.shlwapi.PathCompactPathA
PathCompactPathA.restype = wintypes.BOOL
PathCompactPathA.argtypes = [
    wintypes.HANDLE,  # hDC : HDC optional
    wintypes.LPSTR,  # pszPath : LPSTR in/out
    wintypes.DWORD,  # dx : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathCompactPathA = Fiddle::Function.new(
  lib['PathCompactPathA'],
  [
    Fiddle::TYPE_VOIDP,  # hDC : HDC optional
    Fiddle::TYPE_VOIDP,  # pszPath : LPSTR in/out
    -Fiddle::TYPE_INT,  # dx : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn PathCompactPathA(
        hDC: *mut core::ffi::c_void,  // HDC optional
        pszPath: *mut u8,  // LPSTR in/out
        dx: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern bool PathCompactPathA(IntPtr hDC, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszPath, uint dx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathCompactPathA' -Namespace Win32 -PassThru
# $api::PathCompactPathA(hDC, pszPath, dx)
#uselib "SHLWAPI.dll"
#func global PathCompactPathA "PathCompactPathA" sptr, sptr, sptr
; PathCompactPathA hDC, varptr(pszPath), dx   ; 戻り値は stat
; hDC : HDC optional -> "sptr"
; pszPath : LPSTR in/out -> "sptr"
; dx : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global PathCompactPathA "PathCompactPathA" sptr, var, int
; res = PathCompactPathA(hDC, pszPath, dx)
; hDC : HDC optional -> "sptr"
; pszPath : LPSTR in/out -> "var"
; dx : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL PathCompactPathA(HDC hDC, LPSTR pszPath, DWORD dx)
#uselib "SHLWAPI.dll"
#cfunc global PathCompactPathA "PathCompactPathA" intptr, var, int
; res = PathCompactPathA(hDC, pszPath, dx)
; hDC : HDC optional -> "intptr"
; pszPath : LPSTR in/out -> "var"
; dx : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathCompactPathA = shlwapi.NewProc("PathCompactPathA")
)

// hDC (HDC optional), pszPath (LPSTR in/out), dx (DWORD)
r1, _, err := procPathCompactPathA.Call(
	uintptr(hDC),
	uintptr(pszPath),
	uintptr(dx),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function PathCompactPathA(
  hDC: THandle;   // HDC optional
  pszPath: PAnsiChar;   // LPSTR in/out
  dx: DWORD   // DWORD
): BOOL; stdcall;
  external 'SHLWAPI.dll' name 'PathCompactPathA';
result := DllCall("SHLWAPI\PathCompactPathA"
    , "Ptr", hDC   ; HDC optional
    , "Ptr", pszPath   ; LPSTR in/out
    , "UInt", dx   ; DWORD
    , "Int")   ; return: BOOL
●PathCompactPathA(hDC, pszPath, dx) = DLL("SHLWAPI.dll", "bool PathCompactPathA(void*, char*, dword)")
# 呼び出し: PathCompactPathA(hDC, pszPath, dx)
# hDC : HDC optional -> "void*"
# pszPath : LPSTR in/out -> "char*"
# dx : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。