Click here to Skip to main content
15,890,043 members
Home / Discussions / C#
   

C#

 
GeneralRe: Avoiding open/save diaolg box Pin
Heath Stewart25-Feb-05 5:14
protectorHeath Stewart25-Feb-05 5:14 
GeneralRe: Avoiding open/save diaolg box Pin
Heath Stewart23-Feb-05 12:48
protectorHeath Stewart23-Feb-05 12:48 
QuestionCreating new objects at runtime?? Pin
Besinci23-Feb-05 7:12
Besinci23-Feb-05 7:12 
AnswerRe: Creating new objects at runtime?? Pin
Nick Parker23-Feb-05 7:45
protectorNick Parker23-Feb-05 7:45 
GeneralRe: Creating new objects at runtime?? Pin
Besinci23-Feb-05 7:56
Besinci23-Feb-05 7:56 
Generalbarcode check digit Pin
sardonicus23-Feb-05 7:07
sardonicus23-Feb-05 7:07 
GeneralProblems porting an API call from VB6 to C# Pin
smithriver23-Feb-05 7:00
smithriver23-Feb-05 7:00 
GeneralRe: Problems porting an API call from VB6 to C# Pin
Heath Stewart23-Feb-05 12:37
protectorHeath Stewart23-Feb-05 12:37 
In you're code you're not using the MonthCalendar control's Handle like you are in your VB6 code. You must get the handle to the calendar first:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
class DTPSample : Form
{
  DateTimePickerEx dtp;
 
  [STAThread]
  static void Main()
  {
    Application.Run(new DTPSample());
  }
 
  DTPSample()
  {
    dtp = new DateTimePickerEx();
    Controls.Add(dtp);
    dtp.FirstDayOfWeek = DayOfWeek.Monday;
    dtp.Location = new Point(8, 8);
 
    Text = "DTP Sample";
  }
}
 
public class DateTimePickerEx : DateTimePicker
{
  const int DTM_GETMONTHCAL = 0x1008;
  const int MCM_SETFIRSTDAYOFWEEK = 0x100f;
  DayOfWeek firstDayOfWeek;
 
  [DllImport("user32.dll", CharSet=CharSet.Auto)]
  static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam,
    IntPtr lParam);
 
  public DateTimePickerEx()
  {
  }
 
  /// <summary>Gets a handle to the month calendar when displayed.</summary>
  public IntPtr MonthCalendar
  {
    get
    {
      if (IsHandleCreated)
      {
        return SendMessage(Handle, DTM_GETMONTHCAL,
          IntPtr.Zero, IntPtr.Zero);
      }
 
      return IntPtr.Zero;
    }
  }
 
  [DefaultValue(DayOfWeek.Sunday)]
  public DayOfWeek FirstDayOfWeek
  {
    get { return firstDayOfWeek; }
    set
    {
      bool fireEvent = firstDayOfWeek != value;
      firstDayOfWeek = value;
      if (fireEvent)
        OnFirstDayOfWeekChanged(EventArgs.Empty);
    }
  }
 
  public event EventHandler FirstDayOfWeekChanged;
 
  protected virtual void OnFirstDayOfWeekChanged(EventArgs e)
  {
    if (FirstDayOfWeekChanged != null)
      FirstDayOfWeekChanged(this, e);
  }
 
  protected override void OnDropDown(EventArgs e)
  {
    base.OnDropDown(e);
 
    if (MonthCalendar != IntPtr.Zero)
    {
      SendMessage(MonthCalendar, MCM_SETFIRSTDAYOFWEEK, IntPtr.Zero,
        new IntPtr(firstDayOfWeek == DayOfWeek.Sunday ? 6 :
          (int)firstDayOfWeek - 1));
    }
  }
}
Also notice how I declare SendMessage using CharSet=CharSet.Auto in the DllImportAttribute. This will append "A" and "W" for the appropriate functions when necessary. This helps to produce robust assemblies. Declaring the parameters as the correct type - in this case, both wParam and lParam are actually IntPtrs - also helps. An IntPtr is the width of a pointer on the underlying platform.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: Problems porting an API call from VB6 to C# Pin
smithriver24-Feb-05 8:15
smithriver24-Feb-05 8:15 
Generalprinting in textbox of a form from other form Pin
maheshfour23-Feb-05 5:56
maheshfour23-Feb-05 5:56 
GeneralRe: printing in textbox of a form from other form Pin
S. Senthil Kumar23-Feb-05 6:57
S. Senthil Kumar23-Feb-05 6:57 
GeneralRe: printing in textbox of a form from other form Pin
maheshfour23-Feb-05 7:56
maheshfour23-Feb-05 7:56 
GeneralRe: printing in textbox of a form from other form Pin
Anonymous23-Feb-05 8:53
Anonymous23-Feb-05 8:53 
QuestionHow to make expanded attribute in property grid field editable Pin
lee meng23-Feb-05 5:48
lee meng23-Feb-05 5:48 
QuestionWhat is the simple way to use a C# dll in VC++ Pin
yyf23-Feb-05 5:18
yyf23-Feb-05 5:18 
AnswerRe: What is the simple way to use a C# dll in VC++ Pin
Judah Gabriel Himango23-Feb-05 9:49
sponsorJudah Gabriel Himango23-Feb-05 9:49 
AnswerRe: What is the simple way to use a C# dll in VC++ Pin
Dave Kreskowiak24-Feb-05 3:24
mveDave Kreskowiak24-Feb-05 3:24 
GeneralCounting set bits Pin
PaleyX23-Feb-05 5:12
PaleyX23-Feb-05 5:12 
GeneralRe: Counting set bits Pin
Philip Fitzsimons23-Feb-05 6:33
Philip Fitzsimons23-Feb-05 6:33 
GeneralRe: Counting set bits Pin
PaleyX23-Feb-05 6:51
PaleyX23-Feb-05 6:51 
GeneralRe: Counting set bits Pin
Philip Fitzsimons23-Feb-05 6:59
Philip Fitzsimons23-Feb-05 6:59 
GeneralRe: Counting set bits Pin
PaleyX23-Feb-05 7:10
PaleyX23-Feb-05 7:10 
GeneralRe: Counting set bits Pin
Philip Fitzsimons23-Feb-05 7:15
Philip Fitzsimons23-Feb-05 7:15 
GeneralRe: Counting set bits Pin
PaleyX23-Feb-05 7:26
PaleyX23-Feb-05 7:26 
GeneralRe: Counting set bits Pin
Sebastian Schneider25-Feb-05 2:34
Sebastian Schneider25-Feb-05 2:34 

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.