|
Hello,
I have a function that returns several strings. This function is run over and over again many times. I would like to store all the returned strings in an array. I'm assuming that I have to use a struct. But, how do I get the values inside by index after its created. In VB (yea, i know.) It would be something like this:
Private Type StrData
String1 as string
String2 as String
End Type
Then to access the array it would be something like this:
rtn = StrData.String1(0)
So, how do I convert this to C++ and MFC?
Thanks!
Frank
|
|
|
|
|
I don't understand what rtn = StrData.String1(0) means exactly. What is the (0) there for? "String1" isn't an array.
Anyway, to make a typedef'd struct:
typedef struct
{
CString String1, String2;
} StrData;
To make an array of those, you can use a linked list (since it sounds like you don't know exactly how many structs you'll have). Use std::list<StrData> in STL, or CList<StrData, StrData&> in MFC.
|
|
|
|
|
Thanks Mike. In VB, rtn = StrData.String1(0) the (0) is the index of the n'th (where n is just a number) String1 object contained in the data type StrData. (I think)
I'm afraid I'm new to using "Linked Lists". Could you expand a bit on the usage in MFC? What do I do with the code CList<strdata, strdata&="">.
Thanks again,
Frank
|
|
|
|
|
See: http://home.socal.rr.com/samhobbs/VC/Collections.html
CStringList is really easy to use but the MFC documentation is not. I hope the example in the above page is easy though.
|
|
|
|
|
I am trying to disable two tabs that exist on a tab control with 7 total tabs. Is there anyway to disable specific tabs on with a CTabCtrl object.
|
|
|
|
|
Here are two resources for you to get the answer you want.
1. Search MSDN online (msdn.microsoft.com) for article ID: Q151662 "How To Disable Tabs in CPropertySheet"
And...
2. Paul DiLascia has an article in the March 98 issue of MSJ that covers this topic in entirety. You can search MSDN for that specific issue.
Hope that helps!
Frank
|
|
|
|
|
Can I find this article on-line? If so, where at.
|
|
|
|
|
You can search msdn at http://msdn.microsoft.com/
You can find the source code for the march issue of msdn at http://www.microsoft.com/MSJ/0398/code/MSJmar98.zip
And you can find the actual article that Paul wrote in the March 1998 issue at
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0398/c++0398.htm
(Long URLs probably wrapped).
Hope that helps.
Frank
|
|
|
|
|
Well, folks, here we are four years down the road, and I come along (after much searching) looking for the answer to the same question that Roger had - namely, how to disable m tabs in an n-tab control (where m < n).
Unfortunately, the links given above no longer exist, which highlights the fact that it would've been nice if some clues had been given by the responder in addition to simply referencing the links.
Oh well.... another dead-end....
|
|
|
|
|
How do I develop a solution to enable spell checking on a text box using Win 32 SDK.
Looking for a ideal solution.
Thanks
Siva
|
|
|
|
|
oYou could automate Microsoft Word. Look in MSDN somewhere I think.....
|
|
|
|
|
Following code works well when compiled with Microsoft c-compiler :
j = 0;
j = (j < 1) ? j++ : 0;
--> result j = 1
When compiled with Microsoft c++ compiler
--> result = 0 (wrong)
Can somebody explain this?
|
|
|
|
|
0 is correct, use ++j if you want j to be incremented before being assigned back to itself.
You get 0 because C++ create a temporary (j) variable and increments it (and discards it in this case),
where as C doesn't bother (I think).
|
|
|
|
|
Well, the correct answer is 0. The assignment reduces to:
j = j++;
Since j++ evaluates to 0, 0 gets stuffed in j.
This is really bad programming practice, though. I hope you don't plan on writing production code this way.
|
|
|
|
|
How do I scan a registry folder?
|
|
|
|
|
Take a look at RegEnumKeyEx.
Also check help for 'Registry Functions'
regards,
Louis.
|
|
|
|
|
I am writeing a windows program that runs a file i/o function that takes a while to run, and I can't figure out how to make it update the programs window while it is running the funtion. How do I get it to run the window's window procedure in the middle of the function? (I think that is what I have to do..)
This is probably a really easy thing to fix, but I can't figure it out.
BTW this is a dialog based program (a dialog made in the resource editor) if that makes any difference..
Any help would be greatly appreciated.
Thank You.
|
|
|
|
|
Hi!
Put the following function into your dialog class
and call it in the file i/o loop. This will ensure
that the window messages are correctly disptached.
void CYourDialog::PumpMessages()
{
static MSG msg;
if( GetSafeHwnd() != NULL )
{
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( !IsDialogMessage( &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}
}
HTH
Holger Persch
|
|
|
|
|
|
Hi.
It looks like I am missing NAFXCWD.LIB and gets some linker errors.
Can anyone be so kind to mail me this file or tell me where to find it.
Email: patrik.andersson@kvarnstrands.se
Regards
Patrik
|
|
|
|
|
That's one of the MFC statically-linked libs. Just grab it off your VC CD and copy it to <vc6 install="" dir="">VC98\MFC\LIB.
|
|
|
|
|
I'm having a weird problem where my CListCtrl doesn't show all the items that I load in it. I'm using
a function to load the control initially using LVITEM with InsertItem() followed by SetItem() for all
subitems, and this part works.
However, as the program is running I have to update the listctrl so I call ResetContent() to clear the rows
and then call the initialize function mentioned above to reload everything. The problem is that when I
do this, only the first item shows up in every row. Usually the subitems are blank in most of the rows.
Some rows do show up correctly, but this is only on a few rows. When I say correctly I mean all
subitems are shown with the main row item. Can someone help me with this?
Thanks in advance,
--Trey
|
|
|
|
|
Hi Trey,
Very weird! Maybe there's a bug in the initializing function... Can you provide some code?
Paolo.
|
|
|
|
|
Ok, I have a database objectthat has two vectors of CStrings. I update the database and then call LoadListData(). Like I said before this is weird!
Here is the code to initialize the data:
void CMyDlg::LoadListData(CDatabase* database)
{
// Delete the current contents
m_cListCtrl.DeleteAllItems();
// Use the LV_ITEM structure to insert the items
LVITEM lvi;
lvi.mask = LVIF_TEXT;
CString strItem;
int numberOfAddresses = database->GetAddressCount();
for (int i = 0; i < numberOfAddresses; i++)
{
//*
CAddress* a = database->GetAddress(i);
// Filter if necessary
if(m_bFilterOn && a->m_csCategory != m_csFilterCategory)
continue;
// Insert the first item - First Name
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csFName);
m_cListCtrl.InsertItem(&lvi);
// Set subitem 1 - Last Name
lvi.iSubItem = 1;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csLName);
m_cListCtrl.SetItem(&lvi);
// Set subitem 2 - Company
lvi.iSubItem = 2;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csCompany);
m_cListCtrl.SetItem(&lvi);
// Set subitem 3 - Address 1
lvi.iSubItem = 3;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csAddress1);
m_cListCtrl.SetItem(&lvi);
// Set subitem 4 - Address 2
lvi.iSubItem = 4;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csAddress2);
m_cListCtrl.SetItem(&lvi);
// Set subitem 5 - City
lvi.iSubItem = 5;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csCity);
m_cListCtrl.SetItem(&lvi);
// Set subitem 6 - State
lvi.iSubItem = 6;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csState);
m_cListCtrl.SetItem(&lvi);
// Set subitem 7 - Zipcode
lvi.iSubItem = 7;
lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csZipcode);
}
}
|
|
|
|
|
Well, what I can see is: it lacks the last SetItem.
For ther rest it seems OK.
Try doing ASSERTs on the return value of each SetItem and go with the Debug version.
Also, you may try to add:
ZeroMemory(&lvi, sizeof(LVITEM));
just after the definition.
I found that sometimes this could help... or does nothing
Paolo.
|
|
|
|