DTN_DATETIMECHANGE loop!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: DTN_DATETIMECHANGE loop!

Threaded View

  1. #1
    Join Date
    Jul 2009
    Posts
    14

    Angry DTN_DATETIMECHANGE loop!

    hi! I have a date-time picker control.
    when I select a date it gives 2 notify and when I change month I get an endless loop of notify!!!
    here's my code...

    Code:
    #define   STRICT
    
    #include  <windows.h>
    #include  <stdio.h>
    #include  <commctrl.h>
    
    #pragma comment(lib, "comctl32.lib")
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) 
    {
       static SYSTEMTIME st;
       static HWND       hWndStartDate, hWndStartTime;
       static char       szDate[15], szTime[10], szStamp[20];
       NMDATETIMECHANGE  *Date;
       CREATESTRUCT      *cs;
    
       switch (iMsg) 
       {
       case WM_CREATE :
          cs = (LPCREATESTRUCT)lParam;
          GetLocalTime(&st);
          GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &st, "yyyyMMdd", szDate, sizeof(szDate));
          GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &st, "HHmmss", szTime, sizeof(szTime));
    
          hWndStartDate = CreateWindowEx(0, DATETIMEPICK_CLASS, NULL,
             WS_BORDER | WS_CHILD | WS_VISIBLE,
             10, 10, 100, 25,
             hwnd, NULL, cs->hInstance, NULL);
    
          hWndStartTime = CreateWindowEx(0, DATETIMEPICK_CLASS, NULL,
             WS_BORDER | WS_CHILD | WS_VISIBLE | DTS_TIMEFORMAT,
             10, 40, 100, 25,
             hwnd, NULL, cs->hInstance, NULL);
          break;
    
       case WM_NOTIFY :
          switch(((LPNMHDR)lParam)->code)
          {
          case DTN_DATETIMECHANGE :
             Date = (LPNMDATETIMECHANGE)lParam;
             if(Date->nmhdr.hwndFrom == hWndStartDate || Date->nmhdr.hwndFrom == hWndStartTime)
             {
                DateTime_SetRange(hWndStartDate, GDTR_MAX, &st);
                DateTime_SetRange(hWndStartTime, GDTR_MAX, &st);
                MessageBox(NULL , _T("hello"), _T("hello"), MB_OK);
             }
             break;
    
          case DTN_DROPDOWN :
             MonthCal_SetFirstDayOfWeek(DateTime_GetMonthCal(hWndStartDate), 0);
             break;
          }
          break;
    
       case WM_COMMAND :
          if (IDCANCEL == LOWORD(wParam)) 
          {  
             DateTime_GetSystemtime(hWndStartDate, &st);
             DateTime_GetSystemtime(hWndStartTime, &st);
             break;
          }
          break;
    
       case WM_CLOSE :
          DestroyWindow(hwnd);
          break;
    
       case WM_DESTROY :
          PostQuitMessage(0);
          break;
       }
       return DefWindowProc(hwnd, iMsg, wParam, lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 
    {
       MSG                  msg;
       WNDCLASS             wndclass;
       HWND                 hwnd;
       INITCOMMONCONTROLSEX icex;
       char                 szAppName[] = "DatePickerApp";
    
       wndclass.style         = 0;
       wndclass.lpfnWndProc   = WndProc;
       wndclass.cbClsExtra    = 0;
       wndclass.cbWndExtra    = 0;
       wndclass.hInstance     = hInstance;
       wndclass.hIcon         = LoadIcon(hInstance, szAppName);
       wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
       wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
       wndclass.lpszMenuName  = szAppName;
       wndclass.lpszClassName = szAppName;
       RegisterClass(&wndclass);
    
       icex.dwSize = sizeof(icex);
       icex.dwICC = ICC_DATE_CLASSES;
       InitCommonControlsEx(&icex);
    
       hwnd = CreateWindow(szAppName,
          szAppName,
          WS_OVERLAPPEDWINDOW | WS_VISIBLE,
          0, 0, 400, 400,
          NULL, NULL, hInstance, szCmdLine);
    
       while (GetMessage(&msg, NULL, 0, 0)) 
       {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
       }
       return (int)msg.wParam;
    }
    help!!!
    Last edited by EvIl_DeViL; September 9th, 2009 at 03:36 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center