2009-11-08 3 views
2

Win32를 사용하는 코드를 사용하려고합니다. 그러나이 오류가 발생합니다 :Win32가 존재하지 않습니다. 어떻게 선언하거나 참조 할 수 있습니까?

The Name 'Win32' does not exist in the current context.

무엇이 누락 되었습니까? 어떻게 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; 
     } 
    } 
+1

질문 편집 및 해당 코드 추가 – Davorin

+0

여기에서 유용하지 않으므로 답변을 삭제했습니다. 나는 많은 도움이되는 행운을 얻지 못하고있다. – David

답변

4

이들은 .NET Framework에서 정의되지 않습니다. 이 코드를 작성한 사람은 다른 클래스에 정의되어 있습니다. 그것들은 Win32 API에서 왔으며, Win32 API는 Win32라는 이름을 가진 이유입니다. 당신은 각각의 정의를 검색하고 그들이 무엇을해야 하는지를 알아야 할 것입니다.

Win32.WH *는 윈도우 메시지이며 정수 값이라고 말할 수 있습니다.

편집 : pinvoke.net에는 window messages의 전체 목록이 있습니다.

0

그래, 다윗이 네가 이미 말한대로해라. (pInvoke) 그래. 그런 다음 발견 한 소스를보고 Win32.WM_PAINT, Win32.WM_HSCROLLWin32.WM_VSCROLL이 정의 된 곳을 찾습니다. 내 경험에 비추어 볼 때, 이들은 소스에서 손으로 정의한 것일뿐 읽기 쉽도록 숫자입니다. 물론이 숫자는 Win32 API에서 실제로 정의 된 것과 일치하지만 숫자를 직접 사용하지 않아도되므로 프로그래머가 소스에서 다시 정의하므로 읽는 것이 더 어려워집니다.

3

나는 this Win32 helper class에 의존하는 코드를 붙잡은 것으로 의심됩니다.

프로젝트에 추가하면 바로 Win32가 누락 된 문제를 해결할 수 있습니다. 당신이 투명 텍스트 상자를 원하는 경우

한편
+0

실제로 Win32가 빠진 것이 해결되었지만, 이제는 특정 기능에 대한 방어력을 잃어 버렸습니다 ... 나는 그 함수들 이상으로 검색해야한다고 생각합니다 ... – Mazki516

0

, 왜 단지 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 복잡성을 망쳐 놓는 것보다 쉽고 사용자 정의 클래스에서 쉽게 래핑 할 수 있습니다.

WPF에서 달성하기가 쉬운 기능이 없을 때 왜 WinForms에 맞설 수 있습니까? Windows 98, ME 및 2000은 현재 전체 시장의 약 1 %를 차지합니다. (WPF는 XP 이하의 모든 Windows OS에서 실행되지 않습니다)

관련 문제