|
While it's certainly possible to put code in header files (ATL and WTL do this) it's more efficient at build time to not do so.
Imagine a big project, say 100 CPP files. There's one header file, call it "funcs.h", that has the code for some utility functions. Every CPP file uses at least one utility function, so they all #include funcs.h.
Now suppose you fix a bug in a utility function. Next build, every CPP file must be recompiled because they all depend on the header file.
If you put the code into its own funcs.cpp file, only that file needs to be compiled.
There's also the whole issue of implementation hiding in C++. And commercial libraries that ship header files obviously don't put their code in the publically-available header files.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
It makes compiling more efficient because if you had everything in the .h file everytime you modified one function you would have to recompile the entire application. Using the header files you can link code together and build an application across multiple files. header files also are needed when working with libraries.
|
|
|
|
|
does anybody know how to find a word in a string?
for example I want to find the word "test" in the string "This is a test"...
Is String.Find(... the right way?
|
|
|
|
|
yeah, CString::Find will return the position where "test" begins (10, I think), or -1 if it's not in the string.
Jake
|
|
|
|
|
You can use strstr()
char str_to_find[] = "test";
char *pdest;
int result;
pdest = strstr( your_string, str_to_find );
result = pdest - you_string + 1;
if( pdest != NULL )
printf( "%s found at position %d\n\n", str_to_find, result );
else
printf( "%s not found\n", str );
I more or less just copied the code from the MSDN.
OR you can use the MFC-function Find()
int res = string.Find("test")
"string" needs to be from type CString
hope this helps
|
|
|
|
|
If you're using MFC's CString, use this:
CString myString = "This is a test...";
int pos = myString.Find("test");
if (pos == -1)
{
// string not found
}
else
{
// string found
}
If you're using Standard C++, use this, check out the strstr() function.
|
|
|
|
|
Thank you guys!!!!!!!!!!!!!!!
|
|
|
|
|
Does anybody know how to make a tree controled options dialog, without mfc? Like the one in winamp? with a tree on the left that changes the dialog layout on the right with each selection... do they use property sheets? i've read the articles on this... but i don't want to use MFC! my app is written entirely in pure win32 api from the platform sdk.
thanks,
john
|
|
|
|
|
You start by making several modeless, borderless dialogs. When the selection in the tree changes, show the one dialog that corresponds to the selected tree node.
The techniques in the MFC articles are applicable to you. Don't dismiss them just because they use MFC.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
Any ideas why the compiler is telling me it doesn't recognize the ID of the dialog that VC++ just created? I mean, I just made the resource for "IDD_DIALOG1", then created a new class for it, and when I try to build that class has an error in the generated .h file, at the line: enum { IDD = IDD_DIALOG1 } saying the ID is an undeclared identifier. that's lame. any ideas how to get rid of this?
thanks,
Jake
|
|
|
|
|
Check if in the resource.h header file you have that ID.
And if in the header of your Dlg class you have the include of the resource.h
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
The ID's are in resource.h, which is included only in my CWinApp-derived class. The app's header is included automatically in every cpp file in the project. So, when I compile the class in question, it picks up the include and works fine, but when I build the project, it apparently looks at the headers first and gives me trouble. should i include the app's header in the problem header, instead of in it's cpp file?
|
|
|
|
|
First. Try to include the header in the header of the class dialog.
Second. Check if the value of IDD_DIALOG1 is correct, or if is dupplicated.
If the problem persist, try to sen me the project by mail.
Good luck!!!!
Carlos Antollini.
|
|
|
|
|
I am using a printer outside the Framework.
I declare a variable to hold a RecordSet Field:
CString m_MyCString;
I set the variable to the record set field:
m_MyCString = m_pSet->m_MyStringField.
All is OK so far.
After I start the document:
if (pDC.StartDoc(&pMyDoc)>0)
{
etc.
}
the CString variable m_MyCString gets changed to a different value.
Duh!!
Richard
|
|
|
|
|
i have set the transparent check box in the properties of the control but i still have a white background on the list control
how can i make the list box trasparent or change all the background to the color of the dialog box.
thank you
|
|
|
|
|
|
He also has to make it owner draw too, doesn't he?
|
|
|
|
|
He also has to make it owner draw too, doesn't he?
Have no idea - it depends how Windows draws items in the listbox. If DC has no TRANSPARENT bkmode set, he'll have to go ownerdraw.
The easiest solution would be switching to CListCtrl and using CListCtrl::SetBkColor and CListCtrl::SetTextBkColor.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I've got an very urgent question.
I want to get the Serialnumber of a Disk (Floppy Disk, Hard Disk (IDE &
SCSI), CD,...) into a CString (- the disk where my program is saved).
I've only found Source Code for IDE Hard Disks.
Is there an API function to get the number.
(There is one in VB.)
Gerhard
|
|
|
|
|
|
Does anybody know how to insert a new line
into a CRichEditCtrl/View?
for example like this:
rectrl.InsertText("\nnew line\");
thanks in advance
|
|
|
|
|
Use CRichEditCtrl::ReplaceSel. If there is no current selection, the replacement text is inserted at the insertion point, that is, the current caret location.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
is it no something weird like,
two carriage returns and then a line feed.....
Regards
Ray
"Je Suis Mort De Rire"
|
|
|
|
|
Can you please tell me what's wrong with this code:
CMyRichEditView *pView;
CRichEditCtrl& pCtrl = pView->GetRichEditCtrl();
pCtrl.ReplaceSel("\r\r\ntest");
I get a debug assertion in the third line.
thanks
|
|
|
|
|
I've never used a RichEditCtrl before, so I might be wrong, but it looks like you're declaring a pointer and never constructing it, so pCtrl is probably NULL or invalid somehow. Something like that
Jake
|
|
|
|