|
What Luc said, plus consider using BeginDeferWindowPos() , DeferWindowPos() , EndDeferWindowPos() in your WM_SIZE handler. These APIs allow you to accumulate the movement of multiple windows (controls), and them update them all when the repositioning is finished.
|
|
|
|
|
Hi all,
I want to convert a CString variable to unsigned long long . I know for long we can do it using api atol(long);
but what to use for unsigned long long...
Anybody please help
modified on Tuesday, May 17, 2011 3:44 AM
|
|
|
|
|
|
Yes, but he wants string to long long.
The best things in life are not things.
|
|
|
|
|
I would guess you probably need this[^].
The best things in life are not things.
|
|
|
|
|
|
Hi friends,
I have written simple program of adding and removing columns from using CListCtrl of MFC.
Behavior of the application:
1. When Add button is clicked, its adds 1000 columns to the List control.
2. When Remove Button is clicked it removes the last added 1000 columns from the List Control.
So, when 1000 columns are added to the List Control using InsertColumn() function of MFC, memory usages increased by certain amount(For e.g Say by 500KB), but when we remove the added 1000 columns from the List Control using DeleteColumn() function, the memory is not freed as it was added during the addition of 1000 columns(Only 300KB is freed, resulting in 200KB of Memory Leak).
Create the sample MFC Application and use the below code.
ListControlDlg.cpp
void CListControlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST, m_List);
}
BEGIN_MESSAGE_MAP(CListControlDlg, CDialog)
.
.
.
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedAdd)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedRemove)
END_MESSAGE_MAP()
BOOL CListControlDlg::OnInitDialog()
{
.
.
.
m_Count = 1;
}
void CListControlDlg::OnBnClickedAdd()
{
int max_limit = m_Count + 1000;
CString columnstr = "Column";
CString Columnno = "";
for (int i = m_Count; i <= max_limit; i++)
{
Columnno.Format("%d", i);
CString columnstrTemp = columnstr + Columnno;
m_List.InsertColumn(i, columnstrTemp, LVCFMT_LEFT, 80);
}
m_Count = max_limit;
}
void CListControlDlg::OnBnClickedRemove()
{
int max_limit = m_Count - 1000;
CString columnstr = "Column";
CString Columnno = "";
for (int i = m_Count; i >= max_limit - 1; i--)
{
Columnno.Format("%d", i);
CString columnstrTemp = columnstr + Columnno;
m_List.DeleteColumn(i);
}
m_Count = max_limit;
}
CListControlDlg.h
class CListControlDlg : public CDialog
{
.
.
.
.
private:
CListCtrl m_List;
int m_Count;
public:
afx_msg void OnBnClickedAdd();
afx_msg void OnBnClickedRemove();
}
ListControl.rc
IDD_LISTCONTROL_DIALOG DIALOGEX 0, 0, 501, 289
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_MAXIMIZEBOX |
WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,444,7,50,16
PUSHBUTTON "Cancel",IDCANCEL,389,7,50,16
CTEXT "TODO: Place dialog controls here.",IDC_STATIC,7,174,300,
8
CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT |
WS_BORDER | WS_TABSTOP,27,30,454,236,WS_EX_CLIENTEDGE |
WS_EX_LEFTSCROLLBAR
PUSHBUTTON "Add",IDC_BUTTON1,247,7,50,14
PUSHBUTTON "Remove",IDC_BUTTON2,311,7,50,14
END
Abhijit Satpute.
|
|
|
|
|
[The following assumes that you don't have a mismatched new/free somewhere in your code.]
The way this was explained to me, Windows uses a virtual memory concept to allocate/release in chunks of 'pages' 4096 bytes long. Small memory blocks will come from local heap and it is always in physical memory - this is why freeing memory is not "visible" in Task Manager. Large memory blocks will require additional pages to be allocated, and freeing that memory will be visible.
If you want to dig more deeply into this, there are several excellent articles on leak detection here on CodeProject.
You could also experiment by allocating a large block, waiting 10 seconds, then freeing the block while you are watching Task Manager.
|
|
|
|
|
Thanks for your reply.
Can you recommend any tool(other than Task Manager) which can give detailed memory status of the application?
Best Regards,
Abhijit Satpute
|
|
|
|
|
|
Thank you very much Hans.
Regards,
Abhijit
|
|
|
|
|
Abhijit_Satpute wrote: So, when 1000 columns are added to the List Control using InsertColumn() function of MFC, memory usages increased by certain amount(For e.g Say by 500KB), but when we remove the added 1000 columns from the List Control using DeleteColumn() function, the memory is not freed...
How are you verifying this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
With the help of Task manager. The application memory increases and decreases when we add and delete columns respectively.
Regards,
Abhijit
|
|
|
|
|
Abhijit_Satpute wrote: With the help of Task manager.
Not a good choice. TM does not tell you how much memory your program is using, but the amount of address space that is in use, which differs from the amount of that address space your program is actually using.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
So please suggest me some good tool which can tell me exact memory used by my application.
Regards,
Abhijit
|
|
|
|
|
Abhijit_Satpute wrote: So please suggest me some good tool which can tell me exact memory used by my application.
In all sincerity, why do you think you need to know this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
My japanese client is using Task Manager to see the memory. So i need to convince him that it is not a memory leak.
Japanese clients are very hard to convince.
Regards,
Abhijit
|
|
|
|
|
Hello,
I wanted to create an application in which I wanted to start my application at specific time, say I wanted to start my application at every 3 PM. If my computer is not on at 3 PM, I must be able to start it on later time as well.
I using VC++/MFC application.
Happy Programming.
|
|
|
|
|
It would be simpler to use the Windows Task Scheduler.
The best things in life are not things.
|
|
|
|
|
I have tried to use various examples finding Windows Scheduler with VC++. But almost every application give one or other COM exception. Can I have a link or example which shows use of windows scheduler with VC++/MFC.
Here are some links I have tried,
http://msdn.microsoft.com/en-us/library/aa381915(v=vs.85).aspx[^]
http://msdn.microsoft.com/en-us/library/aa446855(v=vs.85).aspx[^]
In second example I am getting exception in
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test App";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);
pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
|
|
|
|
|
I meant use Task Scheduler instead of writing a program.
The best things in life are not things.
|
|
|
|
|
I meant use Task Scheduler instead of writing a program.
That would be the best choice if I am making application for myself. I wanted to create Application.
Regards
|
|
|
|
|
Reason : Please read the first line of example.
"This example attempts to run an existing task. This example assumes that the task and the test task already exist on the local computer."
Check this
http://msdn.microsoft.com/en-us/magazine/cc163350.aspx
"Every Little Smile can touch Somebody's Heart...
May we find Hundreds of Reasons to Smile Everyday... and
May WE be the Reason for someone else to smile always!" (ICAN)
|
|
|
|
|
Hi Shilpi,
Actually I used Notepad.exe as well, but got exception. Then I tried chrome.exe, though Chrome Browser running on my system. But doesn't work.
Regards
|
|
|
|
|
Did you manually add the Scheduled task of notepad and chrome ??
Go to control panel -> Scheduled task -> Add Scheduled task and than check for this task using your code.
"Every Little Smile can touch Somebody's Heart...
May we find Hundreds of Reasons to Smile Everyday... and
May WE be the Reason for someone else to smile always!" (ICAN)
|
|
|
|
|