منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
لعمل Enable و Disable لزر X في الفورم - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : الأقسام التعليمية - المنتدى القديم (http://vb4arb.com/vb/forumdisplay.php?fid=90)
+--- قسم : مكتبة أكواد المنتدى (http://vb4arb.com/vb/forumdisplay.php?fid=111)
+---- قسم : مكتبة أكواد الفيجوال بيسك 6 (http://vb4arb.com/vb/forumdisplay.php?fid=116)
+---- الموضوع : لعمل Enable و Disable لزر X في الفورم (/showthread.php?tid=5890)



لعمل Enable و Disable لزر X في الفورم - RaggiTech - 17-10-12

كاتب الموضوع : AhmedEssawy

في قسم التصريحات :


كود :
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd _
As Long, ByVal bRevert As Boolean) As Long

Private Declare Function GetMenuItemCount Lib "user32" (ByVal _
hMenu As Long) As Long

Private Declare Function RemoveMenu Lib "user32" (ByVal _
hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) _
As Long

Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Const MF_REMOVE = &H1000&
وللقيام بهذه المهمة نستدعي الدالة التالية :


كود :
Public Sub DisableClose(frm As Form, Optional _
Disable As Boolean = True)
'Setting Disable to False disables the 'X',
'otherwise, it's reset
Dim hMenu As Long
Dim nCount As Long

If Disable Then
hMenu = GetSystemMenu(frm.hwnd, False)
nCount = GetMenuItemCount(hMenu)

Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or _
MF_BYPOSITION)
Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or _
MF_BYPOSITION)

DrawMenuBar frm.hwnd
Else
GetSystemMenu frm.hwnd, True

DrawMenuBar frm.hwnd
End If
End Sub