|
I think that most people do this :
static const char *str = "abc";
|
|
|
|
|
I have an SDI application, and I'm operating in the OnPaint handler for WM_PAINT messages in my CChildView derived from CWnd. In the CChildView class, I have 2 pointers to class objects I made derived from CObList which are initialized to NULL when the view is constructed. When I open the file, data is read in and one or both lists may be filled with items. Here is some example code:
void CChildView::OnPaint() {<br />
CPaintDC dc(this);
if (files != NULL {<br />
char * lpszText = new char[32];<br />
sprintf (lpszText, "Files: %u", files->GetCount());<br />
int nTextHeight = dc.DrawText(lpszText, -1, CRect(10, 30, 100, 100), DT_LEFT | DT_SINGLELINE);<br />
MessageBox(_T("files detected"), NULL, MB_OK);<br />
delete[] lpszText;<br />
} else { dc.DrawText(_T("Files: 0"), CRect(10, 30, 100, 100), DT_LEFT); }<br />
}
Now, what happens is when I start the app, I am told there are no files which is right. When I open the file, the code runs through and I see the MessageBox displayed but the text that should have been drawn in the line above it doesn't show up on the screen. However, if I were to put a breakpoint on the sprintf line, start the program, load a file, it would break on the line and I were to press F5 to continue executing, the result of DrawText would show up on the screen fine and the message box would pop up too.
I've tried to see if I'm doing something wrong or if I'm not doing something I should here and on other GDI tutorial sites but I can't figure out why this behavior exists. Can someone please set me straight?
|
|
|
|
|
If you need solution of problem, use CDC* pDC = GetDC(); instead of CPaintDC dc(this);
|
|
|
|
|
I was reading about GDI and I believe that's the old way and I figured using CPaintDC was used for a reason. I'll check it out, thanks for the tip.
|
|
|
|
|
The problem is that the area in which you are drawing is not 'invalidated'. Breaking into the debugger has the side-effect of invalidating the entire window and that's why it works fine after that. Whenever you change the info, which by the way should be in your document instead of your view, you need to make the view invalidate the area that needs to be updated.
Take a look at this post[^] for more details on how to orchestrate the interaction between the document and its views.
Also, instead of this:
char * lpszText = new char[32];
sprintf (lpszText, "Files: %u", files->GetCount());
int nTextHeight = dc.DrawText(lpszText, [...] );
delete[] lpszText;
I suggest this:
CString sText;
sText.Format("Files: %u", files->GetCount());
int nTextHeight = dc.DrawText(sText, [...] );
It's cleaner, you don't need to worry about how much space to allocate, and you don't risk forgetting to free it.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I think I was doing the second way but I must have changed to C-Style strings for some reason, I don't know. I'm using CString's practically everywhere else. I'll take some time and read that link, thanks a lot.
edit: I just invalidated the view when the data is changed and it worked like a charm, many thanks. Practically that entire post was very informative, good call.
|
|
|
|
|
I would like to get handles to all icons in the system tray but have not been able to do this or find an answer in the MSDN.
Is it possible to get handles to all icons in the system tray and be able to remove them or modify them using the handle ?
Thankyou.
|
|
|
|
|
G Cross wrote:
I would like to get handles to all icons in the system tray but have not been able to do this or find an answer in the MSDN.
Here is answer to your query :-
http://www.codeproject.com/tools/ShellTrayInfo.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I've seen some articles with codes that has something to do with "Unicode".
How can I see the immediate effect of a program that's not "Unicode" compatible? because I'm still using char instead of TCHAR and i'm not using _T either but I haven't felt the effect of it yet.
|
|
|
|
|
Hi guys,
What database access technologies do you use for your applications at work? OCBC? DAO? ADO?
I am using VC6 to program my personal projects. At work, I am forced to use an inhouse database class, reason being it can be used in MFC and ATL projects. And also at work, we usually save data into our file format. So I have not really use any database technology.
I would like to use ADO for my personal projects. But it is very hard to find indepth information on how to use ADO in VC.
So what do you usually use?
Thank you in advance.
|
|
|
|
|
using ODBC is easy.
use CRecordset.
Iman Ghasrfakhri
|
|
|
|
|
I think it would not be user friendly to require my users to set the data source before they can use my application.
|
|
|
|
|
It is so easy to set data sourse in your program
CString str,DBName;;<br />
DBName = "Program path"+"\\DBname.mdb";<br />
str.Format("DSN=Chapar;DBQ=%s;READONLY=FALSE;EXCLUSIVE=FALSE;",DBName);<br />
SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)",str);
& to fined your program path use something like this:
GetModuleFileName(NULL,m_CurrentPath.GetBuffer(256),256);<br />
m_CurrentPath.ReleaseBuffer();<br />
m_CurrentPath.Delete(m_CurrentPath.ReverseFind('\\'),m_CurrentPath.GetLength()-m_CurrentPath.ReverseFind('\\'));
Iman Ghasrfakhri
|
|
|
|
|
Thanks Ghasrfakhri.
So I set it when my program is used for the first time?
|
|
|
|
|
CBasicNet wrote:
So I set it when my program is used for the first time?
Yes, or you can use a DSN-less connection.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
Thanks toxcct! I have seem that article before.
I would like to master ADO first before using a wrapper class which may hides some of the details from me.
|
|
|
|
|
i believe ADO have no class in the "constructor" classes...
that's why i fully use Mr Antolini's !
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Either ODBC or ADO. But I prefer ADO.
John
|
|
|
|
|
Can you give me some reasons for your preference?
|
|
|
|
|
CBasicNet wrote:
Can you give me some reasons for your preference?
I use ADO for everything.
Down Sides to ADO,
-I guess it can be a memory hog (I haven’t see this problem personally)
-Poorly documented, most of the documentation was written for VB, if you know that language than translating it shouldn’t be too difficult.
-ADO is COM based; in C++ working with COM can be a pain.
Positives
-Flexibility, ADO can connect to just about every data source you can think of. Excel, Access dbs, delimited files, SQL server, Oracle server, even LDAP (as memory serves)
-Changing data sources is easy enough just change the connection string.
-Dumping data from the data connection is extremely easy, ADO natively supports dumping data to an XML file, or you can execute a query that will dump data to a file. RE
objDB.Execute _
"SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
"].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
objDB.Close
-It supports calling stored procedures or strait queries.
-Changing the location of the where the data is; is a matter of changing the database connection.
That’s all I can think of for the time being. Before you start using someone else’s class I suggest hacking around with ADO. It’s very powerful but comes at a cost (steep learning curve).
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
|
I have very good experience with OLEDB templates and ATL.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Are you a glutton for punishment or OLEDB templates is different from the OLEDB I have heard of?
|
|
|
|
|
Are you using OLEDB through simple-to-use wrapper classes or you are using it 'raw'?
|
|
|
|
|