|
|
I am working on an application that has the ability to open files using MFC and Visual Studio .Net 2003. I need give the user the option not to continue opening the file for special cases or scenarios. The determination is based on a keyword setting in an XML tag. Using the Serialize method, I was able to modify the software to not continue loading the file. However, it loaded it anyways but not completely. Do you know how I can prevent it from loading a file completely?
|
|
|
|
|
Have your Serialize method throw a CArchiveException. This will cause CDocument to totally cleanup the partially loaded file.
AfxThrowArchiveException(CArchiveException::none);
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Well, i need to execute a function at the change of day(or possibly a time defined by user). I have used CWnd::SetTimer()at one place for 5 secs trigerring. How can i do it to trigger every day(or hour)...i dont think it would be advisable to plainly convert a day's value into milliseconds and pass it to SetTimer()!!! What way can i achieve this??
|
|
|
|
|
It looks like SetTimer has a maximum interval of 24.85 days (if I did the math correctly).
Hours or a day shouldn't be a problem.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Just think of how many milliseconds are lost each day, I would go for QueryPerformanceCounter but then some say the MM timers are better :p
|
|
|
|
|
|
Why don't you just make use of windows' Task Scheduler?
|
|
|
|
|
Task scheduler?? i dont know anything about it...
Right now i have used SetTimer() for 6lac count; that's 10 mins....
do you think there could be a problem using SetTimer()???
|
|
|
|
|
Hi,
I am trying to resize 2 CButtons at runtime, but am having a really hard time getting them to appear in the correct place.
GetWindowRect gives me values that are offset to the dialog. To demonstrate, the code i am using is something like the following;
<br />
CRect btnRect;<br />
btn1.GetWindowRect(btnRect);<br />
<br />
::SetWindowPos(btn1.m_hwnd, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW); <br />
This results in the button moving diagonally across the screen, it doesnt stay still, which is what I would have expected. I find that if i take away (rectDialog.left + 3) and (rectDialog.top + 29) from btnRect.left and .top it will work (stay still).
I assume the '3' is the width of the boarder, and '29' the height of the title bar. Is this correct?
If so, how can I find it programatically?
Thank you very much for your help.
|
|
|
|
|
SetWindowPos coordinates for child windows are relative to the client
area of the parent window.
You are using window coordinates relative to the screen.
Try GetClientRect instead of GetWindowRect.
What Roger said
Also, MoveWindow is simpler and more appropriate for this than SetWindowPos.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
MapWindowPoints() or ScreenToClient()
CRect btnRect;
btn1.GetWindowRect(btnRect);
ScreenToClient(&btnRect); //assumes that this is the parent of btn1
btn1.SetWindowPos(wndTop, btnRect.left, btnRect.top, btnRect.Width(), btnRect.Height(), SWP_SHOWWINDOW);
|
|
|
|
|
I need someone with Orcas to test the following code. It compiles just fine under Comeau C++ 4.3.9 in strict mode (Comeau is supposedly the "most Standards-compliant compiler in existence") but fails with an error under VS.NET 2003 (VC++). According to the ANSI Standard (section 10.3.5 in my Draft copy), I can't find any reason for it to fail.
class MyBase
{
public:
MyBase() {}
virtual ~MyBase() {}
virtual MyBase *Copy() const
{
return new MyBase(*this);
}
};
class MyBase2
{
public:
MyBase2() {}
virtual ~MyBase2() {}
virtual MyBase2 *Copy() const
{
return new MyBase2(*this);
}
};
class MyDerived : public MyBase, public MyBase2
{
public:
MyDerived() {}
virtual ~MyDerived() {}
virtual MyDerived *Copy() const
{
return new MyDerived(*this);
}
};
int main()
{
return 0;
}
|
|
|
|
|
|
I don't have Orcas installed and really don't want to risk messing up my main build environment, which is a pretty delicate setup. Dropping a new compiler on the system is the general equivalent of a tactical nuclear warhead. I want to know if the bug is in Orcas (i.e. emits an incorrect error message). Please, just run it through Orcas and post the output.
|
|
|
|
|
I know you didn't ask, but it works fine in 2005.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks. I'll just assume it works fine in VS 2008 as well.
|
|
|
|
|
another problem
In my menu I use checked option. The problem is how to change the checked/uncheked mark when I click on it and also send the value to some variable (true if checked, false if unchecked).
Program is MFC based on CFormView.
Hope you understand my problem......
|
|
|
|
|
Hi barbarini,
Use the GetMenuItemInfo() API call to get the menu item's state, you can then tell if it's checked or not.
regards,
|
|
|
|
|
ok, but how will i get my menu item, I tried with GetDlgItem but it is not working.
|
|
|
|
|
I tried this just to see if I can change the checked/unchecked mark, but still getting an error:
CMenu* mMenu = this->GetMenu();
mMenu->CheckMenuItem(ID_EDIT_CASESENSITIVE, MF_UNCHECKED | MF_BYCOMMAND);
|
|
|
|
|
Whats return value CheckMenuItem ?
|
|
|
|
|
I think Menu is a part of your Frame window and you are calling the function in a class of View window. Is it?? if yes, try like this...
<br />
CMenu* pMenu;
CWnd* pParent = GetParent();<br />
pMenu= pParent->GetMenu();
pMenu->CheckMenuItem(ID_EDIT_CASESENSITIVE, MF_UNCHECKED);<br />
|
|
|
|
|
interface IDraw
{
virtual void Draw() = 0;
};
interface IShapeEdit
{
virtual void Fill (FILLTYPE fType) = 0;
virtual void Inverse() = 0;
virtual void Stretch(int factor) = 0;
};
//------------
// C3DRect supports IDraw and IShapeEdit.
class C3DRect : public IDraw, public IShapeEdit
{
public:
C3DRect();
virtual ~C3DRect();
// IDraw
virtual void Draw();
// IShapeEdit
virtual void Fill (FILLTYPE fType);
virtual void Inverse();
virtual void Stretch(int factor);
};
//-----------------------------------
// Here is the global 3D rect.
C3DRect* ptheRect;
// Functions to operate on the 3D rect.
void CreateThe3DRect();
void DestroyThe3DRect();
Implementing CreateThe3DRect() and DestroyThe3DRect() is trivial. Simply use the new and delete keywords to create and destroy the object:
// Creation function.
void CreateThe3DRect()
{
// Create a 3d-rect.
ptheRect = new C3DRect();
}
// Destroy the rectangle.
void DestroyThe3DRect()
{
// See ya!
delete ptheRect;
//--------------------
// This method returns interfaces to the client.
bool GetInterfaceFrom3DRect(INTERFACEID iid, void** iFacePtr)
{
if(ptheRect == NULL){
cout << "You forgot to create the 3DRect!" << endl;
return false;
}
if(iid == IDRAW){ // They want access to IDraw.
// Cast the client's pointer to the IDraw interface of ptheRect.
*iFacePtr = (IDraw*) ptheRect;
return true;
}
if(iid == ISHAPEEDIT) { // They want access to IShapeEdit.
// Cast the client's pointer to the IShapeEdit interface of ptheRect.
*iFacePtr = (IShapeEdit*) ptheRect;
return true;
}
// I have no clue what they want.
*iFacePtr = NULL; // Just to be safe.
cout << "C3DRect does not support interface ID: " << iid << endl<< endl;
return false;
}
//----------------------------------------------------
int main()
{
bool retVal = false;
IDraw* pDraw = NULL;
//IDraw3* pDraw3 = NULL;
IShapeEdit* pShapeEdit = NULL;
CreateThe3DRect();
// Can I get the IDraw interface from object?
retVal = GetInterfaceFrom3DRect(IDRAW, (void**)&pDraw);
if(retVal)
pDraw->Draw();
DestroyThe3DRect();
return 0;
}
//-----
are we simply casting pointers from one type to the next here?
when selecting the interface with GetInterfaceFrom3DRect ,i have iFacePtr which is a void pointer and ptheRect.
*iFacePtr = (IDraw*) ptheRect; <-- i dont get this part.
here iFacePtr is of IDraw type.. now we have ptheRect which is of C3DRect, taking that casting it to IDraw and assigning it to iFacePtr.
does this mean we are working with an instance of C3DRect but of type IDraw?
how did we managed that?
doesn't this mean we can make an instance of an abstract class by type casting it?
As you can see im confused any easy to digest explanation would be great.
thank you
|
|
|
|
|
Lamefif wrote: any easy to digest explanation would be great.
The design is lousy, period. I don't know if any explanation of why would be easy to digest since I don't have any idea what you know.
|
|
|
|