روش نادرست اعمال دسترسی کاربر به منوها و کنترلهای فرم در windows form ها
نویسنده: رحمت اله رضایی
تاریخ: ۱۳۹۱/۰۴/۲۵ ۰:۴۱
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public class HackWindowsForms
{
struct POINTAPI
{
public int X;
public int Y;
}
[DllImport("user32.dll")]
static extern int EnumChildWindows(int hWndParent, EnumChildCallbackDelegate enumChildCallback, int lParam);
[DllImport("user32.dll")]
static extern int EnableWindow(int hwnd, int fEnable);
[DllImport("user32.dll")]
static extern int WindowFromPoint(int x, int y);
[DllImport("user32.dll")]
static unsafe extern int GetCursorPos(POINTAPI* lpPoint);
delegate int EnumChildCallbackDelegate(int hwnd, int lParam);
public static void EnableThisWindowControls()
{
unsafe
{
POINTAPI cursorPosition = new POINTAPI();
GetCursorPos(&cursorPosition);
int winWnd = WindowFromPoint(cursorPosition.X, cursorPosition.Y);
EnumChildWindows(winWnd, EnumChildCallback, 0);
}
}
static int EnumChildCallback(int hwnd, int lParam)
{
EnableWindow(hwnd, 1);
EnumChildWindows(hwnd, EnumChildCallback, 0);
return 1;
}
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
HackWindowsForms.EnableThisWindowControls();
MessageBox.Show("حالا روی دکمه مورد نظر کلیک کنید و کلید space را فشار دهید.", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
}