|
you can include resources, which will not be editable in the Resource editor of the VS. Interesting for constant stuff as error messages or data as images. Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hello,
In my MFC application, i added one Dialog resource and give class name as CSample.
I can invoke this dialog through;
CSample obj;
obj.DoModal();
Can i create user defined constructor for dialog class CSample.
If i want to pass some parameter to this class through constructor, can i pass it?Abhijit
|
|
|
|
|
Yes, you can. Just declare the type in the header file and add the definition in the cpp file.
I wonder why haven't you tried?!
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I just want to pass the parameter for dialog class before dialog get invoke.
|
|
|
|
|
Abhijit D. Babar wrote: I just want to pass the parameter for dialog class before dialog get invoke.
Go ahead.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Abhijit D. Babar wrote:
Can i create user defined constructor for dialog class CSample.
Yes.
Abhijit D. Babar wrote: If i want to pass some parameter to this class through constructor, can i pass it?
Yes.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]
|
|
|
|
|
Yes, you can create user defined constructor, and yes, you can pass parameters through the constructor to the dialog, but as the CDialog already gets a CWnd* as constructor parameter, NULL if nothing else is said.
CSample (CWnd* pParent = NULL);
I would use Set/Get methodes to pass parameters, because if you overload the constructor parameters, it may be that the MFC (if you use it) gives you problems if you have an error overloading the constructor. After just use the contructor to initialize the member variables/pointers
I mean:
CSample obj;
obj.SetParam1(value1);
obj.SetParam2(value2);
...
obj.DoModal ();
So you are passing the parameters before it gets invoked as you said in an answer to RajeshRegards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: I would use Set/Get methodes to pass parameters, because if you overload the constructor parameters, it may be that the MFC (if you use it) gives you problems if you have an error overloading the constructor. After just use the contructor to initialize the member variables/pointers
Well, it looks to me a super-defensive approach.
[added]
Actually, I suppose I didn't get you. You are right, error handling in class constructor is troublesome.
[/added]
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]
|
|
|
|
|
Thanks Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hello,
I want to know datatype for "this" pointer in C++.
Can you explain with small example.Abhijit
|
|
|
|
|
There are two ways to look at it:
1. this is a pointer and all pointers are of type ptrdiff_t.
2. Since this is defined for a particular class, its type is the pointer to that class.
-Saurabh
|
|
|
|
|
Your #2 is right. I'm afraid you fell asleep while typing your #1. ptrdiff_t is the type for the difference between 2 pointers. No pointers are themselves of type ptrdiff_t. Please do not read this signature.
|
|
|
|
|
Yes any pointer except class-function-pointers can be saved in prtdiff_t type. It is 32-bits on 32-bit machine and 64-bit on 64-bit machine. Don't let them diff in type confuse you. Check the following articles.
About size_t and ptrdiff_t[^]
http://www.viva64.com/terminology/ptrdiff_t.html[^]
If you don't believe them then here are the definitions from crtdefs file:
#ifndef _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef _W64 int intptr_t;
#endif
#define _INTPTR_T_DEFINED
#endif
#ifndef _PTRDIFF_T_DEFINED
#ifdef _WIN64
typedef __int64 ptrdiff_t;
#else
typedef _W64 int ptrdiff_t;
#endif
#define _PTRDIFF_T_DEFINED
#endif
As you can see, intptr_t and ptrdiff_t are defined identically.
-Saurabh
|
|
|
|
|
Well that's three people who got it wrong. ptrdiff_t is an integral value used to store the difference between two pointers. While you can store a pointer (by casting) in such a variable that is not the same as saying that the datatype of this is ptrdiff_t . The datatype of this is always pointer to the instance of the class in which it is used.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard, being one of the three posts leading up to yours ( and having gotten a 1 vote ) are you saying that I got it wrong? If so, I don't understand as we were both saying the same thing. Specifically:
ptrdiff_t is the type for the difference between 2 pointers. No pointers are themselves of type ptrdiff_t.
and refering to Saurabh's post
this ... , its type is the pointer to that class.Please do not read this signature.
|
|
|
|
|
Sorry no, I was not challenging your comments, with which I obviously agree; nor did I 1-vote you. I was alluding to the comments in Saurabh's post (and the linked articles) that there was not much difference between pointers and ptrdiff_t types. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I didn't think you were the 1-voter, but I was puzzled by who the "3 people" were. I didn't think of the 2 links. BTW, the two links are evidently 1 person. The article linked to on CP also appears on the business website linked to. Please do not read this signature.
|
|
|
|
|
It's type is a pointer to the class in which you are using it. Suppose you are using the this keyword inside a method of the CMyClass class, then its type will be CMyClass* .
|
|
|
|
|
It is a pointer to the current instance of the class, e.g.
class A
{
int a;
public:
A(int a)
{
this->a = a;
}
};
so it's type depends on the class, as for class A , it is A * .
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]
|
|
|
|
|
The static definition for "this" is "pointer to the in-scope class type", hence CPallini sample, above.
The "runtime" type it refers to, may be different: typeid(*this) is the "actual type", and may be a derived class, if *this is polymorphic.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
I'll add the point that the "this" pointer is non-modifiable. (The pointer, not the object.)
Its type is also impacted by whether the member function you are talking about is const or volatile.Please do not read this signature.
|
|
|
|
|
OK, why the 1 vote when all that I said is in the standard?
Explicitly:
C++ standard 9.3.2.1:
In the body of a nonstatic member function, the keyword this is a non-lvalue expression whose value is the address of the object for which the function is called. The type of this in a member function of a class X is X*. If the member function is declared const, the type of this is const X*, if the member function is declared volatile, the type of this is volatile X*, and if the member function is declared const volatile, the type of this is const volatile X*.Please do not read this signature.
|
|
|
|
|
If your class is T then the type of 'this' pointer would be T * const this;. i.e; 'this' pointer would be a constant pointer to the class T.
If there is a const member function in T, then 'this' pointer inside that member function would be of type const T * const this;
|
|
|
|
|
hi to all
i have this problem with win32 code. vc++ console based application.
i have a module...where some inputs/messsages keeps coming.....what I want is to....wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message.... (reason : main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)...
please give me some solution to the problem....or is there anything(funtion/concept) available in win32 (vc++)...
all i need to do is prcess the messages when queue is not empty, otherwise do nothing...
thnaks in advance
|
|
|
|
|
What about documentation: "Multithreading with C and Win32"?
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]
|
|
|
|