|
what's the return value of the StretchBlt call?
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
Hi.
Do delete STL functions such as remove() and erase() calls a class destructor if the element is a pointer to an object? For example, consider a vector of pointers to ClassX objects and a list of pointers to ClassX objects..
[code]
std::vector<classx *=""> sTextVec;
ClassX *pCX;
sTextVec.push_back(pCX);
...
// Now you need to deallocate memory from pText.
// Do functions such as remove() and erase() call ClassX
// destructor, or do you have to delete them explicitly?
[/code]
Thanks,
Kuphryn
|
|
|
|
|
kuphryn wrote:
Do functions such as remove() and erase() call ClassX
destructor, or do you have to delete them explicitly?
the container calls the destructor of the contained type. in your case, the contained type is a pointer, so it has no destructor (it's just a number). even more importantly, the destructor for a pointer does not delete the pointed-to object. this is nice, because you can use pointers as container elements and you don't have to worry that the objects that they point to will be deleted.
so, to really answer your question: yes, you have to manually delete the objects when you're done with them.
-c
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
typical vector clean up code goes 'something like:'
for ( vector_iter = vector.begin();
vector_iter != vector.end();
vector_iter++ )
{
delete (*vector_iter);
}
vector.clear();
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Okay. Thanks everyone.
Kuphryn
|
|
|
|
|
Hi, I am writing a Activex control in VC++(ATL,MFC). In this dll, I also have designed some classes used to support the functionality of this ActiveX Control. There are many places I need to use string, both in the classes and the ATL object's interface. But I don't know which string type to use. Could anyone give me a guidline on how to choose the following string types?
string
wstring
BSTR
_bstr_t
CComBSTR
Thanks!
Sherry
|
|
|
|
|
use BSTR on the external interfaces and choose between _bstr_t and CComBSTR for your internal string handling. they each have their benefits, though neither is as powerful as CString.
-c
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
Thank you Chris!
Then how abour string and wstring? I found string and wstring are widely used in the project I am currently working on, I don't know why they pick them instead of _bstr_t and CComBSTR.
|
|
|
|
|
string and wstring aren't designed to interact with BSTRs (allocation and so on is different with BSTRs).
-c
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
I am building a flat database for someone and thought it would be useful to have a list box available to show a list of the items in the db. I am real new to programming and have searched high and low for a way to accomplish this and haven't found anything. Is there a way to add the data in my db (which uses CFormView) by adding a dialog box? I just want to put it as a tool in the toolbar.
Thanks a lot for any pointers.
Garry
|
|
|
|
|
This is a 'huge' question in some ways.....so I can not possibly hope to provide a 'complete answer' to you....but here are some hints....
1. Listboxes take strings....so think: How can I get a series of strings to add to the list box....For each string fetched from your database, add it to the list...
2. I don't know exactly what you mean by 'flat database' but try to understand how to get some kind of string that represents each record in this database so that you can do #1 above.
3. Simplify the problem space to increase the likelihood of a 'small success' that you can use to build the 'next level' of the problem.
Also, be aware that you will very rarely find a code sample that does 'exactly what you needed' rather, you will most likely find a hint here and a snippette there that you will have to assemble in just the way you need it work. That being said, I'd suggest you crawl all over this web site and lurk for hours in your local book store just 'browsing for ideas.'
I don't know if this is any help at all, but wish you the best of luck on getting your project done....
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Thanks a lot for your advice. I really appreciate it!!
|
|
|
|
|
How can I prevent the first column of a listview header from being resized...???
I have tried the following code, but had no success???:
BOOL CTimelineCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HD_NOTIFY* pHDN = (HD_NOTIFY*)lParam;
switch(pHDN->hdr.code){
case HDN_BEGINTRACK:
if(pHDN->iItem==0){
*pResult=TRUE;
return TRUE;
}
break;
case HDN_ENDTRACK:
Invalidate();
break;
case HDN_BEGINDRAG:
*pResult=TRUE;
return TRUE;
default:
break;
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
Thanx in advance!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
It fails, because while you are probably compiling as a non-unicode app, you're running on a Unicode OS. See, there are actually two messages, HDN_BEGINTRACKA and HDN_BEGINTRACKW . If you're building as non-unicode, then HDN_BEGINTRACK is #define 'd to be equal to HDN_BEGINTRACKA ; if you're building as unicode, then it's #define 'd as HDN_BEGINTRACKW . Only one is actually sent though.
The proper way to do it, is as follows (this will also prevent double-clicking on the header from resizing it):
BOOL CCustomListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
switch ( reinterpret_cast<NMHDR*>(lParam)->code)
{
case HDN_BEGINTRACKW:
case HDN_BEGINTRACKA:
case HDN_DIVIDERDBLCLICKA:
case HDN_DIVIDERDBLCLICKW:
if ( reinterpret_cast<LPNMHEADER>(lParam)->iItem == 0 )
{
*pResult = TRUE;
return TRUE;
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
I found this at http://www.codeguru.com/mfc/comments/5710.shtml[^]; check there also for a version that disables the CTRL+ keyboard resize, and the cursor.
Shog9
------
If you really what to get shitfacde tell a crowded bar that is is yourt borthday and hife your wallet. you ka will many more friends.
- David Wulff, Brithday selebrations, 9/19/02
|
|
|
|
|
I totally forgot about that...
I have two versions of the same control
1) Derived from CWnd with an embedded header control
2) Derived from CListCtrl in report view
The code I originally used worked fine under the first version but wouldn't under the version derived from CListCtrl...
I actually snipped that code from someone else and it was originally coded like how you suggested, but when I changed it for the first CWnd derived control it worked fine...
Anyways...thanks alot I appreciate the help.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
i have read the serialization examples, and my book says that this is the best method for saving data in the real world, and at that my book never talked about it again.. go figure! So im unsure of how to actually save the data and retrieve it. Do you save data as an array and then serialize the array or struct? Or do you serialize data as it is input into the program.
Next, when retrieving the data, do i pull that data into an array, or is there a different method of doing all this?
xai
|
|
|
|
|
MFC serialization is very similar to saving data in binary mode in core C++. For example, let say you have created an abstract C++ class. The class object symbolizes one member of CodeProject including name, age, favorite programming tools, interest, etc. In C++, you write data to a file in a format that reflects the format of the class object. Serialization is similar in that sense.
I believe serialization is less powerful than core C++ write algorithm because you know to know before handle the size of the data. For C++, you could read, skip, and cancel whenever you want. With serialization, I am not completely sure you can skip a specific data.
Serialization is just another algorithm for reading and writing data. You do not have to use it.
Kuphryn
|
|
|
|
|
If you are positively sure that you (your app) are the only ones who will ever read that data, and if you are equally sure that the data format will never change, you can write the data in every way you want - even in some crude MFC CArchive.
But how can you be so sure?
Most of the time you have to support a old data format, or you know taht the next version of your programm will need to store enhanced data.
In this case a documented format is needed. XML springs to mind, but other possibilities are there: Just write comma-sparated values, prefix the file with the number of values and zip-encode the whole thing?
Almost anything is better than unstructured binary data in a file.
|
|
|
|
|
Hi,
I know how to get and replace selections (GetSel/ReplaceSel), but I didnt understand how I get the current position of the blinking cursor (caret).
I'd like to get the position of the caret and access the character left from it's current position? Thx for help!
|
|
|
|
|
clipped from MSDN:
Title: Edit Controls
Kyle Marsh
Microsoft Developer Network Technology Group
Created: January 31, 1992
after a seach on "GetCaretPos"
[ clip follows ]
Finding the Caret Position
An application can perform the following steps to determine the current position of the caret:
{
WORD wLineNumber;
WORD wLineIndex;
WORD dwGetSel;
WORD wStart;
WORD wEnd;
WORD wColNumber;
char szBuffer[128];
wLineNumber = (WORD)SendMessage(GetDlgItem(hWndDlg,IDEDIT),
EM_LINEFROMCHAR, -1, 0L);
// Send the EM_GETSEL message to the edit control.
// The low-order word of the return value is the character
// position of the caret relative to the first character in the
// edit control.
dwGetSel = (WORD)SendMessage(GetDlgItem(hWndDlg,101), EM_GETSEL,
0, 0L);
wStart = LOWORD(dwGetSel);
// Send the EM_LINEINDEX message with the value of -1 in wParam.
// The return value is the absolute number of characters
// that precede the first character in the line containing
// the caret.
wLineIndex = (WORD)SendMessage(GetDlgItem(hWndDlg,101),
EM_LINEINDEX, -1, 0L);
// Subtract the LineIndex from the start of the selection,
// and then add 1 (since the column is zero-based).
// This result is the column number of the caret position.
wColNumber = wStart - wLineIndex;
sprintf(szBuffer,"Caret at Line:%d Column:%d", wLineNumber+1,
wColNumber+1);
MessageBox(hWndDlg, szBuffer, "Current Caret Position",
MB_APPLMODAL);
}
hope that helps
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hi
I'm new to VC from a Delphi background, and would like to know how to call new modals (dialogs) and work on them, as you would in Delphi:
NewModal.ShowModal;
thanks
D
|
|
|
|
|
It is a two-step procedure in VC++:
CYourDlg dlg;
dlg.DoModal();
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
o ok, that's almost the same!
thanks
|
|
|
|
|
hello again
I'm trying to use the MS WebBrowser control in a dialog based application I'm making and I'm having the problem that I need to get access to the HTML code so I can work with it inside the program. The interface and most of the supporting stuff is looking good but I can't grast this final problem. It doesn't help that I'm no COM wizard but I'm always willing to learn
Thanks guys
|
|
|
|