tags:

views:

247

answers:

4

Hi all! it's a very newbie question but after 3 hours of looking after it i'm done with google-ing for today....i'm using a code i've found and it uses Win32, it's says "The Name 'Win32' does not exists in the current content" - what am i missing? how to call\declare win32?? Thank you all, Amit.

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;
        }
    }
+2  A: 

Those are not defined in the .NET framework. Whoever wrote this code had them defined in another class. They are from the Win32 API which is why they are named Win32. You'll need to search on each of those defines and find out what they should be.

I can tell you that the Win32.WH* are window messages they are just integer values.

Edit: pinvoke.net has a full list of window messages.

shf301
A: 

Yeah, do what David said which you said you already did (pInvoke). Then look at the source you found and look where Win32.WM_PAINT, Win32.WM_HSCROLL, and Win32.WM_VSCROLL are defined. In my experience, these are just defined by hand in the source and are just numbers, to make it easier to read. Of course these numbers correspond to what they're actually defined in the Win32 API, but they're redefined in the source by the programmer to avoid having to use the numbers directly, therefore making it harder to read.

Jorge Israel Peña
+2  A: 

I suspect you have grabbed code that relies on this Win32 helper class.

Adding that to your project should solve the immediate Win32 missing problem.

Andy Dent
yep that really solved the Win32 missing, but now you have missed defenition for the specific functions...i guess i've to search agn over those functions...
Mazki516
A: 

On the other hand, if you want a transparent textbox, why not just reference PresentationCore/PresentationFramework/WindowsFormsIntegration and use this to create a transparent text box:

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 };

then add the host to your container and you're set to go. A lot easier than messing with a bunch of Win32 complexity, and easy to wrap in a custom class.

Why beat your head against WinForms when the functionality is trivial to achieve in WPF? Windows 98, ME, and 2000 now account for about 1% of the market in total. (WPF won't run on any Windows OS below XP)

Ray Burns