|
hi!
can anybody tell me how can i crate chjeckbox at run time
i have coded this but give me error
<br />
CButton *b1;<br />
CRect rect;<br />
int no,i;<br />
no=1;<br />
i=0;<br />
b1=new CButton; <br />
rect.SetRect(i+20,20,400,i+20);<br />
b1.Create(name,WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX,rect,&m_Stat,no);<br />
no++;<br />
i+=10;
|
|
|
|
|
What was the error? Kind of makes it hard to narrow down to the problem without a little help.
That said.... b1.Create should be b1->Create
HTH
Brad
|
|
|
|
|
softtec wrote:
i have coded this but give me error
Error? What error?
softtec wrote:
CButton *b1;
b1=new CButton;
Are you storing this b1 pointer somewhere else so as to delete it when it's no longer needed?
softtec wrote:
int no,i;
no=1;
i=0;
rect.SetRect(i+20,20,400,i+20);
b1.Create(name,WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX,rect,&m_Stat,no);
no++;
i+=10;
You are setting rect as left=i+20, top=20, right=400, bottom=i+20.
Assuming that's inside some loop, in the first iteration (when i==0), that means width=380 (i.e.: 400-20) and height=0 (i.e.: 20-20). In the second iteration (i==10), that means width=370 (i.e.: 400-30) and height=10 (i.e.: 30-20). In each iteration, the width is 10 pixels less (starting from 380), and the height is 10 pixels more (starting from 0).
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Variable b1 cant be a local variable .
This belaw sample work successful .
CButton *b1;
void Create()
{
b1=new CButton;
int no,i;
no=1;
i=0;
rect.SetRect(i+20,20,400,i+20);
b1.Create(name,WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX,rect,&m_Stat,no);
no++;
i+=10;
}
or
void Create()
{
static CButton *b1;
b1=new CButton;
int no,i;
no=1;
i=0;
rect.SetRect(i+20,20,400,i+20);
b1.Create(name,WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX,rect,&m_Stat,no);
no++;
i+=10;
}
|
|
|
|
|
Hello All!
I am working on image processing and using the library CImg. Constructor of CImg is used to load the image file (.bmp etc)...
Problem is that when the destructor of CImg Object is called, it doesnt release the full memory.
e.g if i load an image of 225kb...CImg creates an object of 20kb and release 20 kb when destructor is called. 220kb are left unreferenced in the memory.
This is causing hell of problem as i want to process 10-15 images per second.
Plz help me in this regard.
Regards
Mubashir
|
|
|
|
|
Sounds like to me that CImg (note: I've not even looked at the code or doc...) expects your application to manage that part of it. Is there a way to explicitly release the image before destroying the object?
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
hello....
can anyone help me in finding the source code (implementation) for the:
1. evolutionry artificial neural network (neural network with genetic algorithm)...
2. two dimensional cellular automata
i realy need help..
Thanks alot
asma
|
|
|
|
|
is there any way to check if print button pressed in print preview?
|
|
|
|
|
hiho@ll
for simple test environment i'm using the SimpleBrowser from codeproject which uses IWEbBrowser2 to make a "self-made" webbrowser
i know it's relatively easy to control html pages using post or get or to change the input field values
but can this be done with a flash site?
the problem:
i load a flash site from the internet, which has input fields and a form (all made in flash).
so how can i fill out the flash form and send it with webbrowser2?
because it's https i can't really sniffer which content is sent
any suggestions?
thxalot
|
|
|
|
|
How to change the Coordinate Map Mode ,create a compatible DC used to draw ,then call bitblt() to show the picture?
my code in the following , But when I run it ,there is nothing to be showed!
void CTestSetMapModeView::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rect;
GetClientRect(rect);
CClientDC dc (this);
dc.SetMapMode (MM_ISOTROPIC);
dc.SetWindowExt (rect.Width (), -rect.Height ());
dc.SetViewportExt (rect.Width (), -rect.Height ());
dc.SetViewportOrg (point);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SetMapMode(MM_ISOTROPIC);
memDC.SetWindowExt(rect.Width(), -rect.Height());
memDC.SetViewportExt(rect.Width(), -rect.Height());
memDC.SetViewportOrg (point);
CBitmap bitmap,*pOldBitmap;
bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
pOldBitmap=memDC.SelectObject(&bitmap);
memDC.BitBlt(-rect.Width()/2,rect.Height()/2,rect.Width(),rect.Height(),&dc,-rect.Width()/2,rect.Height()/2,SRCCOPY);
//draw some pictures
memDC.Ellipse(-50,50,50,-50);
memDC.Ellipse(-10,20,10,-20);
dc.BitBlt(-rect.Width()/2,rect.Height()/2,rect.Width(),rect.Height(),&memDC,-rect.Width()/2,rect.Height()/2,SRCCOPY );
memDC.SelectObject(pOldBitmap);
bitmap.DeleteObject();
CView::OnLButtonDown(nFlags, point);
}
|
|
|
|
|
Antonlio,
One thing I've found interesting about Windows Programming is the level of filtering Win32 does that is quite invisible. In this case, Win32 contains some code that says "ignore all drawing unless I need to draw..." Windows makes the decision to draw if the window is invalid. If you invalidate the target window, windows will fire an On Paint message. Adjust your code accordingly, and all will be well (at least you should see something on the screen).
chg
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
I think the problem in my case is the " coordinate map ".
I don't know When I excute the following codes:
CRect rect;
GetClientRect(rect);
CClientDC dc (this);
dc.SetMapMode (MM_ISOTROPIC);
dc.SetWindowExt (rect.Width (), -rect.Height ());
dc.SetViewportExt (rect.Width (), -rect.Height ());
dc.SetViewportOrg (point);
, Whether I should also change the memDC's coordinate map mode ,just like the following :
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SetMapMode(MM_ISOTROPIC);
memDC.SetWindowExt(rect.Width(), -rect.Height());
memDC.SetViewportExt(rect.Width(), -rect.Height());
memDC.SetViewportOrg (point);
aa
|
|
|
|
|
The aim of my case is to paint picture in the memory-DC (compatible DC) ,for preventing glitter when refresh(repaint)!
And I choose the maths coordinate mode not the MM_TEXT .That is X-axis ascending from left to righgt while Y-axis from bottom to top!
|
|
|
|
|
Antonlio,
My exposure to date with Win32 is through Windows CE, and Windows CE does not support the different mapping modes. I cannot comment further regarding that issue. I understand what you are doing - it's called double buffering and a host of other names. What I would do is divide and reduce the issue. Just add some code that slaps something silly onto the page in the default mode. If that doesn't show up, it isn't your scaling, it's what I mentioned earlier...
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
CharlieG :
Thank you very much !
I have solved this question by now ,the key of which is the ordinate of the MemDC should be set correct .
Antonliox
|
|
|
|
|
My pleasure. Code on....
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
Drawing inside OnLButtonDown() is not a good approach.
All drawing should be done in YourView::OnDraw() , based on the document's content, and possibly some state you keep in YourView .
At OnLButtonDown() , or for that matter, at the handler of any command that represents user interaction, you should alter the data in the document or the state of your view. If you alter the document, you should make the document notify the views about that fact (see CDocument::UpdateAllViews() ).
The view receives the document's notifications through OnUpdate() . The notification may include additional data that narrows what kind of modification was done and to what extent, so that each view can optimize the work needed to update the drawing. In the more general case, the view just calls Invalidate() , so as to redraw the entire window next time OnDraw() is invoked. Depending on the hint received, it may go for invalidating only a portion of the drawing.
Going back to OnDraw() , you can just draw everything (Windows will only update the invalidated portions of the window, anyway), or you may optimize the drawing by excluding portions of the drawing you know are out of the visible portion of the window, or are not invalidated.
Now, the best place to deal with mapping modes is at YourView::OnPrepareDC() , which the framework will always call before calling YourView::OnDraw .
Drawing to an offscreen bitmap to avoid flickering can be done, for example, in the following way. It's based in some working code but since I modified it for this post and haven't actually tested it, I can't guarantee that it works or even that it compiles, but I hope it helps, anyway:
void CYourView::OnDraw(CDC* pDC)
{
CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap = NULL;
CRect client;
if (pDC->GetClipBox(client) == NULLREGION)
return;
CRect rect = client;
dc.LPtoDP(rect)
if (!pDC->IsPrinting())
{
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
OnPrepareDC(&dc, NULL);
pDrawDC = &dc;
dc.OffsetViewportOrg(-rect.left, -rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
dc.SetBrushOrg(rect.left % 8, rect.top % 8);
dc.IntersectClipRect(client);
}
}
}
DoTheActualDraw(pDrawDC);
if (pDrawDC != pDC)
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
}
}
void CYourView::DoTheActualDraw(CDC* pDC)
{
CYourDocument* pDoc = (CYourDocument*) GetDocument();
CRect rEllipse = pDoc->GetEllipsePositon();
if (pDC->RectVisible(rEllipse))
pDC->Ellipse(rEllipse);
}
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi Jose:
Thank you very much .What you have said is much useful !
AntonlioX
|
|
|
|
|
AntonlioX wrote:
Thank you very much .What you have said is much useful !
You are welcome! Glad to be of help.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi,
Iam using Keith Rule's CMemDc class & I have changed it according to my requirement.Iam posting that class also here.
Now Iam zooming my View using "SetWorldTransform" call.
My problem now is when I change the zoom factor to below or above 100,the Fonts are not smooth.
The following are my codes:
//Creating Font like this in "MyView" constructor.Don't want to use FixedFonts.
m_oFont.CreatePointFont(120, _T("Courier New"));
LOGFONT oLogfont;
m_oFont.GetLogFont(&oLogfont);
//OnPrepareDc looks like this.
void MyView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
pDC->SetMapMode(MM_TEXT);
SetGraphicsMode(pDC->GetSafeHdc(), GM_ADVANCED);
pDC->SelectObject(&m_oFont);
pDC->GetTextMetrics(&m_TextMetrics);
XFORM xForm;
xForm.eM11 = 0.01 * m_iZoomFactor;
xForm.eM21 = 0;
xForm.eDx = 0;
xForm.eM12 = 0;
xForm.eM22 = 0.01 * m_iZoomFactor;
xForm.eDy = 0;
pDC->GetTextMetrics(&m_textMetrics);
SetWorldTransform(pDC->GetSafeHdc(), &xForm);
CScrollView::OnPrepareDC(pDC, pInfo);
}
//My "OnDraw" looks like this.
void MyView::OnDraw(CDC* pDC)
{
CpagesDoc* pDoc = GetDocument();
CSize sizeTotal;
//default scrollsizes to 80 chars X 80 lines.
sizeTotal.cx = 80;
sizeTotal.cy = 80;
//Client Rectangle Size.
CRect rect;
GetClientRect(&rect);
//Creating a temporary Dc.
C_TempDc tempDC(pDC,m_oFont,&rect);
int pageWidth = 800;
int pageHeight = 800;
//int pageGap = 5;
int pageNumber =3;
SIZE size;
size.cx = 1000;
size.cy = (pageHeight*3)+100;
//First Page
tempDC->Rectangle(CRect(0,0,pageWidth,pageHeight));
tempDC->TextOut(5,10,"This is the first line on the FirstPage");
sizeTotal.cx *= MulDiv(m_textMetrics.tmAveCharWidth, m_iZoomFactor, 100);
sizeTotal.cy *= MulDiv(m_textMetrics.tmHeight, m_iZoomFactor, 100);
SetScrollSizes(MM_TEXT, sizeTotal);
}
//Keith Rule's Memory Buffer
#ifndef C_TEMPDC_H
#define C_TEMPDC_H
class C_TempDc : public CDC
{
public:
C_TempDc(CDC* pDC,CFont & font,const CRect* pRect = NULL): CDC()
{
ASSERT(pDC != NULL);
//Initialising.
m_pDC = pDC;
m_oldBitmap = NULL;
m_oldFont= NULL;
//Getting ClipBox Rectangle.
pDC->GetClipBox(&m_clipRect);
//Client Rectangle.
m_clientRect = *pRect;
pDC->DPtoLP(&m_clientRect);
// Create a Memory DC
CreateCompatibleDC(pDC);
//pDC->LPtoDP(&m_rect);
m_bitmap.CreateCompatibleBitmap(pDC,m_clientRect.Width(),m_clientRect.Height());
pDC->LPtoDP(&m_clientRect);
m_oldBitmap = SelectObject(&m_bitmap);
///Selecting the Font.
m_oldFont = SelectObject(&font);
SetMapMode(pDC->GetMapMode());
pDC->DPtoLP(&m_clientRect);
SetWindowOrg(m_clientRect.left,m_clientRect.top);
// Fill background
FillSolidRect(m_clientRect, pDC->GetBkColor());
}
~C_TempDc()
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_clipRect.left,m_clipRect.top,m_clipRect.Width(), m_clipRect.Height(),
this, m_clipRect.left,m_clipRect.top, SRCCOPY);
//Swap back the original bitmap & font.
SelectObject(m_oldBitmap);
SelectObject(m_oldFont);
}
C_TempDc* operator->()
{
return this;
}
operator C_TempDc*()
{
return this;
}
private:
CBitmap m_bitmap;
CBitmap* m_oldBitmap;
CFont* m_oldFont;
CDC* m_pDC;
CRect m_clientRect;
CRect m_clipRect;
};
#endif//C_TEMPDC_H
Hope u can Help....
|
|
|
|
|
Hi, for quite sometime, I use CList to store my non CObject derived class pointer.
CList<cmyclass*, cmyclass*=""> MyPtrList;
However, I remember saw in an article that the author suggest to use
CTypedPtrList<cptrlist, cmyclass*=""> MyPtrList;
However, I am not quite remember the reason to do so and not to use CList to store the pointer of non-CObject class.
Does anyone know why we need to do so?
Thanks.
cheok
|
|
|
|
|
yccheok wrote:
However, I am not quite remember the reason to do so and not to use CList to store the pointer of non-CObject class.
I believe, There is no particular reason not store Non COBJECT drived class in CList.
you can store almost Everything using CList.Let take example:-
int is not derived from CObject, even not a class,it's a keyword but you can store it using CList without nay extra overhead and difficulty.
I can't find any reason for not using CList for Non CObject derived class.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hello, I have an object called XXX previously derived from CDocument in my MDI project.
Later, I create an concrete class called Subject. And I let XXX to have multiple inheritance from Subject (Subject is an object with protected constructor)
The problem is, whenever I used dynamic_cast to cast a Subject pointer to XXX (I am quite sure Subject pointer is actually pointing to XXX), a visual c++ runtime error will occur.
void fun(Subject *s) {
XXX *var = dynamic_cast<xxx *="">(s);
var->hehehe();
}
However, when I try to do this:
void fun(Subject *s) {
XXX *var = (XXX *)(s);
var->hehehe();
}
everything just go fine. may i noe why this happen? is this bug related to something called dynamic creation?
thanks you.
cheok
|
|
|
|
|
Hi,
Have you tried enabling RTTI for your project ?
When it's enabled, instead of throwing an exception, the dynamic_cast will return NULL (make sure you check the return value! )
Hope this helps
|
|
|
|
|
Can you please let me know how I can enable RTTI for the project? Please note that for the classes which my CDocument inheritance from, I created by hand.
Here is my details:
I have an abstract class named CObserver and a concrete class named CSubject. The purpose of having this two classes is that, some interesting event will always happen in subject. observer is a guy which is interested in the event in subject. subject will notify all the observers attached to it whenever an event happen.
---------------------------------------------------------------------
class CObserver {
public:
virtual ~CObserver();
virtual void Update(CSubject *s) const=0;
protected:
CObserver();
};
class CSubject {
public:
virtual ~CSubject();
virtual void Attach(CObserver *o);
virtual void Detach(CObserver *o);
virtual void Notify();
protected:
CSubject();
private:
CList<cobserver*, cobserver*=""> _observers;
};
---------------------------------------------------------------------
Now, I need to monitor a IO port. Then, I need to notify my CDocument whenever there is some IO activity. Hence, I create an CIOMonitor class which is single inheritance from CSubject.
// Please note that I remove most of the members. Only leave those which is related to this bug
class CIOMonitor : public CSubject
{
int GetInt() const;
}
I use Wizard in VC++ to create MDI project. Then, for the CCatchbugDoc (multiple inheritance from CDocument and CObserver). This is because CCatchbugDoc will be interested in the event happen in CIOMonitor
class CCatchbugDoc : public CDocument, public CObserver
{
public:
virtual void Update(CSubject *s) const;
};
Please note here is the root of evil
void CCatchbugDoc::Update(CSubject *s) const
{
/* Everything work fine with this unsafe casting */
/* But dynamic casting just prompt me a runtime error */
/**/
/* CIOMonitor *p = (CIOMonitor *)s; */
CIOMonitor *p = dynamic_cast<ciomonitor *="">(s);
if(p == NULL) {
AfxMessageBox("unknown error during dynamic cast");
return;
}
CString string;
string.Format("Nofity. CIOMonitor: %i", p->GetInt());
AfxMessageBox(string);
}
Here is my suspection
1. In VC++, CCatchbugDoc is created using dynamic creation. Initially, CCatchbugDoc is single inheritance from CDOcument. The following macro is added by VC++ wizard to enable dynamic creation:
IMPLEMENT_DYNCREATE(CCatchbugDoc, CDocument)
Now, I make CCatchbugDoc as multiple inheritance (CDOcument and CObserver). But I still use back the same
IMPLEMENT_DYNCREATE(CCatchbugDoc, CDocument)
Can this be the possible root cause of bug?
Thank you!
-cheok
|
|
|
|
|