Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
GeneralRe: writing a struct to a binary file Pin
DennisMetz17-Feb-04 5:06
DennisMetz17-Feb-04 5:06 
GeneralRe: writing a struct to a binary file Pin
Heath Stewart17-Feb-04 6:19
protectorHeath Stewart17-Feb-04 6:19 
Generalcatch tabpage change Pin
troels_sorensen17-Feb-04 3:41
troels_sorensen17-Feb-04 3:41 
GeneralRe: catch tabpage change Pin
Heath Stewart17-Feb-04 4:07
protectorHeath Stewart17-Feb-04 4:07 
GeneralRe: catch tabpage change Pin
Anonymous17-Feb-04 8:44
Anonymous17-Feb-04 8:44 
GeneralRe: catch tabpage change Pin
Heath Stewart17-Feb-04 9:21
protectorHeath Stewart17-Feb-04 9:21 
GeneralRe: catch tabpage change Pin
Anonymous17-Feb-04 10:56
Anonymous17-Feb-04 10:56 
GeneralRe: catch tabpage change Pin
Heath Stewart17-Feb-04 12:14
protectorHeath Stewart17-Feb-04 12:14 
It wouldn't be pointless to define a uint because you can always cast it to an int upon comparing, but I wouldn't recommend it since this method should be fast (it has to process potentially a lot of messages, after all) and the extra instruction to cast (and possibly two more to store and retrieve depending on the code) is too expensive.

Fortunately, I re-read the documentation for TCN_SELCHANGING and noticed that this message is sent in the form of a WM_NOTIFY message to the parent of the TabControl. This little example works:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Test : Form
{
  public static void Main()
  {
    Application.Run(new Test());
  }
  public Test()
  {
    TabControl tab = new TabControl();
    
    this.SuspendLayout();
    this.Text = "Test";
    this.Controls.Add(tab);
	tab.TabPages.Add(new TabPage("Page 1"));
	tab.TabPages.Add(new TabPage("Page 2"));
    tab.Dock = DockStyle.Fill;
    this.ResumeLayout();
  }
  private const int WM_NOTIFY = 0x004e;
  private const int TCN_SELCHANGING = -552;
  private struct NMHDR
  {
    public IntPtr hwndFrom;
    public int idFrom;
    public int code;
  }
  protected override void WndProc(ref Message m)
  {
    base.WndProc(ref m);
    if (m.Msg == WM_NOTIFY)
    {
      NMHDR hdr = (NMHDR)Marshal.PtrToStructure(m.LParam, typeof(NMHDR));
      Console.WriteLine(hdr.code);
      if (hdr.code == TCN_SELCHANGING)
        m.Result = new IntPtr(1);
    }
  }
}
Sorry for the mess. Most messages I deal with are sent directly and aren't WM_NOTIFY style messages. This gets a little quirky. You'll notice I marshal the LPARAM parameter to an NMHDR struct, which I then check the code. Getting to know the notification messages helps, I just feel dumb that I didn't fully read it before.

Also note that I'm calling base.WndProc first. If you don't, Windows is likely to change the Message.Result field to 0 (or reset it to 0). You could also just not call it and return in this case if you get the WM_NOTIFY message with the NMHDR.code set to TCN_SELCHANGING.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: catch tabpage change Pin
Anonymous17-Feb-04 12:59
Anonymous17-Feb-04 12:59 
GeneralRe: catch tabpage change Pin
troels_sorensen18-Feb-04 21:15
troels_sorensen18-Feb-04 21:15 
GeneralRe: catch tabpage change Pin
Heath Stewart19-Feb-04 3:30
protectorHeath Stewart19-Feb-04 3:30 
Generalpictures in a datagrid Pin
troels_sorensen17-Feb-04 3:38
troels_sorensen17-Feb-04 3:38 
GeneralRe: pictures in a datagrid Pin
Heath Stewart17-Feb-04 4:21
protectorHeath Stewart17-Feb-04 4:21 
Questionneed sql query? Pin
murali_utr17-Feb-04 3:19
murali_utr17-Feb-04 3:19 
AnswerRe: need sql query? Pin
Heath Stewart17-Feb-04 4:33
protectorHeath Stewart17-Feb-04 4:33 
Questionwhats wrong? Pin
ASGill17-Feb-04 2:16
ASGill17-Feb-04 2:16 
AnswerRe: whats wrong? Pin
Uwe Keim17-Feb-04 3:01
sitebuilderUwe Keim17-Feb-04 3:01 
AnswerRe: whats wrong? Pin
Heath Stewart17-Feb-04 3:15
protectorHeath Stewart17-Feb-04 3:15 
GeneralCustom ListBox.Items Pin
Simon Wren17-Feb-04 2:11
professionalSimon Wren17-Feb-04 2:11 
GeneralRe: Custom ListBox.Items Pin
Heath Stewart17-Feb-04 4:52
protectorHeath Stewart17-Feb-04 4:52 
GeneralWinForms: SuspendLayout on Application Pin
troels_sorensen17-Feb-04 2:06
troels_sorensen17-Feb-04 2:06 
GeneralRe: WinForms: SuspendLayout on Application Pin
Heath Stewart17-Feb-04 4:54
protectorHeath Stewart17-Feb-04 4:54 
QuestionResize all items? Pin
thomasa17-Feb-04 1:51
thomasa17-Feb-04 1:51 
AnswerRe: Resize all items? Pin
Heath Stewart17-Feb-04 4:57
protectorHeath Stewart17-Feb-04 4:57 
GeneralRe: Resize all items? Pin
je_gonzalez17-Feb-04 17:28
je_gonzalez17-Feb-04 17:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.