|
Hi
I'm a beginner in VC.
I created a CObject-derived class (CGraphPlotter below).One of its functions create an CFrameWnd object, draw something and then try to display it on the frame.Below is the extract..
But it runs into exception error and i think the problem lies with ShowWindow().I don't know what to do.Invalidate doesnt work too.Can anyone help?Thks.
void CGraphPlotter::CreatePlot(CString title)<br />
{<br />
RECT rect;<br />
POINT pt;<br />
RECT windowSize;<br />
<br />
CFrameWnd *pwndPlot = new CFrameWnd;<br />
<br />
windowSize.left = 0;<br />
windowSize.top = 0;<br />
windowSize.bottom = 300;<br />
windowSize.right = 600;<br />
<br />
pwndPlot->Create(NULL,title,WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,windowSize,NULL,NULL,0,NULL);<br />
<br />
pwndPlot->GetClientRect(&rect);<br />
pt.x=rect.right;<br />
pt.y=rect.bottom;<br />
<br />
CPaintDC dc(pwndPlot);<br />
CPen plotPen;<br />
CPen *pOldPen;<br />
POINT pt;<br />
<br />
plotPen.CreatePen(PS_SOLID,0,RGB(200,0,0));<br />
pOldPen=dc.SelectObject(&plotPen);<br />
<br />
double m_sampleData[5];<br />
int m_sampleXAxis[5];<br />
<br />
dc.MoveTo(0,0);<br />
for(int i=0;i<4;i++)<br />
{<br />
pt.x=m_sampleXAxis[i];<br />
pt.y = m_sampleData[i];<br />
dc.LineTo(pt);<br />
}<br />
<br />
pwndPlot->ShowWindow(SW_SHOW);<br />
}
|
|
|
|
|
you have to write the painting code in OnDraw.
If you write before, the next time the window paints, whatever you did will get erased.
To do that, you have to create a class CPlotterWnd derived from CFrameWnd and override the OnDraw... although drawing in a frame window is not eh correct way. Framewindow is used to host other windows like views, which inturn display the data.
If you have access to MSDN, it explains it quite well. .. or you have to get a book on MFC.
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I've gone and read up on MSDN.I understood the concept much better and i hope to use the correct way.
My application is a SDI and i want to display a graph in the CPlotterWnd(CFrameWnd-derived). Am i right to interpret that i should probably derive CGraphPlotter from CView instead? And to associate them together, can i CREATE CPlotterWnd in CGraphPlotter?
thks
|
|
|
|
|
yes. you are better off creating a view for that. If that is the only view that you want, implement your graph plotting in the default view. But, if you want multiple views that look different from the same data, you can create multiple view classes. MSDN has some doumentation on using multiple view types with SDI applications.
Or you can create another view class, host it inside another frame derived class... and create the framewindow, when you click a menu item or a toolbar button. This way, you can create multiple windows showing the same data in different display formats. But, read up on the multiple view handling on SDI before you go out and implement it this way.
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I have a huge memory leak. I have found that the offending line of code is this one. I comment this part and the leak goes away. The leak is big enough for Windows to say that it is low on virtual memory on a 512 MB machine! m_hdr is a class derived from CHeaderCtrl. There is an image list associated with the header control that has 7 images. The variable direction can be only 0 or 1.
Not being particularly great at MFC UI controls, I copied this from MFC, except for the part where I derive the image index.
HDITEM curItem;<br />
m_hdr.GetItem(column, &curItem);<br />
curItem.mask= HDI_IMAGE | HDI_FORMAT;<br />
curItem.iImage = (sortindex > 3) ? 0 : ((sortindex * 2 + direction) + 1) ;<br />
curItem.fmt= HDF_LEFT | HDF_IMAGE | HDF_STRING;<br />
m_hdr.SetItem(column, &curItem);
My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
modified 29-Aug-18 21:01pm.
|
|
|
|
|
|
You need to set the mask member of the HDITEM struct before calling GetItem() , so the control knows what info you're asking for. As it is, mask is random data and who knows what the control is putting in the struct.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
Hello,
I've to add large strings with very different styles to richedit.
how can i add them all to rich edit and then show all in a second ??!
Because it makes filickers when i add each string to richedit !
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
In my old project I added a class CsortListCtrl derived from CListCtrl, and when I #included it (I think thats all I did) when I put a listctrl on the dialog and used the CW to make a variable for it, it gave me two choices for the type of the control: SO I could either make it CListCTrl or CSortListCtrl. In this new project I've put the control on the form, #included it, but the CW is only offering me one choice i.e. it can only be of type CListCtrl. WHat to do? I need
CSortLIstCTrl mySortCTrl;
|
|
|
|
|
Hiya getting a message saying "Database error - There were no columns specified to retrive." when using these 2 lines:
SqlString = "DELETE * from Branches WHERE Branch_No LIKE '4%' ";
OR
SqlString = "INSERT INTO Branches (Branch_No,Branch_Name) VALUES ('6','Derry') ";
But Branch_No is the first column and Branch_Name is the second..
Am I using the statements wrong??
Thanks,
grahamoj.
|
|
|
|
|
grahamoj wrote:
SqlString = "DELETE * from Branches WHERE Branch_No LIKE '4%' ";
It should be DELETE FROM <table_name> WHERE <condition>
Vini
|
|
|
|
|
grahamoj wrote:
SqlString = "INSERT INTO Branches (Branch_No,Branch_Name) VALUES ('6','Derry') ";
1. What is the error message
2. Does the row exists, if so the statement will fail
3. Is Branch_No declared as INT it so try 6 not '6', although I don't think this will make any diference.
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
// Open the database
database.Open(NULL,false,false,sDsn);
// Allocate the recordset
CRecordset recset( &database );
// Build the SQL statement
SqlString = "DELETE FROM Branches WHERE Branch_No LIKE '4%'";
//SqlString = "INSERT INTO Branches (Branch_No,Branch_Name) VALUES ('6','Derry') ";
// Execute the query
recset.Open( CRecordset::forwardOnly,SqlString,CRecordset::readOnly );
I now know it is the last line, so changed it to:
recset.Open( AFX_DB_USE_DEFAULT_TYPE,SqlString,CRecordset::none );
but this still does not delete the line. The error message I am getting is:
"Database Error: Attempt to open a table failed - there were no columns to retrive were specified".
But my table is called Branches and is specified!!
Any ideas.
grahamoj
|
|
|
|
|
What I always do is use "Query Analyzer" to check out my SQL statement, I tried the following on a scratch table
use teds<br />
INSERT INTO winrasdialit (col001, col002, col003) VALUES('hello', getdate(), 5)
It works OK, so if your SQL statement works in "Query Analyzer" you have at least eliminated one possible error. It does look like you do not have the database open for read only as delete seems to work?
I don't use CRecordset so I can't comment on your synatx
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Since the DELETE and INSERT commands don't return a recordset you shouldn't use the CDaoRecordset (or CRecordset) class to execute them. Just use the Execute method in the CDaoDatabase (or CDatabase) class.
Kelly Herald
Software Developer
MPC formerly Micronpc
|
|
|
|
|
Hi! I'm just curious how you manage to execute those insert and delete queries? I get rt error when doing it like this:
CDaoDatabase* m_pDB;
CDaoRecordset* m_pRS;
m_pDB = new CDaoDatabase;
m_pRS = new CDaoRecordset(m_pDB);
try {
m_pDB->Open("c:\\accessdb\\db1.mdb");
// CString strQuery = _T("SELECT * FROM Table1"); //Works just fine...
CString strQuery = _T("INSERT INTO Table1 VALUES ('3', 'Olga')"); //Doesn't work
m_pRS->Open(dbOpenDynaset, strQuery);
} catch (CDaoException* e) {
AfxMessageBox(e->m_pErrorInfo->m_strDescription);
e->Delete();
}
Can you tell me how to do it?
|
|
|
|
|
Hi, I just started getting into C++/MFC and I've hit my first snag. I'm making a simple program that downloads the contents of a webpage and then sorts out href's. The problem comes into play in the OnReceive event handler. I'm getting 'The instruction at 0x77f475cc referenced by 0x0000000. The memory could not be "written"' right after I get the first packet. I suppose I'm doing something wrong with a pointer? Null maybe? It ONLY does this when I compile for release, it works perfectly when I compile for debug. After changing around some compiler options (turning off optimizations) it still does the same thing. I've done step by step debugging and the last thing I'm seeing is 'Receiving HTML'. I've looked over it for a long time and even showed it to a few friends, they couldn't figure it out either. My guess is it's the pBuf pointer but I don't see why, if anybody could give me some tips I would appreciate it! Here's my code..
void CReconDlg::OnReceive()<br />
{<br />
char *pBuf = new char[1024];<br />
CString strRecvd, strConlen = "Content-Length:", actualLen;<br />
char *pConlen;<br />
int wholePacket, int result, int lenLen, int endPos, int iBufSize = 1024, int iRcvd, int packetStart;<br />
<br />
iRcvd = m_sConSocket.Receive(pBuf, iBufSize);<br />
pBuf[iRcvd] = NULL;<br />
<br />
if (iRcvd == SOCKET_ERROR){<br />
MessageBox("Error on receiving socket");<br />
}else{<br />
m_sStat = "Receiving HTML..";<br />
strRecvd += pBuf;<br />
}<br />
<br />
pConlen = strstr(strRecvd, strConlen);<br />
<br />
if (pConlen != NULL){<br />
result = (int)(pConlen - strRecvd + 1) + 15;<br />
endPos = strRecvd.Find("\n", result) - 1;<br />
lenLen = (endPos - result);<br />
actualLen = strRecvd.Left(endPos);<br />
realLen = actualLen.Right(lenLen);<br />
packetStart = strRecvd.Find("\r\n\r\n", result);<br />
int packetLen1 = (strlen(strRecvd) - packetStart);<br />
m_strIn += strRecvd.Right(packetLen1);<br />
}else{<br />
m_strIn += strRecvd;<br />
}<br />
wholePacket = strlen(m_strIn) - 4;<br />
CString display ;<br />
display.Format("%d", wholePacket);<br />
<br />
if (realLen == display){<br />
m_sStat = "Received entire packet, parsing..";<br />
ParseString(m_strIn);<br />
m_sConSocket.Close();<br />
m_strIn = "";<br />
realLen = "";<br />
<br />
}<br />
<br />
UpdateData(FALSE);<br />
<br />
}
|
|
|
|
|
First thing I noticed is that this:
pBuf[iRcvd] = NULL;
is a buffer overrun. What happens if iRcvd is 1024? You write a 0 to one byte past the end of the array, overwriting whatever is on the stack at that point.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
hi,
when i attempt to use odbc to retrieve data from ms access database, i get an error "error: field data truncated during data fetch" right after executing odbc's Open().. odbc crashed at retrieve data from a field, datatype: memo.. i did a couple test and found out if the field contain more than 255 characters the my program crashes.. is there anyway to fix the problem? thanx in advance..
|
|
|
|
|
which the best book to learn vc SDK?
ive heard of petzold as one.
-We are born naked, wet and hungry. Then things get worse.
|
|
|
|
|
You mean Windows API? Well, Petzold is still the best IMHO
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
|
|
|
|
|
i need to find out the size of the
Tab control....
"how to get size of any control"
|
|
|
|
|
Hi all
I have to download that files(from internet sites,DLL or exe anything)to store in some temporary area like C:Pgmfiles\temp
To do that how to write coding in VC++?
Thanks for viewing this.Please help me.
|
|
|
|
|
Look at the MSDN example:-
TEAR: "Tearing" HTML Pages Off the Internet
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|