|
I can sort of make this work, by putting the owner-draw list box 'full-screen' on a borderless dialog (ick!) and then positioning that. But then I run into problems dismissing the dialog when the user clicks off it, and sorting out where the messages go. It would be nicer and neater if the dynamic way worked...
|
|
|
|
|
Hi,
I need to customize a CMFCPropertyGrid such that be able to display a simple button inside.
when user selects given grid, user can press button inside and then a dialog box will be displayed!
exactly like Folder dialog box.
how can i do this?
best regards
|
|
|
|
|
Can you pls help to How to associate CMap key value to CComboBox MFC
Thanks in advance.
|
|
|
|
|
its not possible to store CComboBox objects into CMap or CList since copy constructor for CComboBox is not available. However you may do it as,
CMap<int, int, CComboBox*, CComboBox*> m_map;
sample to store data
CComboBox *pBox = new CComboBox();
CRect rc(0, 0, 100, 50);
UINT nId = 100;
pBox->Create(SW_HIDE, rc, this, nId);
m_map[m_id] = pBox;
modified on Monday, September 27, 2010 11:24 PM
|
|
|
|
|
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.
|
|
|
|
|