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

KillTimer

関数
作成済みのタイマーを破棄する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL KillTimer(
    HWND hWnd,   // optional
    UINT_PTR uIDEvent
);

パラメーター

名前方向説明
hWndHWNDinoptional指定したタイマーに関連付けられたウィンドウへのハンドルです。この値は、タイマーを作成した SetTimer 関数に渡した hWnd の値と同じでなければなりません。
uIDEventUINT_PTRin

破棄するタイマーです。SetTimer に渡したウィンドウハンドルが有効な場合、このパラメーターは SetTimer に渡した nIDEvent

の値と同じでなければなりません。アプリケーションが hWndNULL に設定して SetTimer を呼び出した場合、このパラメーターは SetTimer が返したタイマー識別子でなければなりません。

戻り値の型: BOOL

公式ドキュメント

指定したタイマーを破棄します。

戻り値

型: BOOL

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出してください。

解説(Remarks)

KillTimer 関数は、すでにメッセージキューにポストされている WM_TIMER メッセージを削除しません。

例については、タイマーの破棄を参照してください。

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

各言語での呼び出し定義

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

BOOL KillTimer(
    HWND hWnd,   // optional
    UINT_PTR uIDEvent
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool KillTimer(
    IntPtr hWnd,   // HWND optional
    UIntPtr uIDEvent   // UINT_PTR
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function KillTimer(
    hWnd As IntPtr,   ' HWND optional
    uIDEvent As UIntPtr   ' UINT_PTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hWnd : HWND optional
' uIDEvent : UINT_PTR
Declare PtrSafe Function KillTimer Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal uIDEvent As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

KillTimer = ctypes.windll.user32.KillTimer
KillTimer.restype = wintypes.BOOL
KillTimer.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND optional
    ctypes.c_size_t,  # uIDEvent : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
KillTimer = Fiddle::Function.new(
  lib['KillTimer'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND optional
    Fiddle::TYPE_UINTPTR_T,  # uIDEvent : UINT_PTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn KillTimer(
        hWnd: *mut core::ffi::c_void,  // HWND optional
        uIDEvent: usize  // UINT_PTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool KillTimer(IntPtr hWnd, UIntPtr uIDEvent);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_KillTimer' -Namespace Win32 -PassThru
# $api::KillTimer(hWnd, uIDEvent)
#uselib "USER32.dll"
#func global KillTimer "KillTimer" sptr, sptr
; KillTimer hWnd, uIDEvent   ; 戻り値は stat
; hWnd : HWND optional -> "sptr"
; uIDEvent : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global KillTimer "KillTimer" sptr, sptr
; res = KillTimer(hWnd, uIDEvent)
; hWnd : HWND optional -> "sptr"
; uIDEvent : UINT_PTR -> "sptr"
; BOOL KillTimer(HWND hWnd, UINT_PTR uIDEvent)
#uselib "USER32.dll"
#cfunc global KillTimer "KillTimer" intptr, intptr
; res = KillTimer(hWnd, uIDEvent)
; hWnd : HWND optional -> "intptr"
; uIDEvent : UINT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procKillTimer = user32.NewProc("KillTimer")
)

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

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

typedef KillTimerNative = Int32 Function(Pointer<Void>, UintPtr);
typedef KillTimerDart = int Function(Pointer<Void>, int);
final KillTimer = DynamicLibrary.open('USER32.dll')
    .lookupFunction<KillTimerNative, KillTimerDart>('KillTimer');
// hWnd : HWND optional -> Pointer<Void>
// uIDEvent : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function KillTimer(
  hWnd: THandle;   // HWND optional
  uIDEvent: NativeUInt   // UINT_PTR
): BOOL; stdcall;
  external 'USER32.dll' name 'KillTimer';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "KillTimer"
  c_KillTimer :: Ptr () -> CUIntPtr -> IO CInt
-- hWnd : HWND optional -> Ptr ()
-- uIDEvent : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let killtimer =
  foreign "KillTimer"
    ((ptr void) @-> size_t @-> returning int32_t)
(* hWnd : HWND optional -> (ptr void) *)
(* uIDEvent : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("KillTimer" kill-timer :convention :stdcall) :int32
  (h-wnd :pointer)   ; HWND optional
  (u-idevent :uint64))   ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $KillTimer = Win32::API::More->new('USER32',
    'BOOL KillTimer(HANDLE hWnd, WPARAM uIDEvent)');
# my $ret = $KillTimer->Call($hWnd, $uIDEvent);
# hWnd : HWND optional -> HANDLE
# uIDEvent : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目