|
May be I did not put my question correctly.
let me put it like this.... I have a CMap
CMap<CString,LPCSTR,CString,CString&> map;
with <key1, value1="">,<key2, Value2>......
I have a combo box cmb, now I want to do some thing like
for(int j=0;j<map.GetCount();j++)
{
cmb.AddString(map[i]);
}
and now the combo should contina key1, key2.key3......
|
|
|
|
|
can't u do like
POSITION pos = map.GetStartPosition();
CString csKey, csValue;
while(pos)
{
map.GetNextAssoc(pos, csKey, csValue);
cmb.AddString(csKey);
}
|
|
|
|
|
I worked, thank you.... but was more worried about the the key value that need to be passed.
But passing the dummy key value as per ur advice worked.
Thanks
|
|
|
|
|
if you don't need values, i mean only keys, why don't you use classes like CStringArray or CList instead of CMap for that purpose?
Have a look at CComboBox::SetItemData() and GetItemData(), using which u can map a value (which can be an index or pointer to a structure or anything) to each item added to combo box.
|
|
|
|
|
Well I mean, I dont need values to fill the combo. later in business logic I need to pick the associated value on SelectCombo depending on value selected, so i need a map
|
|
|
|
|
Ya I got your point, I am using as below
// setting
while( pos )
{
appConfig.m_map.GetNextAssoc(pos, strKey, strValue);
cmb.AddString(strKey);
appConfig.m_map.Lookup( strKey, strValue );
cmb.SetItemData(iCount,(DWORD)(LPCTSTR)strValue );
iCount++;
}
temp = cmb.GetItemData( index );
CString str= (CString *) temp;
but I was unable to get the stored vaule, getting 0 in temp. can you please help me
|
|
|
|
|
strValue is just a local variable, and changing inside the loop too. No meaning in storing its address as combo box item's data.
You are keeping key-value pair in combo box, so you can get the value any time by calling
CString strKey;
cmb.GetLBText( index, strKey );
CString strValue;
appConfig.m_map.Lookup( strKey, strValue );
//got strValur
isn't it enough?
|
|
|
|
|
ok I reverted back to my code again, Thanks for your help
|
|
|
|
|
hello, i'm having a hard time figuring out how to insert a character/string on my CFile,
i have no problem writing the character set at the end or at the beginning of the file, but when i try to add it in between, it overwrites the file.
Example:
i have "JON SMITH" on my file, when i try to insert "H" at index 2, it should look like this "JOHN SMITH", but what happens is this "JOH SMITH" it overwrites, it does not insert.
here is my code
CString txtInsert;
m_txtInsert.GetWindowText(txtInsert);
int szSize = txtInsert.GetLength();
if (!cfile_object.Open(l_ExePath + "Logs\\cfile_example.txt", CFile::modeWrite))
{
AfxMessageBox(_T("Cannot Open File for Reading!\nPls. Check Directory of File!"));
}
else
{
cfile_object.Seek( 2, CFile::begin );
cfile_object.Write(txtInsert, szSize);
cfile_object.Close();
i needed to type "H SMITH" just to get the result "JOHN SMITH" but all i want is the insert the character "H" on the right place..
any help or hints will be much appreciated, thankyou
|
|
|
|
|
File I/O does not work this way, you can only overwrite the data that is already there. You can also add more information at the end by appending data to the existing file. However, if you want to modify what is already there then you must read it in, modify the contents in memory and write out the new information, either to the original, thus overwriting it, or to a new file.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
resolution:
READ from whatever starting pointing from your file, save to buffer, then add whatever character you want at the beginning of the buffer. then WRITE the buffer to your file, this way you can insert...
cfile_object.Seek( insIndex, CFile::begin );
int flen = cfile_object.GetLength();
char *fBuf= new char[flen];
UINT file = cfile_object.Read(fBuf,flen);
fBuf[file] = '\0';
txtInsert = txtInsert + fBuf;
cfile_object.Seek( insIndex, CFile::begin );
cfile_object.Write(txtInsert, szSize + file);
cfile_object.Close();
modified on Tuesday, September 28, 2010 2:53 AM
|
|
|
|
|
As I explained in my previous answer there is no 'insert' facility in file I/O, it has to be implemented by reading the data into memory, modifying the memory buffer(s) and rewriting all of the file from the point of insertion.
The line
fBuf[file] = '\0';
will cause random memory corruption.
I am not sure what the line
txtInsert = txtInsert + fBuf;
is supposed to do, but I doubt that it is what you expect.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Well i have to agree with everything that you have written, i am totally new in visual C++... unlike the .NET that i came from, coding is more easier there, but MFC just gives me what i needed, MFC gives me "CONTROL OVER MY CODE"
i am very thankful about your comments, i got a good hint how to control my Project...
thanks a lot for posting,.
the bigger problem that i face now is how to SORT the record on the CFile., i needed real time sorting for my main project.. every-time a user input is made, the record should be automatically sorted A-Z..
how to sort:
BANANA
APPLE
ORANGE
MANGO
PINEAPPLE
and i got NO idea how to do that, any help would be very much appreciated
|
|
|
|
|
loid grey manuel wrote: i got NO idea how to do that
Well, this is the place we all had to start from, but it does require you to spend some time learning. If you are serious about writing C++ programs then you should learn some of the features that come with it, such as the Standard C++ Library[^]. There are also lots of useful classes in MFC if you are using those libraries; Here[^] is an article that should help you with your sorting problem. In either (or both) case(s) you should get familiar with the MSDN[^] site to help you find answers to many of the problems you will meet on the way.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I am calling HttpOpenRequest API in BHO code. Which is works correctly in
IE6,IE7 and IE8. But HttpOpenRequest failed on IE9.
I am calling it as
d_hHTTPRequest=::HttpOpenRequest(d_hHTTPConnection,
"GET", // HTTP Verb
a_szURI, // Object Name
"HTTP/1.0", // Version
"", // Reference
&szAcceptType, // Accept Type
dwFlag,
0); // context call-back point
Is there any change required for IE9 while using HttpOpenRequest API.
|
|
|
|
|
you might find you get a better result if you explains this
am 2009 wrote: But HttpOpenRequest failed on IE9
a bit more - what was the failure/how did it manifest itself (etc) ... oh, and, please put code inbetween the correct tags to make it more readable - <pre> </pre> or simply use 'code block' from the message editor
'g'
|
|
|
|
|
I am calling win32 HttpOpenRequest API in my ATL COM code. It failed when called HttpOpenRequest. This is ATL COM win32 windows application hence there is not any refereence of
and
tag.
|
|
|
|
|
am 2009 wrote: This is ATL COM win32 windows application hence there is not any refereence of
I meant, when you post code on this forum for others to read, put it in the correct tags
am 2009 wrote: It failed when called HttpOpenRequest
so you have said - you still have not answered what error code it fails with - so no one here can help you since they cannot guess what is happening
'g'
|
|
|
|
|
d_hHTTPRequest=::HttpOpenRequest(d_hHTTPConnection,"GET",a_szURI,HTTP_VERSION ," ",&szAcceptType,dwFlag,0);
Above code is failed in IE9
|
|
|
|
|
you keep missing this VERY IMPORTANT POINT
WHAT DID THE CODE FAIL WITH ?
WHAT WAS THE ERROR CODE ??
|
|
|
|
|
Hi,
Actually i HttpOpenRequest() function failed, i,e. application crash,hence
GetLastError() not called. Before caliing GetLastError() code crash. This is happened with only IE9. otherwise code runs correctly on IE7 and IE8.
|
|
|
|
|
Anyone holds info about native
c++ implementation of delegates
in the upcoming C++0x standard ?
just curious...
|
|
|
|
|
|
Actually, my question stems from some articles
published in codeproject about "fast" c++ delegates
and the innards of pointers to member functions
(i.e. methods).
A functor is probably not resembling this. The most
significant contribution is Boost.Function and Signals.
As there has been significant discussion of the
memory usage of Boost.Function and how to improve it,
I was curious about the standard, as many parts
of boost are under review to be included in the
standard.
Cheers
|
|
|
|
|
I'm writing a plug-in for an NLE, and I wish to forcibly resize my window to fill the area that is available. The PlugInPP class is defined as such:
class ATL_NO_VTABLE CPluginPP :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CPluginPP, &CLSID_PluginPP>,
public IPropertyPageImpl<CPluginPP>,
public CDialogImpl<CPluginPP>
In order to get the sizing messages for the parent window, I have sub-classed it, and when I see a WM_SIZE message, I do the following:
::MoveWindow( Main_zMappingArray[ 0 ].hDialogWnd,
0,
0,
LOWORD( lParam ),
HIWORD( lParam ),
TRUE );
My PlugInPP::OnSize method gets called with the new size, no problem there. However, there is immediately another WM_SIZE message setting back the original sizes or the dialog resource.
I'm beginning to think that the silly buggers have subclassed the PlugInPP window and resize it whenever they see a WM_SIZE message, but that seems like an awful lot of work to do in a situation where the window is by no means resize-able.
Give the ATL::CDialogIMpl and ATL::IPropertyPageImpl base classes, I'm wondering if there's a trick to resizing them, or a trick to preventing them from being resized that I can opt out of.
Otherwise, I guess I'm stuck with subclassing my own window again, and just eating the WM_SIZE messages, and hope that works.
CraigL
|
|
|
|
|