using System;
using System.Drawing;
using System.Runtime.InteropServices;namespace Win32
{
public class WinApi
{
#region Constans values
public const string TOOLBARCLASSNAME = "ToolbarWindow32";
public const string REBARCLASSNAME = "ReBarWindow32";
public const string PROGRESSBARCLASSNAME = "msctls_progress32";
#endregion #region CallBacks
public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
#endregion #region Shell32.dll functions
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
#endregion #region Kernel32.dll functions
[DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern int GetCurrentThreadId();
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern int lstrlen(string lpString);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, int wAttributes);
#endregion

#region Gdi32.dll functions
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern bool TextOut(IntPtr hdc, int nXStart, int nYStart, string lpString, int cbString);
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern bool GetTextExtentPoint32(IntPtr hdc, string lpString, int cbString, ref SIZE lpSize);
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern int SetTextColor(IntPtr hdc, int crColor);
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern int SetBkColor(IntPtr hdc, int crColor);
[DllImport("gdi32.dll")]
public static extern bool StretchBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
IntPtr hDCSrc,  int XOriginScr, int YOriginSrc, int WidthScr, int HeightScr, uint Rop);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int Width, int Heigth);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
IntPtr hDCSrc,  int XOriginScr, int YOriginSrc, uint Rop);
[DllImport("gdi32.dll")]
public static extern IntPtr DeleteDC(IntPtr hDC);
[DllImport("gdi32.dll")]
public static extern bool PatBlt(IntPtr hDC, int XLeft, int YLeft, int Width, int Height, uint Rop);
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
[DllImport("gdi32.dll")]
public static extern int SetMapMode(IntPtr hDC, int fnMapMode);
[DllImport("gdi32.dll")]
public static extern int GetObjectType(IntPtr handle);
[DllImport("gdi32")]
public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO_FLAT bmi, 
int iUsage, ref int ppvBits, IntPtr hSection, int dwOffset);
[DllImport("gdi32")]
public static extern int GetDIBits(IntPtr hDC, IntPtr hbm, int StartScan, int ScanLines, int lpBits, BITMAPINFOHEADER bmi, int usage);
[DllImport("gdi32")]
public static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int StartScan, int ScanLines, int lpBits, ref BITMAPINFO_FLAT bmi, int usage);
[DllImport("gdi32")]
public static extern IntPtr GetPaletteEntries(IntPtr hpal, int iStartIndex, int nEntries, byte[] lppe);
[DllImport("gdi32")]
public static extern IntPtr GetSystemPaletteEntries(IntPtr hdc, int iStartIndex, int nEntries, byte[] lppe);
[DllImport("gdi32")]
public static extern uint SetDCBrushColor(IntPtr hdc,  uint crColor);
[DllImport("gdi32")]
public static extern IntPtr CreateSolidBrush(uint crColor);
[DllImport("gdi32")]
public static extern int SetBkMode(IntPtr hDC, BackgroundMode mode);
#endregion #region Uxtheme.dll functions
[DllImport("uxtheme.dll")]
public static extern int SetWindowTheme(IntPtr hWnd, string AppID, string ClassID);
#endregion
}
}

解决方案 »

  1.   

    c#用API还更麻烦,因为默认下C#是受托管代码,而API属于非托管代码,驻转换很麻烦,麻烦程度就具体看你调那个API了这不是一下子说得清的,你可以在MSDN里找一下相关的关键字,如
    DllImport,InteropServices等等下面是声明API的例子,这个是非常简单的
    [DllImport("DogDllAPI.dll",CallingConvention=CallingConvention.Winapi,EntryPoint="ModuleBasicCheck")]
    public static extern int ChannelCheck(short ChannelNo,int Pwd,byte Cascade);
      

  2.   

    回答你前两个问题:1:VS.net 工具箱里有HelpProvider,拖到你的窗口上。
       helpProvider1.HelpNamespace = Application.StartupPath+"\\x.chm";
       helpProvider1.SetShowHelp(this,true);   这样你在窗口中按F1将弹出帮助,如要和菜单关联,在你菜单时间处理方法中:SendKeys.Send("{F1}");2:你应该定义一个MDI窗口类的成员变量,类型就是你的字窗口类。
      然后在菜单处理方法中判断:if(FindWindow(frmData))
    {
    frmData.Activate();
    }
    else
    {
    frmData = new FrmData();
    frmData.MdiParent = this;
    frmData.Show();
    }
    private bool FindWindow(object frm)
    {
    Form[] frmForms = this.MdiChildren;
    int i;
    bool bFound=false;
    for (i=0; i<frmForms.Length; i++)
    {
    if (frmForms[i].Equals(frm))
    {
    bFound=true;
    break;
    }
    }
    if(i == frmForms.Length)
    bFound=false;
    return bFound;
    }
      

  3.   

    只使用一个实例,可以使用singleton模式:
    class FormChild : Form
    {
    protected FormChild(){}private FormChild _child = null;public FormChild Instance
    {
    get
    {
    if( null == _child )
      _child = new FormChild();return _child;
    }
    }
    }
      

  4.   

    1、前2个问题赞同楼上的说法,简洁明了
    2、第三个问题,应该说比VB更难,因为如果涉及到类型转换,要marshal处理的时候头疼
      

  5.   

    http://www.csdn.net/expert/topic/913/913577.xml
      

  6.   


    ------------------------
        I like to teach a fish how to swim.