473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

LT
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
Jul 22 '05 #1
7 2405
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
Jul 22 '05 #2
Lt
User "Phlip" <ph*******@yahoo.com> 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
Jul 22 '05 #3
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
Jul 22 '05 #4
Lt
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
Jul 22 '05 #5
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
Jul 22 '05 #6
Lt
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
Jul 22 '05 #7
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
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
8
by: Hasani | last post by:
OK, I'm trying to programmatically create an Access database/mdb file but CreateDb(string) always returns false. I don't know what I'm doing wrong, is it my extern signature? Thx in advance ...
2
by: tshad | last post by:
I am getting an error on a object name that doesn't exist (according to asp.net), but if you look at the trace, it does. Here is the error: ...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
5
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
5
by: John Olbert | last post by:
Subject: Error is Object doesn't support this property or method I am trying to pass a C# string under Vs2005 (Net2) to an Vb6 ActiveX Control. I get the following runtime error-- "Object...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.