摘要: 窗体的基类:1/**//*=========================================================================2Copyright(C)2008.Allrightsreserved3CLR版本:2.0.50727.14334Createdby王端奎/HOHat2008-05-3118:27:435====================...
阅读全文
posted @
2008-06-01 00:29 HOH 阅读(177) |
评论 (0) |
编辑
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct TokPriv1Luid

{
public int Count;
public long Luid;
public int Attr;
}

[DllImport("kernel32.dll", ExactSpelling = true)]
internal static extern IntPtr GetCurrentProcess();

[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

[DllImport("advapi32.dll", SetLastError = true)]
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool ExitWindowsEx(int DoFlag, int rea);

internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;

private static bool DoExitWin(int DoFlag)

{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
ok = ExitWindowsEx(DoFlag, 0);
return ok;
}


/**//// <summary>
/// 重新启动
/// </summary>
public static bool Reboot()

{
return DoExitWin(EWX_FORCE | EWX_REBOOT);
}


/**//// <summary>
/// 关机
/// </summary>
public static bool PowerOff()

{
return DoExitWin(EWX_FORCE | EWX_POWEROFF);
}


/**//// <summary>
/// 注销
/// </summary>
public static bool LogOff()

{
return DoExitWin(EWX_FORCE | EWX_LOGOFF);
}
posted @
2007-07-02 17:53 HOH 阅读(217) |
评论 (0) |
编辑
摘要: .NET自带的ComboBox控件没有添加图片的功能,我们可以自己进行扩展,下面就是扩展类的代码:ComboBoxEx.csusingSystem;usingSystem.Windows.Forms;usingSystem.Windows.Forms.Design;usingSystem.Drawing;namespaceMengxianhui.ComboBoxEx{classComboBoxEx...
阅读全文
posted @
2007-07-02 17:51 HOH 阅读(266) |
评论 (0) |
编辑
摘要: 以下代码拷贝后可以直接运行1usingSystem;2usingSystem.Drawing;3usingSystem.Collections;4usingSystem.ComponentModel;5usingSystem.Windows.Forms;6usingSystem.Data;78namespaceWindowsApplication429{10/**////<summary&g...
阅读全文
posted @
2007-07-02 17:47 HOH 阅读(569) |
评论 (0) |
编辑
插入排序
插入排序的核心思想是维持第I个元素左边的一组元素是有序的。
1
private void CR(double[] list)
2
{
3
for(int i=1;i<list.Length;i++)
4
{
5
double t=list[i];
6
int j=i;
7
while((j>0)&&(list[j-1]>t))
8
{
9
list[j]=list[j-1];
10
--j;
11
}
12
list[j]=t;
13
}
14
}
posted @
2007-07-02 16:47 HOH 阅读(55) |
评论 (0) |
编辑
选择排序
选择排序 的核心是每遍历一次集合,只记录下最大元素或者最小元素的位置,然后根据你的需要把这个最大或者最小元素的位置跟第一个或者第二个元素进行交换,第二次遍历就从第二个元素开始,直到最后一个元素结束。如下:
1
2
private void XZ(double[] array)
3
{
4
double y;//中转值
5
for(int i=0;i<array.Length;i++)
6
{
7
int x = i ;//用来记录最小数的位置
8
for(int j=i;j<array.Length;j++)
9
{
10
if(array[x]>array[j])
11
{
12
x = j;
13
}
14
if(j == array.Length-1)
15
{
16
y = array[i];
17
array[i] = array[x];
18
array[x] = y;
19
}
20
}
21
}
22
}
posted @
2007-07-02 13:58 HOH 阅读(56) |
评论 (0) |
编辑