|
Hi,
i have done an mdi application in which all views will have bitmaps as background. I am attaching bitmaps in Onpaint() function of all views.In some view classes i am creating font every time i am calling onpaint function.
this is the code
void CMyView::OnPaint()
{
CPaintDC dc(this); // device context for painting
AttachBitmap(IDB_USERNAME, &dc, CRect(631,23,766,58));
CFont fFont;
CFont *fOldFont;
if(fFont.CreateFont(11,0,0,0, FW_BLACK ,false, false, false, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Tahoma")!=NULL)
{
fOldFont = dc.SelectObject(&fFont);
}
}
this is attachbmp function
BOOL AttachBitmap(UINT sBMPFile, CDC *pDC, CRect rect)
{
CDC memDC;
CBitmap cBitmap;
CBitmap* pOldMemBmp = NULL;
if(!cBitmap.LoadBitmap(sBMPFile))
AfxMessageBox("ting");
memDC.CreateCompatibleDC(pDC);
pOldMemBmp = memDC.SelectObject(&cBitmap);
BITMAP bmpInfo;
cBitmap.GetBitmap(&bmpInfo);
TransparentBlt(pDC->GetSafeHdc(), rect.left, rect.top, rect.Width(), rect.Height(),
memDC.GetSafeHdc(), 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight,COLORREF(RGB(0,255,0)));
if (pOldMemBmp) pDC->SelectObject(pOldMemBmp);
return TRUE;
}
these functions are used in almost all views of my mdi application.
Problem is that after running application for more than oneday.. bitmaps are getting disappeared and system is showing virtual memory of your system is low. and a warning appears as font cannot be created .. what could be the reason? any help is appreciated.
thank you
chaitu
|
|
|
|
|
This means you're leaking memory. The GDI memory you're leaking is the bitmap itself, I believe. Why do you load it every time ? Make it a member variable, so you load it only once, that just makes sense.
Either way, I'm not sure if that solves the core issue, but it might, it will sure simplify the code. But, somewhere in your app, you are leaking GDI resources, and you're running out.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi graus ,
thanks for your reply, i will try that..
|
|
|
|
|
I have created dsn at runtime but i have to enter the values like- user name, password also at runtime.
So how can i do this in vc++?
plzz help me..
thanks in advance
|
|
|
|
|
In the fourth argument to SQLConfigDataSource() , you could try the UID and PWD keywords. Those may be driver specific, however.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Dear all
I have one double number which i want to round to nearest decimal number in Visual C++.
What is the function to do this
REgards
Monhi
|
|
|
|
|
double d =whatever;
int i = (int)(d + .5);
Please note that, as pointed out by Rage it doesn't work properly with negative numbers See the fix here [^].
-- modified at 8:10 Tuesday 10th July, 2007
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
d=-5.6 => i=-5, not -6. Is this ok ?
|
|
|
|
|
he probably should take the absolute value, and then apply it the original sign...
|
|
|
|
|
Rage wrote: d=-5.6 => i=-5, not -6. Is this ok ?
No, of course. I (naively) assumed d > 0 .
But there is an easy fix to account for negative numbers:
i = (int) ( d < .0 ? d -.5 : d + .5 );
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi everybody,
i put a ListControl on a dialog and want to catch the LVN_BEGINDRAG Handler.
I know that LVN_BEGINDRAG is a notify message.
I tried already :
ON_NOTIFY_REFLECT(LVN_BEGINDRAG,OnBeginDrag)
and via :
OnNotify(WPARAM w,LPARAM l, ...
{
if(((LPNMHDR)l)->code == LVN_BEGINDRAG)
int ok = 1; --> breakpoint
but i can't catch it
I tried also directly to add a handler via the ressource editor by adding a new handler,
but there i can't find the LVN_BEGINDRAG handler, only DoubleClick, Set & KillFocus ...
How should i catch it?
Big thanks
|
|
|
|
|
Try this:
ON_NOTIFY(LVN_BEGINDRAG, IDC_LISTVIEW1, OnLvnBeginDrag)
This should work.
"Some people believe football is a matter of life and death.
I'm very disappointed with that attitude.
I can assure you it is much, much more important than that. -- Bill Shankly"
|
|
|
|
|
Thanks for your answer
Is it necessairy to create a class from this Listbox from which i want to catch the Drag?
Because it won't work
|
|
|
|
|
|
Thanks for the tutorial,
but i really don't find where i can add the LVN_BEGINDRAG-handler via the classwizard.
I tried a lot of things, but no way to find a LVN_BEGINDRAG.
|
|
|
|
|
You may actually have to type it in by hand
For the handler prototype(s), see ON_NOTIFY and WM_NOTIFY Messages[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
Insert this code to your program
BEGIN_MESSAGE_MAP(CDialogDlg, CDialog)
ON_NOTIFY(LVN_BEGINRDRAG, IDC_LIST2, OnLvnBeginrdragList2)
END_MESSAGE_MAP()
void CDialogDlg::OnLvnBeginrdragList2(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
}
afx_msg void OnLvnBeginrdragList2(NMHDR *pNMHDR, LRESULT *pResult);
|
|
|
|
|
Big thanks ,
my code was completely correct, but probably the CListbox don't support drag&drop,
with CListCtrl it works fine
|
|
|
|
|
I suggest use of CListCtrl on your program its better and very flexible than CListBox.;)
|
|
|
|
|
Hi All,
I calling the method SetEnvironmentVariable and i getting back return value that is nonzero and the last Error does not return to me nothing.
BUT
The Environment Variable is not set !?
What to do ?
Thanks for any help.
|
|
|
|
|
Yanshof wrote: SetEnvironmentVariable
This function will set the environment variable for the current process only. I will not change the whole system's environment variable.
|
|
|
|
|
Thanks,
How can i create new environment variable and/or change exist one data ?
|
|
|
|
|
|
To change system environment variables, modify the HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment registry key.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I wanted to make my program to work on the desktop.
like http://desktop-tools.net/clock.html
i tried many things but i just dont know how did they do it? i dont know about any technique to make it transparant.
Is this possible or is it somesort of rendercode that creates a picture from what you need to have on the desktop and so making everything arround the text transparant? i hope there is a easier way.
Greetz
Rob
|
|
|
|