|
Just a wild stab-in-the dark, but when i first used combo boxes, they always appeared empty to me.
Then I finally twigged that you have to drag out the size of the dropped down list in the dialog editor. i hadn't done this, and my dropped down list was so small it appeared empty.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hello All,
Forgive me if this isn't the right place to post this, but I'm new to this community.
As the subject reads, I would like to pass a ponter to a function as an argument to another function. I'm pretty comfortable with that, but here's the catch: the function is a an method of an object.
Is this possible?
Any suggestions pointning me in the right direction would be apreciated.
Thanks in advance,
mark
|
|
|
|
|
Unless its a static function , you will get errors as there is no this pointer . Therefore you either pass an object , or pass a pointer to a static function.
|
|
|
|
|
The syntax for at typedef of a pointer to a member is:
(a member of CMyClass returning an int and taking a long and a void* as arguments, just an example)
typedef int (CMyClass::* LPFNMYCLASSMEMBER)(long, void*);
...
bool YourFunction(LPFNMYCLASSMEMBER pfnMember)
{
...
CMyClass* pClass = something;
int iRetVal = pClass->*pfnMember(aLongParam, aVoidPtrParam);
...
}
As I have shown you will have to have a valid object on which you can call the member function (unless it's a static member function which has no this pointer). So you cannot use non-static member functions as callbacks, for instance.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Thank you Steen (and Andrew).
I'll let you know how it works out when I try to implement it.
However, could you pleas explain what you mean about "...non-static member functions as callbacks?"
thx,
mark
|
|
|
|
|
A good example is for timers (this is not what you want to do, but it illustrates the problem).
class CTestClass
{
public:
int ANonStaticMember(void* pData);
static int AStaticMember(void* pData);
CString m_csNonStaticData;
static CString m_csStaticData;
}
CString CTestClass::m_csStaticData = "";
int CTestClass::ANonStaticMember (void* pData)
{
m_csNonStaticData = *(CString*)pData;
m_csStaticData = *(CString*)pData;
}
int CTestClass::AStaticMember (void* pData)
{
m_csStaticData = *(CString*)pData;
}
void Foo()
{
SetTimer(NULL, 1000, &CTestClass::AStaticMember);
SetTimer(NULL, 1000, &CTetsClass::ANonStaticMember);
}
The above code will probably not compile, but I hope you get the idea. The key issue here is that a non-static member function is passed a pointer to the object on which it should act (the this pointer) as it first (and hidden) parameter. The function using the callback function will have to know what object to call the function on to be useful.
But I guess, if you pass a pointer to a non-static member function as a callback to a function you write yourself, and if you in that function calls the callback function on a valid object, it could be OK. Didn't think of that.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Thanks for the example-that makes sense.
"...and if you in that function calls the callback function on a valid object, it could be OK. Didn't think of that."
This is probably what I will do for what I'm working on, but it is very good to know that non-static calback wouldn't otherwise work.
--mark
|
|
|
|
|
Might you know why I'm getting an error message like:"term does not evaluate to a function?"
typedef void (BinarySearchTree::*BSTmemptr) (const &int);
main()
{
BinarySearchTree<int,string> t(error); //intitializes a BST
BSTmemptr fnc; //declare pointer to member funct
fnc=BinarySearchTree::remove; //assign funct to pointer
t.*fnc(9); //attempt to call funct--error is for this line
//....
//....
}
thanx again.
|
|
|
|
|
Operator preceedence. Evaluation of the function operator "()" goes before evaluation of ".*". Put t.*fnc in paranthesis and everything works:
fnc=BinarySearchTree::remove;
(t*.fnc)();
For reference, search VC++ docs at MSDN Lib for "pointer to member", see the article "Expressions with Pointer-to-Member Operators".
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Once again, you're right.
Thank you for your patience--it's is sincerely appreciated. I'll also refer to the article.
How long have you been coding for?
|
|
|
|
|
Around 15 years. If interested you can see check my profile (just click on the little head next to my name).
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I Tried to do what I have with success done with a normal program, to put resources in dll files.
I've done everything accordning to "Q198846-HOWTO: Create Localized Resource DLLs for MFC Application".
However, in a ActiveX this doesn't seem to work.
First problem is when compiling the ResourceDll.
It complains that the file "MyOcx.tlb" can't be found, thats not odd, since it hasn't been created yet.
//from the MyOcx.rc file
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
//1 TYPELIB "MyOcx.tlb"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
So I snuffed it out and tried, and it compiled. Well that won't probably work later, but i kept trying.
I Compiled the MyOcx and it worked, until it tries to register the ActiveX Control. Then regsvr32 asserts, so it cant be registered.
I presume it's either the preprocessor def AFX_RESOURCE_DLL or the LoadLibrary i make that crashes it.
So now my question is, can I, in any way, add multilanguage support to my ActiveX, or do I have to think in a totally diffrent way and maybe use plain old textfiles for language files.
TIA
Fredrik Sigbjörn
|
|
|
|
|
Hi,
I recently discovered the CTabCtrlSSL demo on this site (http://www.codeproject.com/tabctrl/ctabctrlssl.asp) and this was exactly what I needed for my problem... but still not completely.
In my program I had the situation in which I have one dialog showing up on 2 places: once as a stand alone modal dialog and once within a tab control as a sheet of the tab control. In situation 1 I need to show the title bar, in the second case I need to hide it. (I created the dialog in the resource as a title-bar-less dialog)
The problem is that I don't know how to do this in an easy way. I figured out it's got something to do with the CreateEx function, but how do I fit all this inside the dlg-framework??
Thanx,
Dave
Structured programming vs. chaotic mind boggling
|
|
|
|
|
How does it work ? (in relation to TCP/IP )
and how||where do I alter it ?
Thanks for your time
Regardz
Colin J Davies
|
|
|
|
|
Hi,
I'm capturing the mouse with "SetCapture()" and then process the mouse movement in OnMouseMove(UINT nFlags, CPoint point).
The problem is that every time I get outside of my dialog window, the OnMouseMove routine isn't called anymore. How come
My project is a dialog based application and I remember not having this problem with a non-dialog based application.
Also how can I make my cursor invisible?
Any idea??
Thanks
|
|
|
|
|
I think non-dialog and dialog based applications have the same problem. Because once the mouse move outside a window, the mouse messages won't be sent to the window unless a mouse button has been pressed down. It is capable even to the window used "SetCapture()". Sorry but it's out of my reach to solve this problem. But you can use the sentence "::SetCursor(::LoadCursor(NULL,NULL));" to make your cursor invisble and use the sentence "::SetCursor(::LoadCursor(NULL,IDC_ARROW));" to restore it. And, you can always use GetCursorPos() function to retrieve the mouse cursor's current position.
Hope it can help you.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Yes, your are right, I noticed that it has nothing to do with dialog/non-dialog based application. It just happened that in one I used the mouse capture while the mouse button was down...
Thanks again for your help
|
|
|
|
|
Not sure if this is a question or just a rant....
Anyway, I was working on a WTL dialog-based app (WHotfixCheck actually (shameless plug!)) and I added a button which calls up a CFileDialog. Well, just adding a reference to CFileDialog added about 120K, yes 120K, to the release build. Wassup wit' dat?!?
Changing the release optimization from max speed to min size got it down to about 90K, but still... that don't make no sense. CFileDialog doesn't do that much.
--Mike--
http://home.inreach.com/mdunn/
"The Earth is doomed." -- Rupert Giles
your with and
|
|
|
|
|
All,
When I deleted my static control in my dialog ,and compiled the project,as the result,the rc file got bigger and bigger--4 megas more. Why ? Who could hlep me ? Thanks in advance .
|
|
|
|
|
Hi, I have had the same problem with an Active-X Control from Microsoft.
Caused by what ever, the Microsoft Flexgrid grew by every compilation to the double size.
I gave up finding the reason and just deleted the control in the rc-file. (You have to do that in textmode) After inserting it again it worked for a while.
|
|
|
|
|
Hi, I dont know the reason fully. but i faced the same problem b4. and u can open the rc file as a text file in msdev. And go throught it. U might see repeatetive entries for some control. delete them in the text file itself.
This might help.
All the best
Kannan S
|
|
|
|
|
hi, it's me again (i think i should register...)
my prob is not a real prob, but here it is:
i'm using a CFileDialog to open/save files, and that works. the only thing is, i want to set the initial directory. i don't like it that i have always to select drive and directory when i'm working longer on a file for example. so i'm planning to use sort of an .ini file for my program. there i want so store the path of the last opened directory.
with CFileDialog, the initial directory is always the same. i tried it with SetCurrentDirectory, but it didn't work. anyway, is there a function that returns the path of the program i'm currently running? in borland c++ (the dos-based ) it was the first array in argv (remember: int main(int argc, char *argv[]) ).
well, it's not that important, but i want to create a user-friendly program. it simply s#x to select the same directory hundreds of times within 5 minutes, i'm sure you know what i mean
greets,
McEck
|
|
|
|
|
You need to make a change to the OPENFILENAME struct of the CFileDialog before calling DoModal():
CFileDialog dlg ( ... );
TCHAR szInitialDir[MAX_PATH];
dlg.m_ofn.lpstrInitialDir = szInitialDir;
--Mike--
http://home.inreach.com/mdunn/
"The Earth is doomed." -- Rupert Giles
your with and
|
|
|
|
|
I use this to get my Application path.
::GetCurrentDirectory(1024, m_strAppPath.GetBufferSetLength(1024));
m_strAppPath.ReleaseBuffer();
You have to use this before you do anything else with files, since you then change the path. For example in InitInstance.
/Fredrik Sigbjörn
|
|
|
|
|
MFC -
Ok I have a combobox (m_cFilters) and in it I have Filters like:
All Files (*.*)
Text Files (*.tx) ...etc.
I want to grab the part between the parenthesis and store it in a var after the combo box is changed (DropDown combo, btw). I tried mapping the standard combo messages but after the functions return they do not update the combo box. What is the proper way to get the effect I am looking for? Is there an easier way to grab data like this other than straight from the combo string?
Thanks.
----
Xian
|
|
|
|