|
I new a CItemData object for each item of CListCtrl, what is the proper place to delete them when program ends.
I tried CMyListCtrl's destructor and DestroyWindow, it doesn't work (memory leak)
|
|
|
|
|
|
Must add it before the default CListCtrl::OnDestroy.
|
|
|
|
|
If you are storing the pointer for the CItemData by using SetItemData() method then you should handle the LVN_DELETEITEM message. This message is called once for each item in the list control.
Kelly Herald
Software Developer
MPC
|
|
|
|
|
You are right, if that notification is sent for every item on control destruction, then it would be a better solution, because it would work when you ask to remove individual items from the list too.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
At the point of dealing with LVN_DELETEITEM, has the item been deleted? I can't delete the point whose value is returned by GetItemData.
|
|
|
|
|
In the LVN_DELETEITEM handler you don't use GetItemData because the LPARAM is already passed in through the NMHDR pointer. You need to cast it to a NMLISTVIEW pointer. Here is an example:
void CMyDlg::OnLvnDeleteitem(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
MY_DATA_TYPE pData = reinterpret_cast<MY_DATA_TYPE>(pNMLV->lParam);
if (pData != NULL)
delete pData;
}
This gets called for each item in the list control whether you are just removing a single item from the list control or if the window is being destroyed. Be sure to read the MSDN for more information on this notification message.
Kelly Herald
Software Developer
MPC
|
|
|
|
|
Hello all,
I have a function - UpdateTimes() - that connected to SQL server. It will increases the Times value in my database if this value less than 5.
The code like this:
void UpdateTimes()
{
CDatabase m_Db;
CRecordset m_Rs(&m_Db);
m_Db.OpenEx(_T("DSN=MyData;UID=sa;PWD=sa"),0);
CString sSQL_Sel = "SELECT ConID,ChkTimes FROM tblList";
m_Rs.Open(CRecordset::forwardOnly, _T(sSQL_Sel));
while (!m_Rs.IsEOF())
{
short ind = 0;
CString sID;
m_Rs.GetFieldValue(ind, sID);
ind = 1;
CDBVariant varTimes;
m_Rs.GetFieldValue(ind, varTimes);
if (varID.m_iVal <= 5)
{
varID.m_iVal ++;
CString sTemp;
sTemp.Format("%d", varTimes.m_iVal);
CString sSQL_Upd = "UPDATE tblList SET [ChkTimes] = " + sTemp + " WHERE ConID like '" + sID + "'";
m_Db.ExecuteSQL(sSQL_Upd);
}
m_Rs.MoveNext();
}
m_Rs.Close();
m_Db.Close();
}
If my database has only 1 record, this code is OK. But if I have more than 2 records, it has an error message, say "Connection is busy ...".
So do you have another way to do it? Pls help me ...
Thank you very much.
|
|
|
|
|
Using ODBC with SQL Server means you need to be aware that only one record set can be used per connection. If there's one record, when you've read it, there are no more records and the connection can be reused, whereas if there are two or more, it's still busy, and you can't reuse it, but you can use a second (hint).
Alternatively, for what you're doing
"UPDATE tblList Set [ChkTimes] = [ChkTimes] + 1 WHERE [ChkTimes] <= 5"
which is much more efficient, as almost all the work is done by the server, eliminating the need to transfer data backwards and forwards.
Steve S
Developer for hire!
|
|
|
|
|
|
|
For a CWnd you could use (GetScrollBarCtrl() != NULL)
Update: it should be GetScrollBarCtrl(SB_HORZ) or GetScrollBarCtrl(SB_VERT) and it only works for CView and derived classes.
For what kind of window do you need it?
--
jlr
http://jlamas.blogspot.com/[^]
-- modified at 1:23 Monday 5th September, 2005
|
|
|
|
|
|
If you mean how to know if the number of items exceeds the amount of visible items you could use:
(GetItemCount() > GetCountPerPage())
You may also try ApproximateViewRect and compare it to the control dimensions
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I used the first method,(GetItemCount() > GetCountPerPage()),it works perfectly.
|
|
|
|
|
Hi all,
I wanna play *.rm file use MCI!! Can I do it?
If can't ,What should I use ?
Thank you so much.
do it.
|
|
|
|
|
You need realplayer to play .rm files. WMP can't do it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm supposed to make a program that does infix to postfix and prints each, as well as the value of the expression.
Here's my code: http://www.straightlyrics.com/postfix.cpp
Here's a sample data set: http://www.straightlyrics.com/data
The problem lies in where it does the 2 * 6 / 2 + 5 expression.
It outputs the postfix as 2 6 2 / 5 + *
I think it is supposed to be 2 6 2 / * 5 + but I don't know what is causing it to mess up.
By the way, for this program, order of operations are different. / has highest priority, followed by * and + which are equial, then - is last. all operations are supposed to work left to right, except -, which goes right to left.
|
|
|
|
|
Check the order of priority for the operators in your code. Based on that priority The Code is giving the result.
Nice talking to you.
|
|
|
|
|
Hello,
I am having a weird problem with a list view control (CListCtrl) in MFC. I can create it but for some reason I can't add an item to it. When I call the controls InsertItem function, it returns -1, which according to the MFC documentation means that adding the item to the list view was unsuccessful. I know this from running this code:
folderContents.Create(WS_VISIBLE|WS_CHILD|WS_BORDER|<br />
LVS_LIST|LVS_SINGLESEL,<br />
CRect(10,10,300,180), this, <br />
IDC_FOLDERCONTENTS);<br />
<br />
LV_ITEM lvItem;<br />
lvItem.mask = LVIF_TEXT|LVIF_STATE;<br />
lvItem.state = 0;<br />
lvItem.stateMask = 0;<br />
lvItem.pszText = "an item";<br />
lvItem.iItem = 0;<br />
<br />
if(folderContents.InsertItem(&lvItem) == -1)<br />
{<br />
COLORREF c = PALETTERGB(150, 90, 130);<br />
folderContents.SetBkColor(c);<br />
}
When I run the application, backgound color of the list view (named folderContents in above code) is changed. So why cant InsertItem add an item to the list view? There is no explanation in the documentation. Anybody know?
TraileR ParK LifE 4Ever
|
|
|
|
|
The LV_ITEM structure contains a lot of info apart from what you're specifying, and it's all full of random data when you create one. If you add this line:
::memset(&lvItem, 0, sizeof(LV_ITEM));
before setting any values, it works ( I just tried it )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Wow! Thanks a lot! I did not know about this function.
TraileR ParK LifE 4Ever
|
|
|
|
|
I need an advice. For the last weeks I do a lot of Java with the NETBeans IDE. It has some neat features,
like creating the get and set methods automaticaly. Does anyone know about a extention for the VC7 IDE , that can do the
same? (auto generate GET and SET handlers, create overrides for pure virtual methods and so on)
It should be for C++ (thats why I used this forum)
thank you.
|
|
|
|
|
VS2005 has all of this built in for C# and VB.NET, but sadly, not for C++. I reckon once it hits the market, there will be a real call for this stuff in the C++ IDE, and some products will come out to support it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Quote from Microsoft:
"You receive a "This application has requested the Runtime to terminate it in an unusual way" error message when you run a custom Microsoft Visual C++ 6.0 program in Windows XP
View products that this article applies to.
Article ID : 884538
Last Review : May 3, 2005
Revision : 2.1
SYMPTOMS
When you run your custom Microsoft Visual C++ 6.0 program in Microsoft Windows XP, you may receive the following error message:
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
CAUSE
This problem may occur when you use the /GR and the /MD compiler switches, and the version of the Msvcrt.dll file and of the Msvcirt.dll file is 7.0.x.
Note This problem does not occur when you use a version of the Msvcrt.dll file and of the Msvcirt.dll file that is earlier than 7.0.
RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Windows XP service pack that contains this hotfix.
To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=support (http://support.microsoft.com/contactus/?ws=support)
Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.
Prerequisites
There are no prerequisites for installing this hotfix package.
Restart information
You must restart your computer after you apply this hotfix.
Hotfix replacement information
This hotfix does not replace any earlier hotfix.
Hotfix file information
The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel. Date Time Version Size File name
------------------------------------------------------
20-Oct-2004 22:59 7.0.2600.2534 57,344 Msvcirt.dll
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section " quote ends.
Found at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;884538#appliesto
Anyone who knows what this means? I'm trying to launch IExplorer.exe in Program Files section
I have Windows Pro SP2 installed and everything else is working! Also Visual studio 6.0 installed,
I will be most grateful of any answers on this matter
|
|
|
|