|
Hi,
Still new to programming....kinda confused right now.
I created a MFC app to create a standard text editor.(My base class is Ceditview) I wanted to know how i could have the editor have a set string of text on it as soon as it starts.
Basically I want to make it look like a List Control window. Having strings of text passes into the editor window as a display listing. But I also want to allow for regular paragraphs to be passed in? Can this be done or is there a better solution?
Thanks in advance.
|
|
|
|
|
Use SetWindowText in OnCreate.
Hard to suggest a better solution as I dont know what you want the user to do with the pre defined text. But one is to have a list control and an edit control.
Magnus
|
|
|
|
|
I would like to use the predefined text as a column heading. The only thing is that I will have a mixed form of the things that i want to put in the editor.
For example:
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5
1 345 456 567 678 789
2 987 876 765 654 543
This is a line of code that will be inserted in the middle of my so called "table" of information. There is no defined length. This is all entered from another dialog box.
3 123 234 345 456 567
4 678 789 910 566 556
I hope this makes it a little easier for me to understand. I originally wanted to use a ListControl, but since i need to add that paragraph, i couldn't. Unless i can expand it across the columns.
Thanks again in advance.
|
|
|
|
|
Then you have only the editbox, or Richedit if you want more formation options, as an option, unless you make it a little more advanced and use a grid that has support for text over several columns.
There is a really good grid on Codeproject, but I dont know if it supports text over several columns.
Magnus
|
|
|
|
|
Magnus,
Thanks for your help. Can you tell me how I can do this though? I can't the predefined string to the editbox upon startup of the app. Can you or anyone tell me how to do that? How would I format this text? (something like setw() in a cout statement?)
Thanks again.
|
|
|
|
|
Jay Hova wrote:
How would I format this text? (something like setw() in a cout statement?)
Not unless you are working on a console application. Since you've mentioned the use of an edit control and a list control, you are obviously not working on a console application, but rather a GUI application.
Send formatted text to either using a CString object. It has a nice Format() method.
Here's a very simple example:
void CMyEditView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
CEdit &Edit = GetEditCtrl();
Edit.SetWindowText("Hello World");
CString str;
str.Format("2 * 2 = %d", 2 * 2);
Edit.SetWindowText(str);
}
|
|
|
|
|
I know that I can use SetupIterateCabinet from Setup API to uncompress .cab-files.
Will this function uncompress zip-files? Is there another ways to work with zip archives in
C/C++?
|
|
|
|
|
|
I have 4 DLLs as following:
CFiles.dll
CExceptions.dll
CXML.Dll
CDataFormat.dll
CExceptions contains an Object factory that follows the Loki Object Factory model as following:
It has a map containing function pointers with enteries such as following:
void CExceptionFactory::InitializeMap()
{
AddToMethodMap(CExceptionFactory::DATABASE_EXCEPTIONS, CreateDatabaseExceptions);
AddToMethodMap(CExceptionFactory::NULL_POINTER_EXCEPTIONS, CreateNullPointerExceptions);
AddToMethodMap(CExceptionFactory::READER_EXCEPTIONS, CreateReadExceptions);
}
Now, within the DataFormat DLL, depending on the type of formatting, I load different DLLs. For instance, if the type is XML, I load the XML dll as following:
case ID_XML:
{
//m_pDataFormat = new XML();
HMODULE hLibrary = 0;
DataFormatProc pfnDataFormat = 0;
GEA pfnGEA = 0;
hLibrary = ::LoadLibrary("CXML.dll");
if(hLibrary != 0)
{
DWORD dw = 0;
pfnDataFormat = (DataFormatProc) GetProcAddress (hLibrary, "CreateXMLSingletonInstance");
dw = GetLastError();
if(pfnDataFormat != 0)
m_pDataFormat = pfnDataFormat();
m_pDataFormat->LoadFile(L"Stocks.xml");
::FreeLibrary(hLibrary);
}
Now if the method LoadFile above fails, it throws an exception by calling CExcpetionFactory class above and CExceptionFactory will try to look inside its Loki map and retrieve the required method as shown below:
CExceptionFactory::CExceptionFactory(int nTypeID, const string & strMessage)
{
InitializeMap();
CreateObject(nTypeID);
if(m_pException != 0)
{
m_pException->Log(strMessage);
delete m_pException;
}
else
{
throw CExceptionFactory(CExceptionFactory::NULL_POINTER_EXCEPTIONS,"Unknown Exception.");
}
}
void CExceptionFactory::CreateObject(int nTypeID)
{
CallbackMap::const_iterator i = m_Callbacks.find(nTypeID);
if( i != m_Callbacks.end())
{
m_pException = (i->second)();
}
else
m_pException = 0;
}
Now, as soon as the code hits (i->second)(); , it leaves the exception dll all together and goes back to the beginning of that case statement above.
I am quite puzzled with this behaviour.
I am guessing I have a function pointer to begin with the loaded DLL and then I am getting a second function pointer and the compiler gets confused, but why should it?
Your help would be highly appreciated.
thanks
|
|
|
|
|
Well it sounds like you have corrupted your stack. Then you can end up any where in your code when calling function.
Magnus
|
|
|
|
|
how do i get WM_KEYDOWN for controls like a CEdit or a CComboBox (not for the window..)? In VC++ i can only use some events like a OnChange() and others.. but can i intercept other messages too?
Thanks,
Bye
|
|
|
|
|
Yes, but you need to subclass the control you're interested in. Derive your own class from CEdit (or other class as appropriate). If you're creating the control yourself using the Create() member function, use your class in place of CEdit.
If you're interested in a control that's on, for example, a dialog (or another control that's created by some piece of code you can't modify), create an object of your class with a lifetime at least as long as the control, then call SubclassWindow() on the object, passing the window handle of the control you're interested in.
Typically, if the control is on a dialog, you'll create the object that manages the control as a member variable of the dialog's class.
Alternatively using DDX_Control() in a DoDataExchange() function works well.
The change event (EN_CHANGE, a WM_COMMAND message) is actually sent by the edit control during its processing of the message that caused the control's contents to change.
--
Mike Dimmick
|
|
|
|
|
and how do i add a event handler? or do i have to write a different class for every edit control?
|
|
|
|
|
Derive your control from CEdit into CMyEdit. Replace occurences of CEdit in the Message Mapping for CMyEdit. Then, all "usual" CEdit event handlers will be available, plus the "usual" window message handler.
~RaGE();
|
|
|
|
|
To decouple things a bit, you could have your subclassed edit control send a message back to its parent window, perhaps something in the WM_APP range (e.g. WM_APP + 1).
In the parent window class, you would then handle your WM_APP message using an ON_MESSAGE() entry in the message map. See MFC Technical Note 6[^] for more information about ON_MESSAGE .
To handle a custom message, your function should be prototyped as LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam) .
As an alternative, you could do what the edit control normally does and send a WM_COMMAND message with a code you define (that doesn't clash with the normal edit control notification codes), the ID of your control (which you can get with GetDlgCtrlID ) and the window handle of the control (m_hWnd ). This does run the risk of potentially clashing with a Windows-defined message code in a future version of Windows. The existing codes are defined in WINUSER.H . If you go this way, handle the message with ON_CONTROL() .
--
Mike Dimmick
|
|
|
|
|
thank you very much!
I'll try and see what i can do.
|
|
|
|
|
if i have file name, is there any function that can give me the path or diretory where the file is saved?
for example, filename = notepad.exe
then path = c:\window
thank you
|
|
|
|
|
One solution is FindFirstFile() and FindNextFile().
Kuphryn
|
|
|
|
|
Use AssocQueryString(ASSOCF_OPEN_BYEXENAME,ASSOCSTR_EXECUTABLE,...) . For this to be included in your IDE you might need to download the latest SDK from MS.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
pnpfriend wrote:
for example, filename = notepad.exe
then path = c:\window
Unless I've moved Notepad.exe to c:\some\path\way\down\deep\in\windows
You'll need to use kuphryn's suggestion.
|
|
|
|
|
I'm writting an application that does several processing steps on a file, like encription, compression, checksum calculation, etc, and writes the result to another file. And this is to be done with lots of files of different sizes.
I'ld like to know if, in terms of performance, it would be better to use the CRT, the Win32 API for File I/O or the Win32API for File Mapping or another that I'm not aware .
Also I'ld like to know if using concurrent threads to write several files to disk at the same time would be a good option or would it cause havoc in the file system.
Thank you
Artur Jales Moreira
|
|
|
|
|
MC crt usually uses Win32 APIs anyway.
File mapping is useful because you work with memory and write to the file once.
If you can divide your application tasks to write several files at once, it is a great idea( it is probably one of the most efficient use of MT).
|
|
|
|
|
Win32 API would be the fastest because all the other methods use Win32 API but as I say that it does not make a lot of difference because the hard drive is much slower than memory or the CPU so a few more cpu instructions will not make a difference when the CPU executes billions of instructions a second.
jales wrote:
Also I'ld like to know if using concurrent threads to write several files to disk at the same time would be a good option or would it cause havoc in the file system.
If the OS did not cache the data this would be very bad for performance because this will cause the disk to thrash, however with cache some of this will be masked by the system. I do not recommend this however.
John
|
|
|
|
|
jales wrote:
I'ld like to know if using concurrent threads to write several files to disk at the same time would be a good option or would it cause havoc in the file system
Definitely : do not do that.
~RaGE();
|
|
|
|
|
And why not? There is no problem having several threads writing to different files the same time.
What will be a problem is having several threads writing to the SAME file at the same time.
Magnus
|
|
|
|