473,800 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(::IsWind ow(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
OnMcnGetdaystat eMonthcalendar2 (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::OnMcnG etdaystateMonth calendar2(NMHDR *pNMHDR, LRESULT
*pResult)
{
LPNMDAYSTATE pDayState = reinterpret_cas t<LPNMDAYSTATE> (pNMHDR);

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

nCount = Calendar.GetMon thRange(&timeFr om, &timeUntil,
GMR_DAYSTATE);//inside this line there is an assertion error!!!
memset(states,0 x00, sizeof(MONTHDAY STATE)*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.wMont h * 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(pDayStat e->prgDayState, states,
nCount*sizeof(M ONTHDAYSTATE));//copy

*pResult = 0;
}

Lt
Jul 22 '05 #1
7 2424
LT wrote:
I'm calling the CMonthCalCtrl:: GetMonthRange method there is an
assertion error inside that method: ASSERT(::IsWind ow(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*******@yaho o.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.GetMon thRange(&timeFr om, &timeUntil, GMR_DAYSTATE);
to:
nCount =
((CMonthCalCtrl *)GetDlgItem(ID C_MONTHCALENDAR 2))->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.GetMon thRange(&timeFr om, &timeUntil, GMR_DAYSTATE);
to:
nCount =
((CMonthCalCtrl *)GetDlgItem(ID C_MONTHCALENDAR 2))->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_MONTHCALEND AR2));
int nCount = cal.GetMonthRan ge(...);

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::GetDlg Item (ATL) returns a HWND but I'm using CWnd::GetDlgIte m
(MFC) that returns CWnd*
Try:
CMonthCalCtr l cal(GetDlgItem( IDC_MONTHCALEND AR2));
int nCount = cal.GetMonthRan ge(...);


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::GetDlg Item (ATL) returns a HWND but I'm using CWnd::GetDlgIte m
(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
3280
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 with this problem. I am uncertain about what etiquette calls for, but more on that later. My Objective: I am trying to control the _VMWare Desktop_ application
11
3658
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 rules when it comes to file paths. A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle paths in the following manner:
7
22747
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 and change it with other panel which contains other business logic and UI controls.
8
1550
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 my references: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_data_source.3a_.programmatically_configuring_an_odbc_data_source.asp ...
2
1622
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: ******************************************************************************************* Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler...
4
2255
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 application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
5
3419
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 part attempting to do what is this article by Nish: http://www.voidnish.com/articles/ShowArticle.aspx?code=cbwijw I have to hook up a unmanaged callback to a managed method using IJW NOT P\Invoke. So I am employing this "Thunk" or "Bridge" class...
5
550
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 doesn't support this property or method" Yet the Intellisense shows the following-- axMainViewJ1Obj1.AddFileJ1(ref string str);
19
4212
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 = new CTestClientSocket(this, ip, port); pTemp->Connect(); m_collClients.push_back(pTemp);
0
9553
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10256
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9095
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7584
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6824
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2953
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.