|
yccheok wrote:
However, I am not quite remember the reason to do so and not to use CList to store the pointer of non-CObject class.
I believe, There is no particular reason not store Non COBJECT drived class in CList.
you can store almost Everything using CList.Let take example:-
int is not derived from CObject, even not a class,it's a keyword but you can store it using CList without nay extra overhead and difficulty.
I can't find any reason for not using CList for Non CObject derived class.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hello, I have an object called XXX previously derived from CDocument in my MDI project.
Later, I create an concrete class called Subject. And I let XXX to have multiple inheritance from Subject (Subject is an object with protected constructor)
The problem is, whenever I used dynamic_cast to cast a Subject pointer to XXX (I am quite sure Subject pointer is actually pointing to XXX), a visual c++ runtime error will occur.
void fun(Subject *s) {
XXX *var = dynamic_cast<xxx *="">(s);
var->hehehe();
}
However, when I try to do this:
void fun(Subject *s) {
XXX *var = (XXX *)(s);
var->hehehe();
}
everything just go fine. may i noe why this happen? is this bug related to something called dynamic creation?
thanks you.
cheok
|
|
|
|
|
Hi,
Have you tried enabling RTTI for your project ?
When it's enabled, instead of throwing an exception, the dynamic_cast will return NULL (make sure you check the return value! )
Hope this helps
|
|
|
|
|
Can you please let me know how I can enable RTTI for the project? Please note that for the classes which my CDocument inheritance from, I created by hand.
Here is my details:
I have an abstract class named CObserver and a concrete class named CSubject. The purpose of having this two classes is that, some interesting event will always happen in subject. observer is a guy which is interested in the event in subject. subject will notify all the observers attached to it whenever an event happen.
---------------------------------------------------------------------
class CObserver {
public:
virtual ~CObserver();
virtual void Update(CSubject *s) const=0;
protected:
CObserver();
};
class CSubject {
public:
virtual ~CSubject();
virtual void Attach(CObserver *o);
virtual void Detach(CObserver *o);
virtual void Notify();
protected:
CSubject();
private:
CList<cobserver*, cobserver*=""> _observers;
};
---------------------------------------------------------------------
Now, I need to monitor a IO port. Then, I need to notify my CDocument whenever there is some IO activity. Hence, I create an CIOMonitor class which is single inheritance from CSubject.
// Please note that I remove most of the members. Only leave those which is related to this bug
class CIOMonitor : public CSubject
{
int GetInt() const;
}
I use Wizard in VC++ to create MDI project. Then, for the CCatchbugDoc (multiple inheritance from CDocument and CObserver). This is because CCatchbugDoc will be interested in the event happen in CIOMonitor
class CCatchbugDoc : public CDocument, public CObserver
{
public:
virtual void Update(CSubject *s) const;
};
Please note here is the root of evil
void CCatchbugDoc::Update(CSubject *s) const
{
/* Everything work fine with this unsafe casting */
/* But dynamic casting just prompt me a runtime error */
/**/
/* CIOMonitor *p = (CIOMonitor *)s; */
CIOMonitor *p = dynamic_cast<ciomonitor *="">(s);
if(p == NULL) {
AfxMessageBox("unknown error during dynamic cast");
return;
}
CString string;
string.Format("Nofity. CIOMonitor: %i", p->GetInt());
AfxMessageBox(string);
}
Here is my suspection
1. In VC++, CCatchbugDoc is created using dynamic creation. Initially, CCatchbugDoc is single inheritance from CDOcument. The following macro is added by VC++ wizard to enable dynamic creation:
IMPLEMENT_DYNCREATE(CCatchbugDoc, CDocument)
Now, I make CCatchbugDoc as multiple inheritance (CDOcument and CObserver). But I still use back the same
IMPLEMENT_DYNCREATE(CCatchbugDoc, CDocument)
Can this be the possible root cause of bug?
Thank you!
-cheok
|
|
|
|
|
In VC++ 6.0:
Go to Project->Settings...
Go to the C/C++ tab
Category = C++ Language
Check the box "Enable Run-Time Type Information (RTTI)
Set this to both Debug and Release
This makes your exe slightly bigger (not that much), but it allows you to query the types of the objects you're using, and use dynamic_cast.
Watch out for name clashes when using multiple inheritence. If you really need to use this, make sure the base classes do not have methods with the same name (and the base classes' base classes...).
Hope this helps
|
|
|
|
|
Thanks. That's really help me out. Just wondering why vc++ doesn't enable RTTI by default. I think they should give us compilation error when it encounter the user is trying to use RTTI feature by not enabling the RTTI flag.
|
|
|
|
|
Does anyone know of where I can find an example of getting/putting html source in an IE window using VC6. I think I need to use IPersistStream[Init] to be able to access the full source, but I don't really understand how. I have tried doing this with the body object, but the html was incomplete and I was unable to write changes back in because the body is read-only.
I have the rest of my BHO in place, but I am really stumped on to modify the html source code. Any help or directions would be great.
|
|
|
|
|
Hi, for easier portability(dont wanna use winmain to get rid of the console) i need to disable the console that usually pops up by default with the main() program entry function
I dont want any console to pop up. Anyone found a way to use the main function without getting a console right up your face once you run it, or how to kill it before it pops up.
I've looked everywhere for a solution but there seems to be no such available
|
|
|
|
|
How would disabling the console make the code more portable? Isn't the console just the way windows sets up stdout? I mean, if you write something like
#include <iostream>
int main{
std::cout<<"Hello World"<
|
|
|
|
|
Hello,
I need to download a web page and all the pictures that it has.any ideas how to do this?
|
|
|
|
|
|
Hello
On Windows NTFS based systems, after we create a user using the NetUserAdd WINAPI call and we subsequently delete the user from User Account/Control Panel, the references for that particular user in the sharing/security permissions of a file folder still remain. Are there any Windows API's I can use to delete all of those references?
-av
|
|
|
|
|
cgb143 wrote:
and wish to hide the tabs of several dialog boxes that are used as storage pages.
That sounds weird...
cgb143 wrote:
I cannot delete the pages as they are used to store variables.
[...]Can someone suggest how to modify the code to hide the tabs I do not wish to show, the application looks clumsy with 6 (out of 10) blank tabs.
Why don't you just stop using them "to store variables" so as to avoid using those tabs altogether?
cgb143 wrote:
MSDN Win32 Common Controls Part 6
I couldn't find that in MSDN. You are most likely seeing obsolete documentation.
cgb143 wrote:
See the code below:
if (bEnable)
{
m_DisabledPages.RemoveKey (nPage);
CTabCtrl* pTab = GetTabControl();
ASSERT (pTab);
TC_ITEM ti;
char szText[100];
ti.mask = TCIF_TEXT | TCIF_STATE;
ti.dwState = 0x00;
ti.dwStateMask = 0x00;
ti.pszText = szText;
ti.cchTextMax = 100;
}
[...].
You are creating a TC_ITEM named ti, loading some values in it, and then doing nothing...
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Jose Lamas Rios wrote:
cgb143 wrote:
and wish to hide the tabs of several dialog boxes that are used as storage pages.
That sounds weird...
and your point is ??
Jose Lamas Rios wrote:
cgb143 wrote:
I cannot delete the pages as they are used to store variables.
[...]Can someone suggest how to modify the code to hide the tabs I do not wish to show, the application looks clumsy with 6 (out of 10) blank tabs.
Why don't you just stop using them "to store variables" so as to avoid using those tabs altogether?
The application .EXE is around 500Kbytes, the entire program was written around this structure. I do not want to re-write it.
Jose Lamas Rios wrote:
cgb143 wrote:
MSDN Win32 Common Controls Part 6
I couldn't find that in MSDN. You are most likely seeing obsolete documentation.
Well I find it very easily. Visual Studio 6 - Help - Common Controls.
Jose Lamas Rios wrote:
You are creating a TC_ITEM named ti, loading some values in it, and then doing nothing...
this is a small part of the code that SHOULD enable/disable the tab.
I guess that you do not understand the structure hence the 'no -answer'. It's easy to criticise others, some strive to avoid it.
|
|
|
|
|
Hi,
I'm working on a application using quite a lot of GDI+, both printing and for the regular SDI view. (Same program as in the post below)
Everything is working fine in the regular view and print preview. And normally everything is working fine when printing.
My problem is supporting old hardware Some of the people that tested my software is using windows 98, and printing HP 540 Deskjet. Instead of the usual output, either color or b/w, the page prints with inverted colors. In other words, what should be printed as black comes out as white, and what should be white comes out as black.
I can't ignore this problem even though the hardware having problems is *old*, many of my target users is using that old HW.
I've made sure the printer drivers is the latest, GDI+ which I use for printing is working fine in both regular view and print preview, so that's basically out of the question.
I tried printing with the same computer on a newer printer which worked fine.
Anyone got any ideas?
|
|
|
|
|
Just guessing...
How does printing from other programs work?
Have you checked the printer settings (things like "color space", RGB vs CYM, paper type, or anything that looks suspicious)?
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
hey,
Here is a wierd problem I've been breaking my head over for the last couple of days........ I am writing a program in VC which reads information off a window written in VB using the windows handles which I obtain programatically (and which can be viewed by Spy++). The object that I want to read stuff from contains 4 other objects
1. A drop down
2. Label (which I want to read)
3. A Tree
4. Some gif
Through Spy++ when I view this object within the VB application it shows it as "ThunderRT6UserControlDC" ( which is a VB thing ). However I cannot view 1 and 2 through Spy ++ while I can view 3 and 4....now I know that 1 and 2 are a part of the "ThunderRT6UserControlDC" cause I can hide the parent and all 1,2,3 and 4 disappear. If I can get the handle to 2 I can read in the text
Someone PLZZZZZZZZZZZZZZ help me with this its killing me.
To show it disgramatically -->
"ThunderRT6UserControlDC"
------------------------------
+ 2 +
+ 1 4 +
+ 3 +
+ +
------------------------------
|
|
|
|
|
Hi,
I've been working on a MFC application and am basically finishing up the latest bugs.
I've used the standard CArchive class for files, but when opening files there's a problem.
When I am opening files through my program - no problem. Everything working as it should.
However, when opening the files through windows (i.e. double clicking the files, or right-clicking and choosing open), I get an error message. The file opens as it should, but at the same time, I'm getting an error something like this (Directly translated from Norwegian, so not litterary this text): "Can't find {Filename}. Make sure you typed the name right, and try again. If you want to search for a file, click Start and then Search."
Even though I didn't provide any code here, anyone got an idea what's going on?
|
|
|
|
|
I have a dialog that has 2 radio buttons and 2 edit boxes. I would like to disable one of the edit boxes if a specific button is pressed.
Any help? I am using VC++ 6.
Thanks, Alex
|
|
|
|
|
|
|
(GetDlgItem(IDC_MY_EDIT))->EnableWindow(FALSE);
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
HI!
Maybe someone can help me out!
I got:
Stuct OPENFILENAME
ofn.lpstrFile = szFileName;//char[]
I need to convert szFileName to const WCHAR*
for this GDI+ Consrtuctor:
Image( const WCHAR *filename,
BOOL useEmbeddedColorManagement
);
Thanks
lemi
|
|
|
|
|
If you have UNICODE and _UNICODE defined, I think all you'd need to do is make szFileName be a WCHAR too, since lpstrFile will be pointing to a LPWSTR .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|