|
Thanks Prasad,
Thanks to clear my doubts
Pankaj Jain
|
|
|
|
|
A MultiColumn ListBox doesn't give that functionality - you want a ListView instead. To add text to a ListView in the way you want, use something like:
LVCOLUMN col = {0};
SendDlgItemMessage(IDC_LIST2, LVM_INSERTCOLUMN, 0, (LPARAM)&col);
col.iSubItem = 1;
SendDlgItemMessage(IDC_LIST2, LVM_INSERTCOLUMN, 1, (LPARAM)&col);
LVITEM item = {0};
item.mask = LVIF_TEXT;
item.iSubItem = 0;
item.pszText = "Hi";
int itemIndex = (int)SendDlgItemMessage(IDC_LIST2, LVM_INSERTITEM, 0, (LPARAM)&item);
item.iSubItem = 1;
item.pszText = "All";
SendDlgItemMessage(IDC_LIST2, LVM_SETITEMTEXT, itemIndex, (LPARAM)&item);
SendDlgItemMessage(IDC_LIST2, LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE);
SendDlgItemMessage(IDC_LIST2, LVM_SETCOLUMNWIDTH, 1, LVSCW_AUTOSIZE);
[Updated to correct code, add column sizing]Last modified: 17mins after originally posted --
|
|
|
|
|
Hi All,
I use AllocSysString like this
1) - CString myStr="ABCD";
int i=SomeFunction(myStr.AllocSysString());
Later in the code I free the memory as SysFreeString(_com_util::ConversStringToBSTR(myStr));
After using a memory profiling tool now, I don't get a mem. leak in this manner.
Is this the correct approach or should I use
2) - CString myStr="ABCD";
BSTR myStrBSTR=myStr.AllocSysString();
int i=SomeFunction(myStrBSTR);
and then use SysFreeString. While googling I found out the use of CComBSTR.
Can someone here tell me if I am using the right approach or should I use the second one, or use CComBSTR that manages allocation/deallocation by itself.
|
|
|
|
|
Q2A wrote: 1) - CString myStr="ABCD";
int i=SomeFunction(myStr.AllocSysString());
Later in the code I free the memory as SysFreeString(_com_util::ConversStringToBSTR(myStr));
After using a memory profiling tool now, I don't get a mem. leak in this manner.
This approach will definitely cause memory leak, instead use CComBSTR .
CString str(_T("Some Value");
CComBSTR bsStr(str.AllocSysString());
int i=SomeFunction(bsStr);
or Use CComBSTR .
CComBSTR bsStr(_T("Some Value"));
int i=SomeFunction(bsStr);
Here, you dont need to worry about memory leak, CComBSTR will take care of those.
|
|
|
|
|
Hello,
What's the difference between these?
CComBSTR a[256]; //note: square brackets
CComBSTR b(256); //note: parenthesis
|
|
|
|
|
Like2Byte wrote: CComBSTR a[256]; //note: square brackets
It is array of CComBSTR . 256 elements.
Like2Byte wrote: CComBSTR b(256); //note: parenthesis
It is a single CComBSTR object, initialized to initial character size of 256.
|
|
|
|
|
Thanks, Prasad!
That makes things clearer for me.
|
|
|
|
|
Hi.
The application I coded is ATL/WTL windows app, now everything is fine in debug, when I compile it in release it compiles with no errors, however strings for label and other controls are cut off, it shows like only the first letter or nothing.
I get the strings from string table in the local resource, and it works fine in debug mode, I also checked the encoding and it is MBCS defined in both release and debug versions.
What can cause this behavior?
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
Check if you have missed any setting.
Have a look at difference betn debug and release[^] for possible cause. Though this article may not be very useful in this context, but may be you get some idea.
|
|
|
|
|
Thanks, but nothing to help me there, as it pertains mainly to MFC programming. I think I will have to go through Michael Dunn's article about string encodings, hope to find something useful there.
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
It's likely that you've not initialised a variable - when I've had Release/Debug issues, that's what it's usually been.
I always make sure that I include Debug information in Release builds - that way I can use the debugger with Release builds reasonably meaningfully - as long as you keep optimisations turned on and you use the Release version of the C run-time, you've still got a Release build.
|
|
|
|
|
Thanks, I'll give it a try. I am not sure about having debug info in the release build, but I will use it at least for the sake of finding out what the problem is.
Thank you.
Sarajevo, Bosnia
|
|
|
|
|
Some more info - the debug info will be held separately (in a PDB file), so there is a) no symbol information exposed in the EXE, and b) little change in size in the EXE.
|
|
|
|
|
Hi all!
I'm relatively new to templates and am rapidly learning.. However VC 2005 is giving me fits on type checking STL vs. my old VC 6 compiler.
I have a vector defined: std::vector<char> _iBuff;
With what I want to do, I need access to _iBuff.begin() but if I for example say:
char *b = _iBuff.begin();
I get:
error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'char'
with
[
_Ty=char,
_Alloc=std::allocator<char>
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
What am I doing wrong? .begin() should return a (char *), or at least I think it should.
Thanks in advance!
|
|
|
|
|
An iterator is not a pointer to an element. VC6 let you do that, but it was always wrong to use iterators that way. Do this:
char* b = &_iBuff.front();
|
|
|
|
|
Mike,
Thanks a million, that did the trick. I should have looked deeper into <vector>, once I looked at the function for .front() it made sense...
Again, my thanks!
|
|
|
|
|
Or do this:
char* b = &(*_iBuff.begin()); as Mike's suggestion to use front() isn't always applicable (such as when you're dealing with an arbitrary iterator).
|
|
|
|
|
Hi everybody. Can somebody please help me with this?
I have a dialog that I use embedded in the tab control, that is on the main dialog. I want to send a user defined message (or is there a better way?) to notify the parent dialog to hide-show itself. How do I go about this?
Thanks.
|
|
|
|
|
You send a user defined message using SendMessage() or PostMessage() . You define a message using #define .
|
|
|
|
|
Thanks, I know that. But the parent dialog does not intercept the message, as I have REFLECT_NOTIFICATIONS defined, so it doesn't work.
|
|
|
|
|
Why don't you get rid of REFLECT_NOTIFICATIONS?
|
|
|
|
|
I can not, because I am using a derived class to embed my dialog class into the tab control, so I need to reflect the messages.
Thanks.
|
|
|
|
|
Define a message ID in the WM_APP range, like this:
#define UWM_SHOW_HIDE_MAIN_WINDOW WM_APP Then in your child dialog:
GetTopLevelParent().SendMessage(WM_APP, show_or_hide_flag); Or you could break it into two messages, one for showing and one for hiding. Handle UWM_SHOW_HIDE_MAIN_WINDOW in your main dialog's message map and show/hide the window accordingly.
|
|
|
|
|
Thanks Mike,
you are as helpful as always. I ran through all of your articles about WTL, but couldn't figure this GetTopLevelParent() out. Thank again.
|
|
|
|
|
I'm using VC 2005, and WTL 7.5. And I cannot for the life of me get intellisense to work with the WTL classes. Has anyone had any luck with this?
Cheers,
- Dan
|
|
|
|