Disable Form Close Button
This code is used to disable the "X" form button (that one top right) in a form
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
Upload
<html>
<head>
<style>
td { font-family: Verdana; font-size: 12px; }
.month { background-color: #2861a6; color: #ffffff; font-weight: bold; }
.day { background-color:#b0c4de; color: #000000; text-align: center; }
</style>
<script>
function changeBG(objRow, sState)
{
var theCell = document.getElementById(objRow);
if (sState == "over")
{ theCell.style.backgroundColor="#1e90ff"; }
else
{ theCell.style.backgroundColor="#b0c4de"; }
}
</script>
<title>PHP Calender System</title>
</head>
<?
if (!$curYear){$curYear=date("Y");}
$cellCount=0;
$mainTableCellCount=0;
echo "<table cellpadding=\"2\" cellspacing=\"2\" align=\"center\">\r";
for ($curMonth=1;$curMonth<=12;$curMonth++)
{
if ($mainTableCellCount == 0) { echo "<tr>\r"; }
echo "<td align=\"center\" valign=\"top\">\r";
$curDay=1;
$thisMonth=$curMonth;
while($curMonth==$thisMonth)
{
$thisMonth=date("m",mktime(23,59,59,$curMonth,$curDay,$curYear));
$totalDays=date("d",mktime(23,59,59,$curMonth,$curDay-1,$curYear));
$curDay++;
}
$monthTextual=date("F",mktime(0,0,0,$curMonth,1,$curYear));
$firstDayOfMonth = date("w",mktime(0,0,0,$curMonth,1,$curYear));
echo "<table cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\" align=\"center\">\r";
echo "<tr><td class=\"month\" colspan=\"7\">$monthTextual - $curYear</td></tr>\r";
if ($firstDayOfMonth > 0) { echo "<tr>\r"; }
for($cellCount=0;$cellCount<=$firstDayOfMonth-1;$cellCount++)
{
echo "<td class=\"day\"> </td>\r";
}
for ($curDay=1;$curDay<=$totalDays;$curDay++)
{
if ($cellCount == 0) { echo "<tr>\r"; }
echo "<td class=\"day\" id=\"$curMonth-$curDay\" onMouseOver=\"changeBG('$curMonth-$curDay','over');\" onMouseOut=\"changeBG('$curMonth-$curDay','out');\">$curDay</td>\r";
$cellCount++;
if ($cellCount == 7) { echo "</tr>\r"; $cellCount=0;}
}
if ($cellCount > 0 && $cellCount < 7)
{
for ($i=$cellCount; $i<7; $i++)
{
echo "<td class=\"day\"> </td>\r";
}
echo "</tr>\r";
}
echo "</table><br>\r";
$mainTableCellCount++;
if ($mainTableCellCount == 3) { echo "</tr>\r"; $mainTableCellCount = 0; }
}
echo "<form action=\"$PHP_SELF\" method=\"GET\">\r";
echo "<select name=\"curYear\">\r";
for($yearOffset=-4;$yearOffset<=4;$yearOffset++)
{
$year = date("Y", mktime(0,0,0,0,0,date("Y")+$yearOffset));
if ($year == $curYear) { $selected = " selected"; } else { $selected = ""; }
echo "<option value=\"$year\"$selected>$year</option>\r";
}
echo "</select>\r";
echo "<input type=\"Submit\" value=\"Submit\">\r";
echo "</form>\r";
?>
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean
'
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const MF_DISABLED = &H2
'
Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
Dim hMenu As IntPtr
Dim menuItemCount As Integer
'
'Obtain the handle to the form's system menu
hMenu = GetSystemMenu(hwnd, False)
'
'Obtain the number of items in the menu
menuItemCount = GetMenuItemCount(hMenu)
'
'Remove the system menu Close menu item.
'The menu item is 0-based, so the last
'item on the menu is menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_DISABLED Or MF_BYPOSITION)
'
'Remove the system menu separator line
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_DISABLED Or MF_BYPOSITION)
'
'Force a redraw of the menu. This
'refreshes the titlebar, dimming the X
Call DrawMenuBar(hwnd)
End Sub
'
'
'------------------- USAGE -------------------
'Put this in the Load Event of a Form
'
DisableCloseButton(Me.Handle)
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine