Skip to content

Instantly share code, notes, and snippets.

Avatar

OHSAWA Masashi Benshi

View GitHub Profile
@Benshi
Benshi / PrivateFontCollection.bas
Last active Nov 10, 2021
[VBA] GDI+ Flat API で System.Drawing.Text.PrivateFontCollection を呼び出す
View PrivateFontCollection.bas
' ThisWorkbook モジュール
Option Explicit
Private Const LF_FACESIZE As Long = 32&
Private Const LANG_NEUTRAL As Integer = 0
Private Const NullPtr As LongPtr = 0
Public m_GDIplusToken As LongPtr
Private Type GdiplusStartupInput
GdiplusVersion As Long
@Benshi
Benshi / ClassLibraryNet5.vb
Last active Nov 8, 2021
[VB] .NET 5 製 COM コンポーネント
View ClassLibraryNet5.vb
'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 / PictureFromClipboard.bas
Last active Oct 4, 2021
[Excel]シート上の画像をフォームに表示
View PictureFromClipboard.bas
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 / FileInfoExtention.vb
Created Aug 12, 2021
[VB] ファイルの占有サイズを取得する
View FileInfoExtention.vb
Option Strict On
Imports System.ComponentModel
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Module FileInfoExtention
''' <summary>
''' ドライブのクラスターサイズを返します。
''' </summary>
@Benshi
Benshi / PDF_to_GIFF.vb
Last active Aug 3, 2021
PDF ファイルを TIFF 画像に変換する
View PDF_to_GIFF.vb
'NuGet で「Microsoft.Windows.SDK.Contracts」を参照しておく
Option Strict On
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Linq
Imports Windows.Data.Pdf
Public Class Form1
Private Const WICTiffEncoder As String = "0131be10-2001-4c5f-a9b0-cc88fab64ce8"
@Benshi
Benshi / RecordingForm.vb
Last active Jul 15, 2021
[VB] NAudio による録音サンプル
View RecordingForm.vb
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)
@Benshi
Benshi / HtmlDocumentHelper.bas
Created May 21, 2021
[VBA]ウィンドウから HTMLDocument オブジェクトを取得する
View HtmlDocumentHelper.bas
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 / SwapMouseButton.bas
Created Mar 23, 2021
マウスの主ボタンと副ボタンを入れ替える (VBA)
View SwapMouseButton.bas
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoW" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#Else
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoW" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#End If
@Benshi
Benshi / TextBoxBaseExtensions.vb
Created Mar 23, 2021
TextChanged イベントを発生させずに TextBox の Text を書き換える
View TextBoxBaseExtensions.vb
Public Module TextBoxBaseExtensions
<System.Runtime.CompilerServices.Extension>
Public Sub SetText(this As TextBoxBase, value As String)
Static forceWindowText As System.Reflection.MethodInfo = GetType(System.Windows.Forms.TextBoxBase).GetMethod("ForceWindowText", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
forceWindowText.Invoke(this, New Object(0) {value})
End Sub
End Module
View ディレクトリのサイズを素早く返す
// >= .NET 5.0
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
public static class DirectoryInfoExtensions
{
/// <summary>
/// ディレクトリのサイズを返します。
/// </summary>