Calender Control

This is a discussion on Calender Control within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to use the month calender box in a dialog box. When I use MCN_SELECT and try to retrieve ...

  1. #1
    iglod
    Guest

    Calender Control

    I'm trying to use the month calender box in a dialog box. When I use MCN_SELECT and try to retrieve data with GetDay(),GetMonth() and GetYear() the day is of by 14 days and the month is of by 2. The year seems to be ok. My code looks like this.
    void CGuiDlg::OnSelectMonthcalendarStart(NMHDR* pNMHDR, LRESULT* pResult)
    {
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);

    int oldDay,oldMonth,oldYear;
    oldDay=m_calendarStart.GetDay();
    oldMonth=m_calendarStart.GetMonth();
    oldYear=m_calendarStart.GetYear();

    Bla , bla ,bla ..........
    *pResult = 0;
    }

    Iím stumped any help would be great

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i don't know if this will help but heres the code from the calander on CP.com's site.

    Code:
    /*This program prints a calendar for a year specified. The user enters a
    
         year for the calendar and the programs automatically prints the calendar
    
         in text format.
    
    
    
         The codes are: day_code (0 = Sun, 1 = Mon, etc.)
    
                        leap_year (0 = no leap year, 1 = leap year)   */
    
    
    
    #include <stdio.h>
    
    #include <stdlib.h>       
    
    
    
    #define TRUE 1
    
    #define FALSE 0
    
    
    
    int get_day_code (int year);
    
    int get_leap_year (int year);
    
    void print_calendar (FILE *fout, int year, int day_code, int leap_year);
    
    int get_year (void);
    
    
    
    main()
    
    {
    
       
    
       int year, day_code, leap_year; 
    
       
    
       FILE *fout;
    
       
    
       fout = fopen ("calendar.txt", "w");
    
       
    
       year = get_year();                           
    
       
    
       day_code = get_day_code (year);
    
       
    
       leap_year = get_leap_year (year);
    
       
    
       print_calendar(fout, year, day_code, leap_year);
    
       
    
       printf("Open up \'calendar.txt\' to see your calendar...\n");
    
       
    
       system("pause");
    
         
    
    }
    
         
    
    int get_year (void)
    
    {
    
    
    
    int year;
    
    printf ("Enter a year: ");
    
    scanf ("%d", &year);
    
    return year;
    
    
    
    }             
    
    
    
    int get_day_code (int year)
    
    {
    
    
    
    int day_code;
    
    int x1, x2, x3;
    
    	x1 = (year - 1.)/ 4.0;
    
    	x2 = (year - 1.)/ 100.;
    
    	x3 = (year - 1.)/ 400.;
    
    day_code = (year + x1 - x2 + x3) %7;
    
    
    
    return day_code;
    
    
    
    }             
    
    
    
    int get_leap_year (int year)
    
    {
    
    	
    
    //if((year% 4) == 0 );
    
    if(year% 4==0 && year%100 != 0 || year%400==0)
    
       return TRUE;
    
       else return FALSE;	
    
    		
    
    }
    
    
    
    void print_calendar (FILE *fout, int year, int day_code, int leap_year) //function header
    
    {
    
    
    
    	int  days_in_month,     /* number of days in month currently 
    
                                                         being printed */
    
             day,       /* counter for day of month */
    
             month;     /* month = 1 is Jan, month = 2 is Feb, etc. */
    
    
    
         fprintf (fout,"                   %d", year);
    
    
    
         for ( month = 1; month <= 12; month++ ) {
    
              switch ( month ) { /* print name and set days_in_month */
    
              case 1:
    
                   fprintf(fout,"\n\nJanuary" );
    
                   days_in_month = 31;
    
                   break;
    
              case 2:
    
                   fprintf(fout,"\n\nFebruary" );
    
                   days_in_month = leap_year ? 29 : 28;
    
                   break;
    
              case 3:
    
                   fprintf(fout, "\n\nMarch" );
    
                   days_in_month = 31;
    
                   break;
    
              case 4:
    
                   fprintf(fout,"\n\nApril" );
    
                   days_in_month = 30;
    
                   break;
    
              case 5:
    
                   fprintf(fout,"\n\nMay" );
    
                   days_in_month = 31;
    
                   break;
    
              case 6:
    
                   fprintf(fout,"\n\nJune" );
    
                   days_in_month = 30;
    
                   break;
    
              case 7:
    
                   fprintf(fout,"\n\nJuly" );
    
                   days_in_month = 31;
    
                   break;
    
              case 8:
    
                   fprintf(fout,"\n\nAugust" );
    
                   days_in_month = 31;
    
                   break;
    
              case 9:
    
                   fprintf(fout,"\n\nSeptember" );
    
                   days_in_month = 30;
    
                   break;
    
              case 10:
    
                   fprintf(fout,"\n\nOctober" );
    
                   days_in_month = 31;
    
                   break;
    
              case 11:
    
                   fprintf(fout,"\n\nNovember" );
    
                   days_in_month = 30;
    
                   break;
    
              case 12:
    
                   fprintf(fout,"\n\nDecember" );
    
                   days_in_month = 31;
    
                   break;
    
              }
    
    
    
              fprintf(fout,"\n\nSun  Mon  Tue  Wed  Thu  Fri  Sat\n" );
    
    
    
              /* advance printer to correct position for first date */
    
              for ( day = 1; day <= 1 + day_code * 5; day++ )
    
                   fprintf(fout," " );
    
    
    
              /* print the dates for one month */
    
              for ( day = 1; day <= days_in_month; day++ ) {
    
                   fprintf(fout,"%2d", day );
    
                   if ( ( day + day_code ) % 7 > 0 ) /* before Sat? */
    
                        /* move to next day in same week */
    
                        fprintf(fout,"   " );
    
                   else  /* skip to next line to start with Sun */
    
                        fprintf(fout, "\n " );
    
              }
    
    
    
              /* set day_code for next month to begin */
    
              day_code = ( day_code + days_in_month ) % 7;
    		  }
    		  }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 12:56 PM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 08:55 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21