Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does my object exist? So why its HWND doesn't exist? That's a question... (CMonthCalCtrl control)

Reply
Thread Tools

Does my object exist? So why its HWND doesn't exist? That's a question... (CMonthCalCtrl control)

 
 
LT
Guest
Posts: n/a
 
      07-25-2004
Hello,
I have the following problem. I'm using the CMonthCalCtrl calendar
control. I need to emphasize some of days, so I'm handling the
MCN_GETDAYSTATE event. The problem is when my handler function is
called for the first time during initializing of the application. When
I'm calling the CMonthCalCtrl::GetMonthRange method there is an
assertion error inside that method: ASSERT(::IsWindow(m_hWnd));
It seems that my event handler is called before creating a window
handle of the calendar control (when after initializing, there is no
error).
To solve this problem I would call my event handler
OnMcnGetdaystateMonthcalendar2(NMHDR *pNMHDR, LRESULT *pResult) by
hand after the initialization but I don't know what to write as
parameters pNMHDR, pResult. Besides, I don't know if that idea is
appropriate or not.


Has anybody any idea? Maybe although something about how MFC controls
are initialized (I'm newbie in VC++)

There is a bit of code:

void CqweDlg::OnMcnGetdaystateMonthcalendar2(NMHDR *pNMHDR, LRESULT
*pResult)
{
LPNMDAYSTATE pDayState = reinterpret_cast<LPNMDAYSTATE>(pNMHDR);

SYSTEMTIME timeFrom;
SYSTEMTIME timeUntil;
SYSTEMTIME timeDay;
timeDay.wDay = 28;
timeDay.wMonth = 7;
timeDay.wYear = 2004;

nCount = Calendar.GetMonthRange(&timeFrom, &timeUntil,
GMR_DAYSTATE);//inside this line there is an assertion error!!!
memset(states,0x00, sizeof(MONTHDAYSTATE)*nCount);
int iDay, iFrom, iUntil;
iDay = timeDay.wYear * 10000 + timeDay.wMonth * 100 + timeDay.wDay;
iFrom = timeFrom.wYear * 10000 + timeFrom.wMonth * 100 +
timeFrom.wDay;
iUntil = timeUntil.wYear * 10000 + timeUntil.wMonth * 100 +
timeUntil.wDay;
if ( iDay >= iFrom && iDay <= iUntil )
{
int index = timeDay.wMonth - timeFrom.wMonth;
if (index<0) index+=12;
states[index] |= 1<< (timeDay.wDay - 1);//emphasize
}

memcpy(pDayState->prgDayState, states,
nCount*sizeof(MONTHDAYSTATE));//copy

*pResult = 0;
}

Lt
 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      07-25-2004
LT wrote:

> I'm calling the CMonthCalCtrl::GetMonthRange method there is an
> assertion error inside that method: ASSERT(::IsWindow(m_hWnd));


Why can't you say "if" before calling GetMonthRange?

If trouble persists, use http://groups.google.com to find a newsgroup
qualified to answer. This newsgroup can only accurately discuss
platform-neutral C++.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
 
 
 
Lt
Guest
Posts: n/a
 
      07-25-2004
User "Phlip" <> wrote :
> Why can't you say "if" before calling GetMonthRange?

I need get variables timeFrom, timeUntil for the rest of the code. And that
rest should be runned as well after the initialization as before a dialog
window is visible.

Lt


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      07-25-2004
Lt wrote:

> Phlip wrote:


> > Why can't you say "if" before calling GetMonthRange?


> I need get variables timeFrom, timeUntil for the rest of the code.


Can you concoct these values from functions in the <time.h> header file? Or
the platform-specific equivalents? Because the user has not yet had the
opportunity to change a value in your calendar control, you must be
collecting values that you could generate by alternate means.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
Lt
Guest
Posts: n/a
 
      07-25-2004
I works now. I've changed the line:
nCount = Calendar.GetMonthRange(&timeFrom, &timeUntil, GMR_DAYSTATE);
to:
nCount =
((CMonthCalCtrl*)GetDlgItem(IDC_MONTHCALENDAR2))->GetMonthRange(&timeFrom,
&timeUntil, GMR_DAYSTATE);
I've just used GetDlgItem instead of the Calendar variable created by select
in IDE the "Add variable..." command.

Lt


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      07-25-2004
Lt wrote:

> I works now. I've changed the line:
> nCount = Calendar.GetMonthRange(&timeFrom, &timeUntil, GMR_DAYSTATE);
> to:
> nCount =
> ((CMonthCalCtrl*)GetDlgItem(IDC_MONTHCALENDAR2))->GetMonthRange(&timeFrom,
> &timeUntil, GMR_DAYSTATE);


That line only works by accident. GetDlgItem returns a HWND, which happens
to be the first member inside CMonthCalCtrl. Then GetMonthRange only uses
that first member.

Typecasts are not magic that turns anything into anything else. Avoid as
many typecasts as possible. When the compiler tells you that your code is
not well-formed, fix the code. Typecasts only throw away compiler
diagnostics.

Try:

CMonthCalCtrl cal(GetDlgItem(IDC_MONTHCALENDAR2));
int nCount = cal.GetMonthRange(...);

Note that not cramming things all on one line makes them easier to fix, and
note that nCount should not exist before it is assigned.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
Lt
Guest
Posts: n/a
 
      07-25-2004
Philip wrote:
>GetDlgItem returns a HWND, which happens to be the first member inside

CMonthCalCtrl

CWindow::GetDlgItem (ATL) returns a HWND but I'm using CWnd::GetDlgItem
(MFC) that returns CWnd*

>Try:
>CMonthCalCtrl cal(GetDlgItem(IDC_MONTHCALENDAR2));
>int nCount = cal.GetMonthRange(...);


That dosen't work because the constructor CMonthCalCtrl::CMonthCalCtrl ()
doesn't take any parameters.

Lt


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      07-25-2004
Lt wrote:

> >GetDlgItem returns a HWND, which happens to be the first member inside

> CMonthCalCtrl
>
> CWindow::GetDlgItem (ATL) returns a HWND but I'm using CWnd::GetDlgItem
> (MFC) that returns CWnd*


MFC sucks. It has lead both of us astray. Switch to WTL to be happier, and
typecast less.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
What does "::DestroyWindow(hWnd)" mean? Joseph C++ 3 07-20-2005 03:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57