Win32 API 日本語リファレンス
ホームSystem.Console › ShowConsoleCursor

ShowConsoleCursor

関数
コンソールのカーソルの表示・非表示を切り替える内部関数。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

INT ShowConsoleCursor(
    HANDLE hConsoleOutput,
    BOOL bShow
);

パラメーター

名前方向説明
hConsoleOutputHANDLEin対象のコンソール画面バッファのハンドル。
bShowBOOLinカーソルを表示する場合TRUE、非表示にする場合FALSE。表示カウントを増減する。

戻り値の型: INT

各言語での呼び出し定義

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

INT ShowConsoleCursor(
    HANDLE hConsoleOutput,
    BOOL bShow
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern int ShowConsoleCursor(
    IntPtr hConsoleOutput,   // HANDLE
    bool bShow   // BOOL
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function ShowConsoleCursor(
    hConsoleOutput As IntPtr,   ' HANDLE
    bShow As Boolean   ' BOOL
) As Integer
End Function
' hConsoleOutput : HANDLE
' bShow : BOOL
Declare PtrSafe Function ShowConsoleCursor Lib "kernel32" ( _
    ByVal hConsoleOutput As LongPtr, _
    ByVal bShow As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ShowConsoleCursor = ctypes.windll.kernel32.ShowConsoleCursor
ShowConsoleCursor.restype = ctypes.c_int
ShowConsoleCursor.argtypes = [
    wintypes.HANDLE,  # hConsoleOutput : HANDLE
    wintypes.BOOL,  # bShow : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
ShowConsoleCursor = Fiddle::Function.new(
  lib['ShowConsoleCursor'],
  [
    Fiddle::TYPE_VOIDP,  # hConsoleOutput : HANDLE
    Fiddle::TYPE_INT,  # bShow : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn ShowConsoleCursor(
        hConsoleOutput: *mut core::ffi::c_void,  // HANDLE
        bShow: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern int ShowConsoleCursor(IntPtr hConsoleOutput, bool bShow);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_ShowConsoleCursor' -Namespace Win32 -PassThru
# $api::ShowConsoleCursor(hConsoleOutput, bShow)
#uselib "KERNEL32.dll"
#func global ShowConsoleCursor "ShowConsoleCursor" sptr, sptr
; ShowConsoleCursor hConsoleOutput, bShow   ; 戻り値は stat
; hConsoleOutput : HANDLE -> "sptr"
; bShow : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global ShowConsoleCursor "ShowConsoleCursor" sptr, int
; res = ShowConsoleCursor(hConsoleOutput, bShow)
; hConsoleOutput : HANDLE -> "sptr"
; bShow : BOOL -> "int"
; INT ShowConsoleCursor(HANDLE hConsoleOutput, BOOL bShow)
#uselib "KERNEL32.dll"
#cfunc global ShowConsoleCursor "ShowConsoleCursor" intptr, int
; res = ShowConsoleCursor(hConsoleOutput, bShow)
; hConsoleOutput : HANDLE -> "intptr"
; bShow : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procShowConsoleCursor = kernel32.NewProc("ShowConsoleCursor")
)

// hConsoleOutput (HANDLE), bShow (BOOL)
r1, _, err := procShowConsoleCursor.Call(
	uintptr(hConsoleOutput),
	uintptr(bShow),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function ShowConsoleCursor(
  hConsoleOutput: THandle;   // HANDLE
  bShow: BOOL   // BOOL
): Integer; stdcall;
  external 'KERNEL32.dll' name 'ShowConsoleCursor';
result := DllCall("KERNEL32\ShowConsoleCursor"
    , "Ptr", hConsoleOutput   ; HANDLE
    , "Int", bShow   ; BOOL
    , "Int")   ; return: INT
●ShowConsoleCursor(hConsoleOutput, bShow) = DLL("KERNEL32.dll", "int ShowConsoleCursor(void*, bool)")
# 呼び出し: ShowConsoleCursor(hConsoleOutput, bShow)
# hConsoleOutput : HANDLE -> "void*"
# bShow : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn ShowConsoleCursor(
    hConsoleOutput: ?*anyopaque, // HANDLE
    bShow: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;
proc ShowConsoleCursor(
    hConsoleOutput: pointer,  # HANDLE
    bShow: int32  # BOOL
): int32 {.importc: "ShowConsoleCursor", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int ShowConsoleCursor(
    void* hConsoleOutput,   // HANDLE
    int bShow   // BOOL
);
ccall((:ShowConsoleCursor, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32),
      hConsoleOutput, bShow)
# hConsoleOutput : HANDLE -> Ptr{Cvoid}
# bShow : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ShowConsoleCursor(
    void* hConsoleOutput,
    int32_t bShow);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.ShowConsoleCursor(hConsoleOutput, bShow)
-- hConsoleOutput : HANDLE
-- bShow : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const ShowConsoleCursor = lib.func('__stdcall', 'ShowConsoleCursor', 'int32_t', ['void *', 'int32_t']);
// ShowConsoleCursor(hConsoleOutput, bShow)
// hConsoleOutput : HANDLE -> 'void *'
// bShow : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  ShowConsoleCursor: { parameters: ["pointer", "i32"], result: "i32" },
});
// lib.symbols.ShowConsoleCursor(hConsoleOutput, bShow)
// hConsoleOutput : HANDLE -> "pointer"
// bShow : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ShowConsoleCursor(
    void* hConsoleOutput,
    int32_t bShow);
C, "KERNEL32.dll");
// $ffi->ShowConsoleCursor(hConsoleOutput, bShow);
// hConsoleOutput : HANDLE
// bShow : BOOL
// 構造体/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    int ShowConsoleCursor(
        Pointer hConsoleOutput,   // HANDLE
        boolean bShow   // BOOL
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun ShowConsoleCursor = ShowConsoleCursor(
    hConsoleOutput : Void*,   # HANDLE
    bShow : Int32   # BOOL
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ShowConsoleCursorNative = Int32 Function(Pointer<Void>, Int32);
typedef ShowConsoleCursorDart = int Function(Pointer<Void>, int);
final ShowConsoleCursor = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<ShowConsoleCursorNative, ShowConsoleCursorDart>('ShowConsoleCursor');
// hConsoleOutput : HANDLE -> Pointer<Void>
// bShow : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ShowConsoleCursor(
  hConsoleOutput: THandle;   // HANDLE
  bShow: BOOL   // BOOL
): Integer; stdcall;
  external 'KERNEL32.dll' name 'ShowConsoleCursor';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ShowConsoleCursor"
  c_ShowConsoleCursor :: Ptr () -> CInt -> IO Int32
-- hConsoleOutput : HANDLE -> Ptr ()
-- bShow : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let showconsolecursor =
  foreign "ShowConsoleCursor"
    ((ptr void) @-> int32_t @-> returning int32_t)
(* hConsoleOutput : HANDLE -> (ptr void) *)
(* bShow : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("ShowConsoleCursor" show-console-cursor :convention :stdcall) :int32
  (h-console-output :pointer)   ; HANDLE
  (b-show :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ShowConsoleCursor = Win32::API::More->new('KERNEL32',
    'int ShowConsoleCursor(HANDLE hConsoleOutput, BOOL bShow)');
# my $ret = $ShowConsoleCursor->Call($hConsoleOutput, $bShow);
# hConsoleOutput : HANDLE -> HANDLE
# bShow : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。