|
Moak wrote: Okay this is the same as Cédric just posted... now you have some links
Na naah naa... you posted ur reply to wrong person!.... "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You can write a creator class which can help you create objects.
Inside the class you will need code that will check the class name and create the object for you -
static void* Creator(char* className)
{
if (strcmp(className, "CMyTestClass") == 0)
return new CMyTestClass;
else if (strcmp(className, "CMyTestClass2") == 0)
return new CMyTestClass2;
.
.
.
}
|
|
|
|
|
«_Superman_» wrote: static void* Creator(char* className){ if (strcmp(className, "CMyTestClass") == 0) return new CMyTestClass; else if (strcmp(className, "CMyTestClass2") == 0) return new CMyTestClass2; . . .}
He he he looks like Factory Pattern "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
transoft wrote: I save this name in a string like:
char* ClassString = "CMyTestClass"
yes it is possible as told by poster above me.. frankly i never do it as it will leave hacker chance to crack my application, better procedure would be to use good old polymorphism "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
This has nothing to do with "hacking". There are some cases where this is extremely useful (it depends a lot on the context of course). And your point about polymorphism has nothing to do with the question. Creating a specific instance of a class using an Id (a name for instance) using a factory pattern uses polymorphism anyway.
Here's a concrete example in which this could be useful. Suppose you have a program that is able to execute a list of operations. The user is able to create an XML file containing the information about the different operations to execute. What you would typically do is have a different nodes in your XML file (one for each operation you want to execute). And for each of these nodes, you can have parameters which are specific to the operation you want to execute. One property of the node is of course the name of the operation to execute. This way, when loading the file you get the name of your operation, delegate the creation of the operation to the factory and pass the parameters to the operation object so that it can "configure" itself from the xml information. Once your object is constructed, you can store it in a list along other operations to be executed. Of course, all the specific operation classes inherit from the same base class (which provide virtual functions like run, loadPropertiesFromXML, ...).
This is of course one simple example but there are a lot of cases where this becomes useful.
|
|
|
|
|
Hi all,
please help me to resolve error of Access is Denied.
When server is Windows server 2008 and client machine is Windows xp Professional with service pack 3.
in network window when i want to access this client machine its popup a username and password window to access.
in my code if i use RegConnectRegistry without entering username password in network window for xp client,this return a error of Access Denied.
if i use RegConnectRegistry after entering username password in network window for xp client,
than its execute,no error return but after the i want to open the registry by RegOpenKey.
now this return error access denied.
please help me what can i do.
thanks.To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Hi...
I am using Visual Studio 2008, and i am working with a multiple document application, it is CView Based. In CView how can i add cbutton?
My code is,
CRect button1Rect;
CButton button1;
button1Rect.SetRect(250,75,400,100);
button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
button1.ShowWindow(SW_SHOW);
the above code not showing the cbutton.
but if the code is like,
CRect button1Rect;
CButton button1;
button1Rect.SetRect(250,75,400,100);
button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
button1.ShowWindow(SW_SHOW);
AfxMessageBox(L"Button created");
It shows the button.
How to solve this problem?
Any help will be appreciated.
Thanks...G.Paulraj
|
|
|
|
|
Umm, your problem is that if you show a message box you see the button on your view but if you don't then there's no button? My guess would be that you need to update your view or maybe your button (make it redraw itself). If you don't bring up the message box but after creating the button you somehow force the view to redraw, like, moving another window around on top of it, do you see your button appearing out of "nowhere"? If yes, then try calling RedrawWindow on your view OR on your button after it was created. > The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
yes..
You are correct. i redraw the window.
Thanks...G.Paulraj
|
|
|
|
|
Did you try calling "Invalidate(false)" function?modified on Monday, February 8, 2010 10:16 AM
|
|
|
|
|
Hi,
button1Rect and button1 should be members to view class. Then only the button will display.Try with that.
cheers!.nss
|
|
|
|
|
The button object has to be a member of your CView derived class. Then, I assume you can override OnInitialUpdate() function and put the code for creating the button in that.
|
|
|
|
|
In my application i need to add grid with specific coloum selection property
is there any method to add check boxes in coloumn headers.
Thanks in advance...
pk
|
|
|
|
|
|
Hi all,
I am trying to convert CString value to double value. see below
if(pos == 0)
{
assfile.ReadString(nextLine);
pos = nextLine.Find(_T(","));
temp = nextLine.Left(pos);
dValue = _wtof(temp);
if (dValue < minval)
minval = dValue;
}
i am using _wtof() to convert string to double. The problem here is after conversion the double value has more decimal points every time.
for example
str = "234.555"
after conversion the double value will be like this 234.55500005
i want the double value to be as it is in the string. how to resolve this?
Thanks in advance.
Regards,
kumarhi
|
|
|
|
|
You can't control that. This is due to the precision of the double which is not perfect. I suggest you google about "floating point precision" to learn more about the subject (see this[^] for instance).
|
|
|
|
|
Did you try:
double dValue = 234.55500005;
long lValue = dValue * 1000;
dValue = lValue / 1000;
|
|
|
|
|
I doubt! "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
As Cedric Moonen said, you cannot control this.
But you can always choose what you want to be displayed by formatting the data.
For example, printf("%.3f", dValue); will only show you 3 decimal digits.
The same formatting can also be used with CStringT::Format and other APIs like StringCchPrintf .
|
|
|
|
|
Hi,
I need to develop a software which will get installed in the user pc and reads the phone number from the attached modem. This phone number will be the users own number not the incoming one. Is it possible using Ms-Comm control?
Regards,
J
|
|
|
|
|
emmmatty1 wrote: Is it possible using Ms-Comm control?
My experience with the MSComm control makes me recommend you to not use the MSComm control at all. It introduces more problems than it solves. Writing the communication with a device such as a modem is fairly simple. For an example on how to do serial communication you can have a look here[^].
If you have any requirements on performance regarding speed you cannot use MSComm.
Whether you use the MSComm control to communicate with the modem or you roll your own solution is up to you. But I'm very curious on how you're planning on getting the phone number of the user where the modem is installed. I am not aware of such functionality or any AT command that supports it.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi,
i need some help to bring a dialog to top, but only for him parent dialog.
I use this to set child dialog on the top, but he still on top for all applications:
::SetWindowPos(pWaitDlg->m_hWnd, HWND_TOP,0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
but i need it to be only for him's parent dialog on top, not for all, this is a small dialog with progressbar on it!
Thanks for any help!!
Arrin
|
|
|
|
|
I think you can try giving handle to the parent window instead of HWND_TOP as second parameter.
|
|
|
|
|
Hi,
thanks for answer, that is!
Only one issue is there , first here is code:
CProgressDlg dlgProgress;
dlgProgress.Create(CProgressDlg::IDD, GetDesktopWindow());
this->EnableWindow(FALSE);
::SetWindowPos(dlgProgress.m_hWnd, this->m_hWnd,0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
dlgProgress.ShowWindow(SW_SHOW);
dlgProgress.CenterWindow();
dlgProgress.BringWindowToTop();
There is only one thing that is not ok, i can switch between this two dialogs if i click they icons in the taskbar,
in this case is this little "dlgProgress"(simple Dialog with progressbar) Dialog in the background of hims parent(if i click on parent icon),
and that is what i need to avoid! This little dlgProgress must be on top of hims parent until the process is finish!
Thanks for help!
Arrin
|
|
|
|
|
May be you can remove the call to GetDesktopWindow().
I think dlgProgress.Create(CProgressDlg::IDD) would be enough.
In addition to that, I suppose dlgProgress has to be a member of the parent dialog.
|
|
|
|