2017-03-08 8 views
0

私は独自のカスタムコントロールを作成しましたが、ここではこのカスタムコントロールを他のコントロールのツールヒントに設定します。だから私は追加したコードは、以下のコードを通じてのsendMessageて失敗SendMessageはツールヒントウィンドウを設定できません

public class MyControl : Control 
{ 
    Dictionary<IntPtr, Component> m_tools; 
    TOOLINFO m_toolInfo; 

    public MyControl() 
    { 
     m_tools = new Dictionary<IntPtr, Component>(); 
     m_toolInfo = new TOOLINFO(); 
    } 

    string myTipText; 

    public string MyTipText 
    { 
     get 
     { 
      return myTipText; 
     } 
     set 
     { 
      myTipText = value; 
     } 
    } 

    protected override void OnPaint(PaintEventArgs e) 
    { 
     base.OnPaint(e); 

     SolidBrush brush = new SolidBrush(Color.Blue); 
     e.Graphics.DrawString(this.MyTipText, this.Font, brush, e.ClipRectangle.Location); 
    } 

    internal void AddControl(Component component) 
    { 
     if (component != null) 
     { 
      if (component is Control) 
      { 
       Control control = component as Control; 

       control.HandleCreated += control_HandleCreated; 

       if (control.IsHandleCreated) 
       { 
        control_HandleCreated(control, EventArgs.Empty); 
       } 
      } 

     } 
    } 

    void control_HandleCreated(object sender, EventArgs e) 
    { 
     Control control = sender as Control; 

     if(control!=null) 
     { 
      m_tools[control.Handle] = control; 

      m_toolInfo.hwnd = this.Handle; 
      m_toolInfo.uId = control.Handle; 

      **int result = WindowsAPI.SendMessage(this.Handle, (int)TTM.TTM_ADDTOOLW, 0, ref m_toolInfo);** 
     } 
    } 

} 

しかしのSendMessage結果をツールチップとしてカスタムコントロールを設定します。私は知っている、なぜカスタムコントロールがコントロールのツールチップとして設定されていない。ここで

は、私は失敗の理由を見つけることができなかったのSendMessage、

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError=true)] 
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref TOOLINFO lParam); 

です。誰か助けてください。

よろしく、 アマルラジU.

答えて

0

私はあなたのWNDPROC方法を見ることができませんでした。すべてのメッセージはあなたの住所に送られます。しかし、 "WndProc(ref Message m)"のようなキャスターで、カスタムメッセージのデフォルト送信がない場合、彼らは空を飛んでいます。

TTM.TTM_ADDTOOLW 

これは受信者に送信されるカスタムメッセージです。オーバーライドされたWndProcメソッドを持つコントロールがなければならず、このメソッドはメッセージをキャッチしてそこで処理する必要があります。

私はForm1のからのForm2にメッセージを送った:

`SendMessage(Form2.handle, Msgs.Close, 0, null)` 

をなどのForm2からcatched:おそらくそれはあなたのソリューションをリードすることができる

protected override void WndProc(ref Message m) { 
    if (m.Msg == Msgs.Close) { 
     AskForExit(); 
    } else if (m.Msg == Msgs.Other) { 
     DoOtherStuffOwnedByMe(); 
    } 
     base.WndProc(ref m); 
} 

関連する問題