|
what type of variable "name" is?
The following code generates name.txt in my project directory. and dumps the string in file.
ofstream outputFile("name.txt");
ifstream inputFile;
string name = "ABCD";
outputFile << name.c_str();
outputFile.close();
HTH
|
|
|
|
|
Hi,
I've created a custom control where I want to be able to change the colour of the control dependent on the background colour of my dialog, i.e. if the user has customised their dialog I would like to set my control to the same colour.
Is it possible to determine this colour at runtime?
Also, is there a list of predefined colours available, e.g. the default colour of a dialog, and if so where are they defined?
TIA
Tony
|
|
|
|
|
maycockt wrote: Is it possible to determine this colour at runtime?
See Window Background[^] for how this information is held.
maycockt wrote: is there a list of predefined colours available
See GetSysColor()[^].MVP 2010 - are they mad?
|
|
|
|
|
Use the GetClassLongPtr[^] function with the handle of the dialog and GCLP_HBRBACKGROUND as the index.
|
|
|
|
|
May be you can call the following from the custom control:
COLORREF rgb = GetParent()->GetDC()->GetPixel(0, 0);
This may not work if the point (0, 0) on the parent is overlapped by the control.
|
|
|
|
|
Hi
Suppose I have a class like:
Class CMyTestClass {....}
I save this name in a string like:
char* ClassString = "CMyTestClass"
How can I instance this by using this string?
CMyTestClass* pmyClass = new ClassString ????????
Thanks,
|
|
|
|
|
It's possible, but your class should derive from CObject in MFC environment. CRuntimeClass::FromName method could be used to accomplish this task.See here for details. Life is a stage and we are all actors!
|
|
|
|
|
But my class is not derived from "CObject".
How can I do that?
Thanks
|
|
|
|
|
There's no way to do that by default. However, you could create a factory class which is responsible for creating instances of your class (as long as they all inherit from the same base class) based on their name. I suggest you google for "Factory pattern" in C++.
|
|
|
|
|
Cedric Moonen wrote: I suggest you google for "Factory pattern" in C++.
but it factory pattern, all class name should be pre-known, i think he asking for dynamically loading class object. "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
|
|
|
|
|
ThatsAlok but it factory pattern, all class name should be pre-known, i think he asking for dynamically loading class object.
You can't create an instance of a class that doesn't exist... Of course your classes have to be known at compile time, thus you can also populate easily your factory with the names.
Furthermore, even if you were able to create an instance of any class, what would you do with it ? You can't write any code that will use the class because you don't know which object you are manipulating (unless all the classes inherit from the same base class in which case you manipulate the base class).
|
|
|
|
|
|
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
|
|
|
|