|
Not sure I got you, anyway have a look at creational design patterns [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Not sure I got you
I might have not explained clearly Let me try my luck once more
I need some thing simlar to Builder[^] pattern. In that link PizzaBuilder is an abstract class providing methods to override. Many builder classes are derived from it and overrides the functionality. If you look at the main function (C#) you will find
PizzaBuilder hawaiianPizzaBuilder = new HawaiianPizzaBuilder();
PizzaBuilder spicyPizzaBuilder = new SpicyPizzaBuilder(); In this case we knows HawaiianPizzaBuilder or SpicyPizzaBuilder is the one to instantiate.
But in my case, I know only the class is derived from PizzaBuilder and it's name, say CustomPizzaBuilder . In that case, how do I instantiate it?
This can be easily done using reflection in managed code. As reflection is not supported in standard C++, is there a workaround for this? Or how does the Builder pattern is implemented in C++ when we have only the subclass name available?
I hope I made it clear.
|
|
|
|
|
OK. I think you may exploit the Prototype pattern:
(1)
Every new converter, say kConverter , should provide a clone method like
class kConverter : public IConverter
{
public:
IConverter * clone()
{
return new kConverter();
}
};
(2) Every new converter should add himself to a global map<string, IConverter>
Does the above make sense?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Does the above make sense?
Perfect! It did. This is going to work. Many thanks.
I think the clone() method is not needed as I will add new converters to map<string, IConverter> .
Thanks for taking time to help me. A well deserved 5
|
|
|
|
|
N a v a n e e t h wrote: I think the clone() method is not needed as I will add new converters to map<string,>.
Yes, that makes perfect sense.
N a v a n e e t h wrote: Thanks for taking time to help me
You're welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
I prefer not to include any header files in other header files as long as it is possible.
But I have problem when I want to use an Enumeration type in a header file, which is defined in another header file.
I mean we can introduce classes and structs at the start of a header file, but it is not the case about Enumeration Data Types:
struct st1; //correct
Class C1; //correct
Enum e1; //Incorrect
|
|
|
|
|
is this a design question ?
or just trying to inform somebody here ?
if so, I strongly unadvise to do so. that is just not suitable for most advanced designs, and it's just the way C/C++ is designed and intended to work...
so, to make it short, go with #includes withing headers, it's not bad to do so !
|
|
|
|
|
I am not sure, but I think it is a good idea to do such a thing.
Actually I avoid making circular includes in this way.
|
|
|
|
|
reza matinnejad wrote: I avoid making circular includes in this way
this CANNOT happen, as long as you designed your headers correctly.
there is a multiple includes exclusion system which tells for the header which it's defined in not to include it more than once...
If you're using Visual Studio only, the following is good and prefered for performances. This is MS specific:
<font color="green">
<font color="blue">#pragma once</font>
<font color="green">
if your sources are portable on pultiple plateforms, then use the standard construction which works on any compiler (Visual C++ included):
<font color="green">
<font color="blue">#ifndef</font> __YOUR_HEADER_FILE_H_INCLUDED__
<font color="blue">#define</font> __YOUR_HEADER_FILE_H_INCLUDED__
<font color="green">
<font color="blue">#endif</font> <font color="green">//At the very end of the file</font>
|
|
|
|
|
Thank you
|
|
|
|
|
ps, i didn't say it, because it was obvious to me, but you have to be careful that the macros such as "__YOUR_HEADER_FILE_H_INCLUDED__" is unique for each file (if 2 headers define the same macro, redefining identifiers errors may happen)...
|
|
|
|
|
how to disable user from right clicking in Edit Box.and also cant copy or paste using (ctrl+c) and (ctrl+v) in visual c++ project..
|
|
|
|
|
Better idea that I would suggest is to disable the edit box. Use the following function to disable the Edit box.
EnableWindow(FALSE)
Regards,
Rane
|
|
|
|
|
Yes, derive your own class from CEdit and handle WM_CONTEXTMENU message . For information on
WM_CONTEXTMENU[^]
I hope it helps..
Regards,
Sandip.
|
|
|
|
|
can u plz give me a code that using WM_CONTEXTMENU to restrict right cliking in edit box
|
|
|
|
|
You can try something like this..
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
ON_WM_CONTEXTMENU()
ON_MESSAGE(WM_COPY,OnCopy)
ON_MESSAGE(WM_PASTE,OnPaste)
END_MESSAGE_MAP()
void CMyEdit::OnContextMenu(CWnd* pWnd, CPoint point)
{
}
void CMyEdit::OnCopy(WPARAM wParam,LPARAM lParam)
{
}
void CMyEdit::OnPaste(WPARAM wParam,LPARAM lParam)
{
}
And declarations..
protected:
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
void OnCopy(WPARAM wParam,LPARAM lParam) ;
void OnPaste(WPARAM wParam,LPARAM lParam) ;
I hope it helps.
I assume you can derive the class from CEdit and add similar handlers to your class.
Also don't forget to add the control variable of type CMyEdit for the Edit Box.
Regards,
Sandip.
|
|
|
|
|
thanks for da reply
actually i m very beginner to visual c++ so feel problem while deriving plz can u help me further that how to derive myCEdit from CEdit and override its methods etc....
thanks in advance
|
|
|
|
|
I will advise you to read some book on MFC. Windows Programming with MFC by Jeff Prosise is good for beginners.
Now your problem.
1. Select Insert Menu -> New Class.
2. Type In your class name (CMyEdit)and select Base class as CEdit
3. Then add the handlers and their declarations from my previous posts to the class.
4. Add the member variable of type CMyEdit for Edit box.
I hope this makes sense.
But I suggest you to read from book as this is something very basic.
Regards,
Sandip.
|
|
|
|
|
thanks for da help
after deriving CMyedit class from Edit and adding handler of WM_CONTEXTMENU, WM_COPY,WM_PASTE
now plz tell the code to restrict menu and copy,paste using these methods
,means what would be coding to handle menu in these methods
void CMyedit::OnContextMenu(CWnd* pWnd, CPoint point)
{ // TODO: Add your message handler code here
}
void CMyedit::OnCopy(WPARAM wParam,LPARAM lParam) {
// TODO: Add your message handler code here
}
void CMyedit::OnPaste(WPARAM wParam,LPARAM lParam) {
// TODO: Add your message handler code here
}
|
|
|
|
|
Blank implementation will prevent the Menu as well as copy and paste. You must have not added the member variable of type CMyEdit to your dialog in which you have your Edit Box.. You need to associate your class with the EditBox by adding a member variable and respective call to DDX_Control in the functio DoDataExchange()..
No need to edit this manually you can use wizard to add the variable. Only thing wizard will not do is to include header file MyEdit.h which you need to include manually.
I hope it is clear.
Regards,
Sandip.
|
|
|
|
|
Hi all,
I am getting an error here which usually does not happen.
I am getting
Unhandled exception at 0x77ddd83e in UpdateService.exe: 0xC0000005: Access violation reading location 0x00c7913e.
the values are:
hKey {unused=??? } HKEY__ *
lpValueName 0x004b9198 "Installer" const wchar_t *
Reserved 0 unsigned long
dwType 1 unsigned long
lpData "R" const unsigned char *
cbData 520 unsigned long
I wonder why it crashes as I use the same thing to my other inputs it does not happen. the code is this:
RMRegSetValueEx(hkey,UPDATELINK,0,REG_SZ,(BYTE*)((*Iter)->link.c_str()),_MAX_PATH);
RMRegSetValueEx(hkey,UPDATEFILE,0,REG_SZ,(BYTE*)(*Iter)->savePath.c_str(),_MAX_PATH);
RMRegSetValueEx(hkey,UPDATEINSTALL,0,REG_SZ,(BYTE*)(*Iter)->nameVer.c_str(),_MAX_PATH);
LONG RMRegSetValueEx(
HKEY hKey,
LPCTSTR lpValueName,
DWORD Reserved,
DWORD dwType,
CONST BYTE *lpData,
DWORD cbData
)
{
do
{
if (lRegOperLastErr == 1450)
{
Sleep(100);
}
lRegOperLastErr = RegSetValueEx(
hKey,
lpValueName,
Reserved,
dwType,
lpData,
cbData
);
} while (lRegOperLastErr == 1450);
return lRegOperLastErr;
}
At the bold part where the crashing happens at only one time at a specific value, that is being used with other values but does not crash.
Please advise
thanks,
Jayjay
|
|
|
|
|
monsieur_jj wrote: At the bold part where the crashing happens at only one time at a specific value,
What is that specific value that you are passing in?
Regards,
Rane
|
|
|
|
|
Hi Rane,
RMRegSetValueEx(hkey,UPDATEINSTALL,0,REG_SZ,(BYTE*)(*Iter)->nameVer.c_str(),_MAX_PATH);
the UPDATEINSTALL = _T("Installer")
nameVer = "Re-Rite Asian 6.0.0.125"
_MAX_PATH = 260
Is that all you need?
Thanks,
Jayjay
|
|
|
|
|
Why can't you use FormatMessage function to get a generic description of the error?
Regards,
Rane
|
|
|
|
|
Why are you passing _MAX_PATH instead of the actual size (in bytes) of the string?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|