|
So i've heard and yes I certainly have, but for the time being i'm keeping with what i have and i'll see what comes of it.
Believe me, the learning curve for STL is not that steep, and the payoff is worth the effort. Consider this: As soon as you start using objects with nontrivial constructors and want to have arrays of them, then you will no longer be able to use malloc and have to resort to either new /delete or STL containers (that's where you are now). What's the point of mastering the intricacies of manual memory management when STL does the job for you? After all it's just about learning one of two methodologies, and the second is by far the most profitable.
I'm actually doing something quite similar with templates, designed from the ground up.
Call me stupid, but i enjoy playing with things that aren't broke;P
I think playing with these things is an excellent way to learn the language. When it comes to writing production code, though, it is better to rely on standard libraries.
p.s-I've heard and read little of these vectors, so correct me if i'm wrong, but basically there templates with automatic reallocation as needed. Magically index any location and whola it's available..?
No, for vectors you have to indicate resizing explicitly. Other STL containers called maps work sort of like you say. Hey, type "STL tutorial" on your web searcher and enter STL paradise! You will not regret having done it
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'll certainly consider looking into using STL.
Thinking in C++ by Bruce Eckel introduced me to templates using the vector as an example. His vector basically has magical indexing. You specify the index location and it there.
I've noticed the STL version of vectors requires explicit resizing. Honestly, i think i prefer Bruce's idea of magic indexing...sounds easier, just set and delete...It's like VB
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
You can still use new and delete. In your SetSize function you need to delete the memory first beofre allocating the new one, or if you need the old values still, copy it across:
MyClass::MyClass()
{
m_pData = NULL ;
}
MyClass::~MyClass()
{
delete []m_pData ;
}
void MyClass::SetSize(int new_size)
{
ASSERT(new_size >= 1) ;
delete []m_pdata ;
m_pData = NULL ;
m_pData = new char[new_size] ;
}
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
|
|
|
|
|
Thanx Roger, i already settled for malloc, realloc and free, but this looks easier on the eyes, and quick enough to redo.
Thanx again!
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
I was wondering how to use the color palette used in microsoft paint so the user can define their own colors. I've seen other programs do it so it must be possible. Does it have something to do with the CPalette class?
Sorry if its confusing, its really late.
-Raffi
The truth about C++
|
|
|
|
|
How about CColorDialog?
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
|
Can anyone tell me how to put a CRichEditCtrl in a dialog app? It will run but it closes right away and never shows the dialog. Thanks if you can help.
- Matt Newman
-Sonork ID: 100.11179:BestSnowman
Frankly AOL should stick to what it does best: Fooling millions of americans into believing that it, AOL, is the web. -Paul Watson
|
|
|
|
|
Did you call AfxInitRichEdit in your CWinApp::InitInstance function?
Matt Gullett
|
|
|
|
|
It worked, Thanks.
- Matt Newman
-Sonork ID: 100.11179:BestSnowman
Frankly AOL should stick to what it does best: Fooling millions of americans into believing that it, AOL, is the web. -Paul Watson
|
|
|
|
|
You can also create it like this without AfxInitrichedit():
extern CWnd* pParentWnd;
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
pmyRichEditCtrl->Create(
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,
CRect(10,10,100,200), pParentWnd, 1);
|
|
|
|
|
You can also create it like this without afxinitrichedit():
// pParentWnd is an external pointer to the parent window.
extern CWnd* pParentWnd;
// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;
pmyRichEditCtrl->Create(
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,
CRect(10,10,100,200), pParentWnd, 1);
|
|
|
|
|
Mmmm...
Ok !, I remember I think you have to add this code in your InitInstance method from the APP:
AfxInitRichEdit();
Funny isn´t it ? ( I think I had one time that problem it´s a sh...), Bye !
Braulio
|
|
|
|
|
This is the point :at this case you don't need to add AfxInitRichEdit() anywhere
(you do not add richedit in resources tab)
1.Define controller in header of class--->CRichEditCtrl richedit;
2.In OnCreate or OnInitDialog you create richedit---->
richedit.create(.........);
|
|
|
|
|
Hi guys,
In my MFC application, I'm using an IRC layer to make remote machines connecting into a group and exchanging data.
I send some WHO commands in order to get the addresses of the remote machines.
Sometimes, the IRC server replies with an IP Address (123.123.123.123) and sometimes with a Domain Name (this.is.my.domain) but never both. I store the result into a string. I need to get both IP Address and Domain Name, or at least the IP Address if the Domain Name is not accessible.
How do I:
- detect if the format I get is an IP Address or a Domain Name,
- convert an IP Address to a Domain Name,
- convert a Domain Name to an IP Address.
Thanks a lot in advance for your help...
Jean-Louis
|
|
|
|
|
Here's a piece of code I used some time ago:
ULONG uRemAddr = inet_addr(lpszHostAddress);
if (uRemAddr == INADDR_NONE) {
hostent* pHE = gethostbyname(lpszHostAddress);
if (pHE == 0) {
m_lastError = WSAGetLastError();
return FALSE;
}
uRemAddr = *((ULONG*)pHE->h_addr_list[0]);
}
The address is in lpszHostAddress , at the end the IP address (as a 32bit unsigned number) is in uRemAddr . You can use the getnameinfo() function to get the host name from the IP address.
|
|
|
|
|
Thanks a lot man! That saved my day...
|
|
|
|
|
Hello, i was confused by a question for a
long time.i am making
a program that contains a dialogbar. i create
it in a class(CMyDialogbar) with 6 buttons.
and i want these buttons have push style just
like MSPaint's toolbox.and now i create a new
class named CPushButton extend from CButton.
then i call CPushButton::Create(...) to create
a button, but when i compile this program, the
button in the dialogbar still gray.it doesnt
work at all. i look up MFC Libary Reference to check
the parameters i passed to CPushButton::Create(..),
they are all right!i dont know what to do next!
can anybody give me some suggestion?
or ,is there another way to solve this problem??
how can i implement these button ?? and make them
have push button style ????
it almot drived me mad !!!thank in advance!
Thank u 4 helping me!!!!! Thank u !!!!
Codeproject
|
|
|
|
|
The buttons are probably disabled because there are no command or UI handlers.
Check out the macros ON_COMMAND and ON_UPDATE_COMMAND_UI.
If you have an ON_COMMAND handler you do not need the UI handler to enable the button.
If you want to have a pushbutton, call CButton::SetButtonStyle() with nStyle as BS_PUSHBUTTON.
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
Thanks a lot, i ll have a try.
thx
nickong
Codeproject
|
|
|
|
|
I downloaded TAPI3.0 sample incoming from MSDN. The trouble is I cannot compile it. It requires nmake usage. The instruction only says type in nmake in the directory where you have this sample unzipped. It is supposed to compile t3in. I tried this in command prompt and it did not work. I am new to C++ and cannot find any place where I can type 'make' within project or its tools.
Could somebody help me understand how nmake can be used in this situation.
|
|
|
|
|
Do you remember when you installed Visual Studio whether or not you opted to let the installer add VC to your path? This could be the problem. nmake.exe is located in:
C:\Program Files\Microsoft Visual Studio\VC98\Bin\NMAKE.EXE
on my installation. You can add this path to your PATH environment variable so that it's available on the command line and then run nmake in the TAPI directory.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
I create C++ modeless dialog from an Active X control.
When an ActiveX control is the parent window of a modeless dialog box the TAB key, ToolTips don't work as expected.
The problem with the TAB key could be solved using ::SetWindowsHookEx function, though it is quite dangerous.
But I still can't enable tooltips.
Ruslan
|
|
|
|
|
I have been trying to resolve this problem all morning. I'm running WinXP and have VC++6 SP5 with the latest PSDK installed, and I don't know what I'm doing wrong. I am trying to dump into a buffer a HTML file but keep getting this error:
CFile exception: accessDenied, File Unknown, OS error information = 5.
First-chance exception in WebServer.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
I have tried stepping through it and looking at msdn.microsoft.com (what a joke) for the error message and the steps to resolve it but can't find anything. Here is a code snippet and let me know if I am doing something wrong.
CFile SendFile;
if (!SendFile.Open("c:\\wwwroot\\index.html", CFile::readOnly|CFile::shareDenyWrite|CFile::typeBinary))
return -1;
DataLeft=SendFile.GetLength();
SendFile.Read(SendData, (UINT)DataLeft);
I have tried using the CFile Open method and the overloaded constructor to open this file and read it, but to no avail. It opens fine, but when reading in the document I get the exception noted above.
The error is thrown at the call to the Read method. Anyone know what's wrong? I am baffled and my brain is about to fry. This is part of a webserver I'm writing as a hobby project and one I'll post to the site when I can get bare minimums working (that is if anyone is interested)
HomeNuke
----
"Nuke'd Your Home, Yet?"
Run your own PostNuke based web server from home
http://www.homenuke.com
|
|
|
|
|
Get rid from CFile::typeBinary . You cannot use it with CFile , only with derived classes
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|