|
Before I write my own....I need something to auto-magically cleanup resources such as HMODULE, new'd data, GDI objects, etc. Is there a template lib that can handle all these different data types?
For instance, for an HMODULE I need it to call FreeLibrary, for regular new'd memory I need to call delete pData or delete [] pArray.
I've looked through STL, ATL and WTL but they don't seem to have anything that does the trick.
I want to be able to write something like
AutoThingy<hmodule> hLib = LoadLibrary("some.dll");
or
AutoSomething<char*> pData = new char[123];
and not have to worry about the call to FreeLibrary or delete [] before I exit the function.
Todd Smith
|
|
|
|
|
|
Does that class make a distinction between a HGDIOBJ and a HMODULE and a pointer allocated with new , because all three of these types of objects need to be deleted in different manners?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Well, you instruct it how the delete semantics goes for your
kind of resource, via a destructor-policy (that is a template
parameter which takes a class that sole purpose is to implement
a Destroy(T) member function.
Now you can write things like this:
template <>
inline void CAutoDestructor<HANDLE>::Destroy(HANDLE hFile)
{
_ASSERTE(hFile != INVALID_HANDLE_VALUE);
::CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}
typedef CAutoPtr<HANDLE, CAutoDestructor<HANDLE>, INVALID_HANDLE_VALUE> CFileHandle;
or something like:
template <>
inline void CAutoDestructor<HINSTANCE>::Destroy(HINSTANCE hLibrary)
{
_ASSERTE(hInstance != 0);
::FreeLibrary(hInstance);
hInstance = 0;
}
typedef CAutoPtr<HINSTANCE, CAutoDestructor<HINSTANCE>, 0> CLibraryHandle;
I seem to recall that boost has got a similar design, which
you might be interested in. Please check it also there.
Cheers.
--
Maxime Labelle
maxime.labelle@freesurf.fr
|
|
|
|
|
Looks interesting, Thanks!
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I have a CEdit derived class, which has to do the following
1. Whenever user types something, it highlights the text.
2. Remove the highlight, when the user presses Enter key.
The problem is:
I am not able to get a keydown or WM_CHAR message for the Enter key. The Edit box is on a dialog. So (1) works, but the edit box does not know that (2) happened.
Any suggestions?
Thanks
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Try setting the "Want return" property on the edit control (in the resource editor). If that doesn't work, you may need to override your dialog's OnOK() handler and invoke a method on your CEdit derived control.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks for the reply.
I am doing it in OnOK now. But, I was trying to find a better solution, where the Edit box is completely independent in implementation of this highlight stuff.
The ES_WANTRETURN works only for multiline Edit controls, whereas mine is a single line one
Thanks again
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
CWnd::OnSysChar
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Thank you for your help, but this does not work either.
I just tried it... and I receive no calls on this, when I use this in my CEdit derived class.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
What you CAN do, is to detect the loss of focus. This covers a return character, as well as mouse moves and etc. (You probably want to remove the highlight if the user clicks in another control, don't you?)
Try using this:
CWnd::OnKillFocus
afx_msg void OnKillFocus( CWnd* pNewWnd );
Parameters
pNewWnd
Specifies a pointer to the window that receives the input focus (may be NULL or may be temporary).
Remarks
The framework calls this member function immediately before losing the input focus.
If the CWnd object is displaying a caret, the caret should be destroyed at this point.
Note This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
CWnd Overview | Class Members | Hierarchy Chart
See Also CWnd::SetFocus,WM_KILLFOCUS
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
|
|
|
|
|
The situation is different.
I have a window that has a dialogbar that contains this editbox.
When Enter key is pressed, there is no focus change. and the ENTER can be seen only in the parent window derived from CFrameWnd.
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
|
Try handling the WM_GETDLGCODE windows message.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|
I implemented the PreTranslateMessage and handled the WM_KEYDOWN as Matt Gullet suggested and it works great. I had done that before I saw your post and did not try this.
Anyway, Thank you for the help
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Just overide PreTranslateMessage and look for a WM_KEYDOWN message with a wParam of VK_RETURN. You will also have to check the status of the alt/control/shift keys (if needed).
|
|
|
|
|
works like a charm.
Thank you very much
Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
I created an edit control in Win32 as following:
hwndEdit = CreateWindow( TEXT("edit"), tcLabel,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL ,
cxChar + 100, cyChar * (2 * i ) /* * (1 + 2 * i) */, 20 * cxChar + 100,
cyChar * (1.25), hwndDlg, (HMENU) i,
((LPCREATESTRUCT) lParam)->hInstance, NULL)
However, the following catch inside my dialog's WM_COMMAND catch statement, no longer works after creating my edit box :
if (HIWORD(wParam) == EN_CHANGE ||
HIWORD(wParam) == CBN_SELCHANGE)
When I click inside the text boxes, a couple of messages are generated, but they don't correspond to "EN_CHANGE". How would I find out what those messages are within VC btw? Any idea what this problem maybe?
thanks
|
|
|
|
|
When you click in the edit control, Windows will send a WM_SETFOCUS to your dialog to indicate that the focus has changed. The EN_CHANGE notification is sent when the text inside the control changes. A CBN_CHANGE notification is not sent for an edit control.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
You must to Write into the edit for the message EN_CANGE will be cached...;)
Best Reagards...
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
I'm trying to create TAb views like in the Vusial Studio Work space browser or in the Output window, but my project always crashes. Has someone experience on how to program this?
Thanks
|
|
|
|
|
When a file is saved using CArchive, is it then posible to read the file in an application created for Linux??
|
|
|
|
|
Sure, a file is a file is a file. You will just need to mimic CArchive in your linux program.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim Smith wrote:
Sure, a file is a file is a file.
Which brings up the age-old question... Which came first, the file or the filers?
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
<nobr>
Homepage : Sonork = 100.16311 01000010011011110110001000100000011101110110000101110011 00100000011010000110010101110010011001010010111000000000
|
|
|
|
|
Thanks and yes, that makes sence..
|
|
|
|