その他のウインドウ関係のAPI関数
その他のウインドウ関係のAPI関数のサンプルです。
サンプルの実行画面

ソースコード
[OtherWindow.frm]
'CloseWindow=>ウインドウを最小化する '<引数> 'hWnd: ウインドウのハンドル '@戻り値@ '正常終了1 Private Declare Function CloseWindow Lib "USER32" (ByVal hWnd As Long) As Long 'BringWindowToTop =>ウインドウを手前にする '<引数> 'hwnd: ウインドウのハンドル '@戻り値@ ' 正常終了0以外 '*常に手前にはならない---->常に手前にするならSetWindowsPosを使用する Private Declare Function BringWindowToTop Lib "USER32" (ByVal hWnd As Long) As Long 'GetDesktopWindow=>デスクトップハンドルを取得 '<引数> ' なし '@戻り値@ 'デスクトップのハンドル Private Declare Function GetDesktopWindow Lib "USER32" () As Long 'GetForegroundWindow =>現在操作中のウインドウのハンドルを取得 '<引数> ' なし '@戻り値@ '操作中のウインドウのハンドル Private Declare Function GetForegroundWindow Lib "USER32" () As Long 'GetWindowDC =>ウインドウ全体のデバイスコンテキストのハンドルを取得する '<引数> 'hWnd: ウインドウのハンドル '@戻り値@ ' デバイスコンテキストのハンドル Private Declare Function GetWindowDC Lib "USER32" (ByVal hWnd As Long) As Long 'SetActiveWindow=>ウインドウをアクティブにさせる '<引数> 'hWnd: ウインドウのハンドル '@戻り値@ ' 直前にアクティブだったウインドウのハンドル Private Declare Function SetActiveWindow Lib "USER32" (ByVal hWnd As Long) As Long Private Sub Command1_Click(Index As Integer) Dim Ret As Long Select Case Index Case 0 Ret = CloseWindow(Form1.hWnd) Case 1 Ret = BringWindowToTop(Form1.hWnd) Case 2 Ret = GetDesktopWindow MsgBox "デスクトップのハンドルは" & vbCrLf & Ret Case 3 Ret = GetForegroundWindow MsgBox "現在操作中のウインドウハンドルは" & vbCrLf & Ret Case 4 Ret = GetWindowDC(Form1.hWnd) MsgBox "ウインドウ全体のデバイスコンテキストは" & vbCrLf & Ret Case 5 Ret = SetActiveWindow(Form1.hWnd) End Select End Sub
ソースコード一式のダウンロード
vbapi_otherwindow.zip 1.17 KB (1,202 バイト)
このサンプルの動作環境について
このサンプルは 「Windows98」及び「Microsoft Visual Basic 5.0 Professional Edition」で確認しております。環境が異なる場合は正常に動作しない場合もございますのでご了承下さい。
スポンサーリンク
関連記事
前の記事: | ウインドウを常に手前にする |
次の記事: | ウインドウのタイトルを変更する |
公開日:2015年03月06日
記事NO:00425