|
How about using LoadAccelerators()
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Compiler - VC6
I'm working on a project that is an activeX control, and that links to several DLL's. In one of the DLL's, I'm having a problem with CStrings - for some reason, I'm getting an access violation (C0000005) in MFC42D.DLL when I try to pass a CString from one class to another. Both classes are in the DLL I'm working in.
I've tried a number of methods for creating the CString in the calling function,but nothing seems to be working. Is there some sort of bizarre rule concerning CStrings that I'm not aware of?
If anyone can suggest something to check, I'd appreciate hearing about it.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote:
Is there some sort of bizarre rule concerning CStrings that I'm not aware of?
I am aware of no such known restrictions.
John Simmons / outlaw programmer wrote:
If anyone can suggest something to check, I'd appreciate hearing about it.
Memory corruption can produce C0000005 access violation errors in blocks (objects) that are not related to the code responsible for the problem.
Is your CString object on the stack? If it is move the location significantly by placing a large block of memory on the stack right in front of it. Then test for the error again.
char buf[0xffff];
CSstring mystring;
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
i am definitely puzzled by this.
i have a small class hierarchy:
result - abstract base class
burnsResult - abstract, derived from result
002burnsResult - concrete, derived from burnsResult
003burnsResult - concrete, derived from burnsResult
textResult - concrete, derived from result
so far so good. the default copy constructor exists for class textResult, but it does not exist for 002burnsResult or 003burnsResult.
i am getting:
error C2582: 'operator =' function is unavailable in 'file'
the VS .NET 2003 help for this error is nice and clear, the only problem is that the word operator does not exist in any of the .h files defining these classes
so how come there is a default copy constructor for one class, but not the other two?
i don't really want to define my own copy constructor, since there should be no need. i am mainly a C programmer, so perhaps i have overlooked something obvious. anyone got any ideas on why this is happening?
|
|
|
|
|
feline_dracoform wrote:
i am getting:
error C2582: 'operator =' function is unavailable in 'file'
On what line of code?
feline_dracoform wrote:
i don't really want to define my own copy constructor, since there should be no need.
Just because you don't see the need does not mean one does not exist. Copy constructors are almost always a good idea. At the very least, they keep the compiler from making (incorrect) assumptions.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
Copy constructors are almost always a good idea. At the very least, they keep the compiler from making (incorrect) assumptions.
i had made the assumption that using the default copy constructor was a good idea, since this made sure i wouldn't forget to copy one of the member variables of my class.
is this a bad assumption on my part?
|
|
|
|
|
Per MSDN:
If you do not supply any constructors, the compiler attempts to generate a default constructor. If you do not supply a copy constructor, the compiler attempts to generate one. A compiler-generated default constructor sets up the object (initializes vftables and vbtables), and it calls the default constructors for base classes and members, but it takes no other action.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
First a copy constructor is not the same thing as an assignment operator. That said the compiler will generate a default assignment operator much the same as it does for copy constructors, i.e., member wise.
So moving on...
feline_dracoform wrote:
error C2582: 'operator =' function is unavailable in 'file'
That message does not mean that the default assignment operator has not been generated by the compiler. It is completely dependent on what you are attempting to assign to what in the code that produces that error.
Without seeing some of the pertinent code we just can't tell what the problem is.
Hate is not a family value.
-pete
|
|
|
|
|
*oops*
yes, i discovered a copy constructor isn't the same as an assignment operator after quite a bit of reading yesterday. it is a few years since i have done much C++, and i had forgotten this.
the problem function was:
result *002burnsResult::cloneResult(ParentResult *newParent)
{
002burnsResult *newResult = new 002burnsResult;
*newResult = *this;
newResult->setParent(newParent);
return newResult;
}
feeling confused, i tried to compile the same class under UNIX. this also refused to work, but the compiler told me it was unable to construct a default copy constructor for the class i didn't even get as far as this function.
i think having a class member of type QValueVector<QString> is causing this problem, but i have no idea why. i am guessing Qt have done something strange in their classes.
writing a copy constructor, and switching to:
002burnsResult *newResult = new resultBurns(*this);<br />
works fine. the thing is, all i have done in my copy constructor is a list of a = rhs.a lines, one per class member.
at least this works, and i have re-learnt a bit of C++. i would still like to understand why this didn't work though.
|
|
|
|
|
Hi,
To disable and enable a submenu item on runtime in an MFC app, I have used the following
code but seen no change. What is the problem with it?
MSDN says m_bAutoMenuEnable should be set to FALSE in the constructor of CMainFrame (in CMenu::EnableMenuItem), but in CDialog class there doesn't seem to be such a variable, or is there?
If I have to use ON_UPDATE_COMMAND_UI, can you give me some information on what to do?
Thanks...
CMenu* pMenu, *subMenu;
pMenu = AfxGetMainWnd()->GetMenu();
subMenu = pMenu->GetSubMenu(1);
subMenu->EnableMenuItem(ID_SETTINGS_F, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
DrawMenuBar();
subMenu->EnableMenuItem(ID_SETTINGS_F, MF_BYPOSITION | MF_ENABLED);
|
|
|
|
|
i m trying to understand ur problem. if i m correct, u want to disble some submenu item on some event occuring. ur code seems to be perfectly OK. i guess u can remove the statement
DrawMenuBar();
i hope it will work. as it works in my application
|
|
|
|
|
Yes, i want to disable the submenu item on some event and enable it on some other event. However the code does not work with or without DrawMenuBar(); The menu does not get affected at all.
Should I do something with the UPDATE_COMMAND_UI?
|
|
|
|
|
Maybe something like this:
//add event handler to menu item.
void PbmFlexListViewer::OnUpdateYourMenuItem(CCmdUI *pCmdUI){<br />
pCmdUI->Enable(bEnable);<br />
}
good luck!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
Could not make it grayed, but is disabled right now.
I use this code and threw away the preivous things!
settingsF_Enable = TRUE;<br />
<br />
settingsF_Enable = TRUE;<br />
<br />
void MyDlg::OnUpdateSettingsF(CCmdUI* pCmdUI) <br />
{<br />
pCmdUI->Enable(settingsF_Enable);<br />
}
I hope somebody could tell me how to make it gray.
There must be something to be added in the OnUpdateSettingsF() function, but I couldn't find how to call the pointer to the menu item and call EnableMenuItem() with MF_GRAYED
|
|
|
|
|
i have created a status bar in my dialog based application.
the code is below:-
#define IDC_STATUSBAR 32000 //resource id
CStatusBarCtrl m_StatBar;
BOOL m_bStatOK = m_bStatBar.Create(WS_CHILD | WS_BORDER | WS_VISIBLE, rect, this, IDC_STATUSBAR);
m_StatBar.SetText("Application Running",0,0);
The program is running fine. the text is shoen on the left hand side of the status bar. Now i want to display another text on the right hand side of the statusbar. how do i do? i tried by inserting the statement
m_StatBar.SetText("Time",255,0);
But it had no impact?
how do i proceed?
|
|
|
|
|
I want to change the position of mouse on an internet explorer window.I have tried the code below.The problem is that hr = pDoc4->createEventObject(NULL,&pEvtObj) fails.Because of this failure there is no point proceeding with the remaining code.Can you tell me the reason for this failure.Thanks in advance.
//For changing mouse position
IHTMLEventObj *pEvtObj = NULL;
IHTMLDocument4 *pDoc4 = NULL;
hr = m_pHTMLDoc->QueryInterface(IID_IHTMLDocument4,(void**)&pDoc4);//m_pHTMLDoc is a valid document pointer
if(SUCCEEDED(hr))
{
// VARIANT vEvt;
// VariantInit(&vEvt);
// vEvt.vt = VT_DISPATCH;
// vEvt.pdispVal = NULL;
hr = pDoc4->createEventObject(NULL,&pEvtObj);
if(SUCCEEDED(hr))
{
CComQIPtr<ihtmleventobj2, &iid_ihtmleventobj2=""> pEvtObj2;
pEvtObj2 = pEvtObj
Xpos = 100;
Ypos = 200;
g_Ypos = g_lastYpos = Ypos;
hr = pEvtObj2->put_clientX(Xpos);
if(hr == 0)
{
AfxMessageBox("put_clientX successful");
}
else
{
AfxMessageBox("put_clientX failed");
}
hr = pEvtObj2->put_clientY(Ypos);
// }
// pEvtObj->Release();
}
pDoc4->Release();
}
|
|
|
|
|
I need and algorithm or a sample code to compare two lines on word basis and show added/deleted/changed words within lines during comparison.
Any suggestion would be appreciated.
Thanks
|
|
|
|
|
Hello, I don't know if this is super-easy to accomplish,
I am pretty new to VC++/MFC..
I need to create a dialog which must contain a different number
of CButton controls depending on certain state parameters of the
application. So I need to dynamically create a number of those
controls and attach a message handler for them ( they all share
the same message handler code ).
How do I attach this listener function to the controls once
I've created them?
(I destroy all buttons and create a bunch of new ones when the layout changes)
thankful for any help.
|
|
|
|
|
Why dont you enable/disable or show/hide the controls at runtime, it is also better by UI Design-Guidelines.
-> Make a full dialog with all resources in the resource editor, assign control objects to all controls and work with mycontrol.EnableWindow( bActiveNow )
Try this @ home. (B&B)
|
|
|
|
|
I've thought of that as well.
But I really don't have a clue as of what the maximum number of controls is. I could of
course create a ridiculously large amount of CButton objects to be on the safe side, and just
hide/show those. But it sounds a bit unneccessary to me...
And I'm still very much interested in attaching a message handler dynamically. Can I for example
create a hook and install it for every new item? And in that hook listen for the BN_CLICKED event
and if one is received obtain the text for the control and pass it further on?
If so, how is a hook procedure attached?
|
|
|
|
|
Hello, I don't know if this is super-easy to accomplish,
I am pretty new to VC++/MFC..
I need to create a dialog which must contain a different number
of CButton controls depending on certain state parameters of the
applications. So I need to dynamically create a number of those
controls and attach a message handler for them ( they all share
the same message handler code ).
How do I attach this listener function to the controls once
I've created them?
(I destroy all buttons and create a bunch of new ones when the layout changes)
thankful for any help.
|
|
|
|
|
Hello,
Can a GDI object be created once (say when the class is constructed) and be used as many times as the programmer is pleased?
Example:
Class::Class()
{
myPen = CPen(....);
}
void Class::DrawThis()
{
pDC = new CDC();
pDC -> Attach(GetDC() -> GetSafeHdc());
pDC -> SelectObject(&myPen);
}
Is this valid and recommended?
dNimrod#X
________________________
|
|
|
|
|
Yes, but I don't recommend it because it can be hard(er) to maintain code that shares GDI objects. The only time I'd keep a GDI object around for the lifetime of my app is when it's very expensive to create one on the fly.
One other thing - DrawThis() should unselect myPen when it's done using it. For example:
void Class::DrawThis()
{
CPen* pOldPen = pDC->SelectObject (&myPen);
...
pDC->SelectObject (pOldPen);
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I disagree with Ravi, if you are going to use a GDI object a lot, I say create it once and just keep using it. The exception is device contexts (CDC and related classes) - DCs are a shared and scarce system resource, and CDC s should exist for only as long as you need them.
Your sample code is wrong, however, in the way it's using CDC . You need to match GetDC() and ReleaseDC() calls, as well as select the pen out of the DC before releasing it.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
#include "witty-quote.h"
|
|
|
|
|