C# Win32没有';不存在-我如何声明或引用它?

C# Win32没有';不存在-我如何声明或引用它?,c#,winapi,C#,Winapi,我正在尝试使用我发现的使用Win32的代码。但是,我遇到了以下错误: 当前上下文中不存在名称“Win32” 我错过了什么?如何调用/声明Win32 public class TransparentTextBox : TextBox { PictureBox pictureBox = new PictureBox(); public TransparentTextBox() { pictureBox.Dock = DockStyle.Fill;

我正在尝试使用我发现的使用Win32的代码。但是,我遇到了以下错误:

当前上下文中不存在名称“Win32”

我错过了什么?如何调用/声明Win32

public class TransparentTextBox : TextBox
{
    PictureBox pictureBox = new PictureBox();
    public TransparentTextBox()
    {
        pictureBox.Dock = DockStyle.Fill;
        this.Controls.Add(pictureBox);
    }
    protected override void WndProc(ref Message m)
    {

        base.WndProc(ref m);
        switch (m.Msg)
        {
            case Win32.WM_PAINT:

                Bitmap bmpCaptured =
                  new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
                Bitmap bmpResult =
                  new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
                Rectangle r =
                  new Rectangle(0, 0, this.ClientRectangle.Width,
                  this.ClientRectangle.Height);

                CaptureWindow(this, ref bmpCaptured);
                this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
                this.BackColor = Color.Transparent;

                ImageAttributes imgAttrib = new ImageAttributes();

                ColorMap[] colorMap = new ColorMap[1];

                colorMap[0] = new ColorMap();

                colorMap[0].OldColor = Color.White;

                colorMap[0].NewColor = Color.Transparent;

                imgAttrib.SetRemapTable(colorMap);

                Graphics g = Graphics.FromImage(bmpResult);

                g.DrawImage(bmpCaptured, r, 0, 0, this.ClientRectangle.Width,
                    this.ClientRectangle.Height, GraphicsUnit.Pixel, imgAttrib);

                g.Dispose();

                pictureBox.Image = (Image)bmpResult.Clone();
                break;


            case Win32.WM_HSCROLL:

            case Win32.WM_VSCROLL:

                this.Invalidate(); // repaint

                // if you use scrolling then add these two case statements


                break;
        }
    }

这些未在.NET framework中定义。编写此代码的人在另一个类中定义了它们。它们来自Win32 API,这就是它们被命名为Win32的原因。您需要搜索这些定义中的每一个,并找出它们应该是什么

我可以告诉你Win32.WH*是窗口消息,它们只是整数值


编辑:有一个完整的列表。

是的,照大卫说的做,你说你已经做了(平沃克)。然后查看您找到的源代码,并查看定义了Win32.WM_PAINT、Win32.WM_HSCROLL和Win32.WM_VSCROLL的位置。根据我的经验,这些只是在源代码中手工定义的,只是数字,以便于阅读。当然,这些数字与Win32 API中实际定义的数字相对应,但是程序员在源代码中重新定义了这些数字,以避免直接使用这些数字,因此更难阅读。

我怀疑您获取了依赖这些数字的代码


将其添加到您的项目中应该可以立即解决Win32缺失的问题。

另一方面,如果您想要一个透明的文本框,为什么不直接引用PresentationCore/PresentationFramework/WindowsFormsIntegration并使用它来创建一个透明的文本框:

using WPFTextBox = System.Windows.Controls.TextBox;
using WPFBrushes = System.Windows.Media.Brushes;
using WPFElementHost = System.Windows.Forms.Integration;

...

var textBox = new WPFTextBox { Background = WPFBrushes.Transparent };
var host = new WPFElementHost { Dock = DockStyle.Fill, Child = textBox };
然后将主机添加到容器中,就可以开始了。这比处理一堆Win32复杂度要容易得多,并且易于封装在自定义类中


当WinForms在WPF中实现的功能微不足道时,为什么还要与WinForms较量呢?Windows 98、ME和2000现在占市场的1%左右。(WPF不会在XP以下的任何Windows操作系统上运行)

编辑您的问题并添加代码我删除了我的答案,因为它在这里没有用处。我也不太可能找到有用的东西。是的,这确实解决了Win32缺失的问题,但现在你已经错过了特定函数的防御功能…我想我必须在这些函数上搜索agn。。。