Skip to content

Instantly share code, notes, and snippets.

View Benshi's full-sized avatar

OHSAWA Masashi Benshi

  • Toukei Computer, Co.,Ltd.
  • TOKYO, Japan
  • 12:57 (UTC +09:00)
  • X @Benshi_Orator
View GitHub Profile
@Benshi
Benshi / Program.vb
Last active March 15, 2023 12:50
[C#] .NET 6 で、GetActiveObject を使って VS/Access/Word/Excel/PowerPoint で開いているドキュメントのパスを得る
// this code for .NET 6
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
if (OperatingSystem.IsWindows())
{
// VS2022=17.0, VS2019=16.0, VS2017=15.0, VS2015=14.0, VS2013=12.0, VS2012=11.0, VS2010=10.0, VS2008=9.0, VS2005=8.0, VS2003=7.1, VS2002=7
foreach (var v in new []{ "", ".17.0", ".16.0", ".15.0", ".14.0", ".12.0", "11.0", ".10.0", ".9.0"})
{
@Benshi
Benshi / Form1.vb
Last active January 31, 2023 12:36
[VB]UIAutomation によるブラウザのリロード処理
'Form に Button1, Button2 および ListView を貼って実行します
'
'下記のアセンブリを参照設定する必要があります
' UIAutomationClient
' UIAutomationType
'
'⚠ このコードを Visual Studio からデバッグ実行する場合には
'[デバッグ] - [ウィンドウ] - [例外設定] から
' [Managed Debugging Assistants] - [NonComVisibleBaseClass]
'のチェックを Off にしておく必要があります
@Benshi
Benshi / TreeViewEx.vb
Created January 25, 2023 08:58
[VB][WinForms] TreeView に Scroll イベントを追加する
Option Strict On
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
'<DefaultEvent(NameOf(TreeViewEx.Scroll))>
<DefaultEvent("Scroll")>
Public Class TreeViewEx
Inherits TreeView
@Benshi
Benshi / UserForm1.frm
Last active January 2, 2023 20:51
[VBA] UIAutomation の階層を列挙する
Option Explicit
'
' Excel VBA 向けのサンプル
' 下記の参照設定が必要です
' Microsoft Scripting Runtime (scrrun.dll)
' UIAutomationClient (UIAutomationCore.dll)
'
' UserForm1 に、下記のコントロールが必要です
' CommandButton1
' OptionButton1 , OptionButton2 , OptionButton3
@Benshi
Benshi / wankuma95803.vb
Last active September 29, 2022 00:03
わんくま掲示板 No95803 : 起動済みのエクスプローラーで開かれているフォルダー内のファイルを選択状態にする
Option Explicit On
Option Strict On
Imports SHDocVw '参照設定(COM):Microsoft Internet Controls
Imports Shell32 '参照設定(COM):Microsoft Shell Controls And Automation
'Imports mshtml '参照設定(COM):Microsoft HTML Object Library
Imports System.IO
Imports System.Runtime.InteropServices
'コントロールを 2 つ貼っておく
' Button1
@Benshi
Benshi / HtmlDocumentHelper.bas
Created May 21, 2021 05:09
[VBA]ウィンドウから HTMLDocument オブジェクトを取得する
Option Explicit
Private Declare PtrSafe Function CLSIDFromString Lib "ole32" (ByVal pString As LongPtr, ByRef pCLSID As Currency) As Long
Private Declare PtrSafe Function RegisterWindowMessageW Lib "user32" (ByVal lpString As LongPtr) As Long
Private Declare PtrSafe Function SendMessageTimeoutW Lib "user32" (ByVal hWnd As LongPtr, ByVal msg As Long, ByVal wParam As LongPtr, ByRef lParam As LongPtr, ByVal fuFlags As Long, ByVal uTimeout As Long, ByRef lpdwResult As Long) As LongPtr
Private Declare PtrSafe Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, ByRef riid As Currency, ByVal wParam As LongPtr, ppvObject As Any) As Long
Private Enum SMTO
NORMAL = 0
BLOCK = 1
ABORTIFHUNG = 2
@Benshi
Benshi / PictureFromClipboard.bas
Last active January 15, 2022 00:50
[Excel]シート上の画像をフォームに表示
Option Explicit
Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As LongPtr
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32" (ByRef lpPictDesc As PICTDESC_BITMAP, ByRef RefIID As Any, ByVal fPictureOwnsHandle As Long, ByRef IPic As IPicture) As Long
Private Const PtrNull As LongPtr = 0
Private Type PICTDESC_BITMAP
cbSizeofStruct As Long
@Benshi
Benshi / ClassLibraryNet5.vb
Last active November 8, 2021 07:22
[VB] .NET 5 製 COM コンポーネント
'Guid は固有の値を指定する必要があります
Imports System.Runtime.InteropServices
Imports System.Net.Http
Imports System.Text
<ComVisible(True)>
<CoClass(GetType(ClassLibraryNet5))>
<Guid("E001C99F-F4BC-4A40-8C4C-3CF4D8E701EE")>
<InterfaceType(ComInterfaceType.InterfaceIsDual)>
Public Interface IClassLibraryNet5
@Benshi
Benshi / FileInfoExtention.vb
Created August 12, 2021 06:22
[VB] ファイルの占有サイズを取得する
Option Strict On
Imports System.ComponentModel
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Module FileInfoExtention
''' <summary>
''' ドライブのクラスターサイズを返します。
''' </summary>
@Benshi
Benshi / RecordingForm.vb
Last active July 15, 2021 00:13
[VB] NAudio による録音サンプル
Partial Public Class RecordingForm
Inherits System.Windows.Forms.Form
Private recordingData As System.IO.MemoryStream '録音データ
' NuGet で NAudio パッケージを組み込んでおくこと
Private WithEvents waveIn As NAudio.Wave.WaveInEvent
Private writer As System.IO.Stream
Private Sub waveIn_DataAvailable(sender As Object, e As NAudio.Wave.WaveInEventArgs) Handles waveIn.DataAvailable
writer?.Write(e.Buffer, 0, e.BytesRecorded)