日期:2014-05-18  浏览次数:21091 次

C# 调用API创建窗口
有个程序是用C++写的,现在想移植到c#,不知道c#能不能直接通过API来创建窗口

------解决方案--------------------

------解决方案--------------------
使用platform Invoke
参见
ms-help://MS.MSDNQTR.v90.en/dv_fxinterop/html/eca7606e-ebfb-4f47-b8d9-289903fdc045.htm

但是我觉得你是给自己找麻烦。建议使用managed c++,也可以调用net的类库。
------解决方案--------------------
API的调用是没问题的。。不过 C#要先引用对那些APIDLL。
------解决方案--------------------
Enable设置成false?
------解决方案--------------------
最简单的方法就是通过Google搜索。
------解决方案--------------------
C# 调用 API 举例:

C# code
using System; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

class Test : Form 
{ 
  const int MF_BYPOSITION = 0x0400; 
  const int MF_REMOVE     = 0x1000; 

  [DllImport("user32.dll",EntryPoint="GetSystemMenu")] 
  extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert); 

  [DllImport("user32.dll",EntryPoint="RemoveMenu")] 
  extern static int RemoveMenu(IntPtr hMenu, int nPos, int flags); 

  Test() 
  { 
    Text            =  "不能移动和改变大小的窗口"; 
    FormBorderStyle = FormBorderStyle.FixedSingle; 
    MaximizeBox     = false; 
    MinimizeBox     = false; 
    RemoveMenu(GetSystemMenu(Handle,IntPtr.Zero),1,MF_BYPOSITION|MF_REMOVE); 
  } 

  static void Main() 
  { 
    Application.Run(new Test()); 
  } 
}