'APIの宣言(ハンドル部分のlong型を IntPtr に書き直してあります) Public Declare Function GetSystemMenu Lib "user32.dll" _ Alias "GetSystemMenu" (ByVal hwnd As IntPtr, _ ByVal bRevert As Long) As IntPtr
Public Declare Function RemoveMenu Lib "user32.dll" _ Alias "RemoveMenu" (ByVal hMenu As IntPtr, _ ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Const SC_CLOSE As Long = &HF060 Public Const MF_BYCOMMAND As Long = &H0
Dim infEndflg As Integer
Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load
'ウィンドウハンドルもともにメニューを無効化 Dim lngH As IntPtr lngH = GetSystemMenu(Me.Handle, 0) RemoveMenu(lngH, SC_CLOSE, MF_BYCOMMAND)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click
'アプリケーションの終了ボタンによる制御 infEndflg = True Me.Close()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, _ ByVal e As System.ComponentModel.CancelEventArgs) _ Handles MyBase.Closing 'フォームが閉じられるときにチェック If Not infEndflg Then e.Cancel = True End Sub