| | |
assign number to function
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
Hi and sorry for the inconvenience
I am trying to make an interface where a function is run given a number(windows API).
I want a default function to be run if it hasn't been overwritten by the user.
So my question is can i assign a number to a function/method
like using this number I am going to access this function.
Any help is deeply appreciated
I am trying to make an interface where a function is run given a number(windows API).
I want a default function to be run if it hasn't been overwritten by the user.
So my question is can i assign a number to a function/method
like using this number I am going to access this function.
Any help is deeply appreciated
All i've got is a slice of pi
something like this:
C++ Syntax (Toggle Plain Text)
void foo( int x = 0) { switch( x ) { case 0: printf("case 0\n"); break; case 1: printf("case 1\n"); break; default: printf("default\n"); break; } } int main() { foo(); foo(1); }
Last edited by Ancient Dragon; May 9th, 2009 at 1:17 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
Yes but in an automated way so I can add functions at runtime and make it have a value.
I know I could do this with a loop and an if statement but it would be optimal if could check if the message is being handled and abort if not
btw should I use function pointers for this?
I know I could do this with a loop and an if statement but it would be optimal if could check if the message is being handled and abort if not
btw should I use function pointers for this?
All i've got is a slice of pi
Yes, function pointers might be helpful, but you would still have to have a list of pre-defined functions just as I had in the code I posted. For example if the command string were "say hello" the program could not call a function say() at run time unless it was already known at compile time.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
The problem is that it is the windows API we are talking about and I can't have a predefined function for every windows message.
I was thinking something like obtaining a function pointer and the message number from the user and let that overwrite the default behavior(DefWindowProc()).
so I was thinking maybe there was a way of connecting the function and the number
I was thinking something like obtaining a function pointer and the message number from the user and let that overwrite the default behavior(DefWindowProc()).
so I was thinking maybe there was a way of connecting the function and the number
All i've got is a slice of pi
If the program knows the HWND handle then call SetWindowLong() to hook into its default proc
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
Thank You!
this is what I've got.
There are some problems and you can't replace a function but I can handle that myself
this is what I've got.
There are some problems and you can't replace a function but I can handle that myself
CPP Syntax (Toggle Plain Text)
class msghandler { public: void HandleMessage(WNDPROC func, UINT msg); LRESULT CALLBACK handle(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); private: std::vector<msg_func> msglist; }; LRESULT msghandler::handle(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { std::vector<msg_func>::iterator iter; for(iter = msglist.begin(); iter < msglist.end(); iter++) //loop until find match { if((*iter).msg == msg) { return (*iter).function(hWnd, msg, wParam, lParam); //return user defined function's return value } } return DefWindowProc(hWnd, msg, wParam, lParam); //return DefWindowProc } void msghandler::HandleMessage(WNDPROC func, UINT msg) { msg_func temp; temp.function = func; temp.msg = msg; msglist.push_back(temp); }
All i've got is a slice of pi
![]() |
Similar Threads
- addEventListener not adding var in function (JavaScript / DHTML / AJAX)
- random number (C++)
- assign elements to a multi-d array (C)
- Parameter lists for fucntion pointers?? (C)
- generating an auto number (Visual Basic 4 / 5 / 6)
- Wierd error messages with calculator program (C++)
- Help with Class, stuck. (C++)
- 35 processes, need to trim the fat (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: how to read inful file by using command line?
- Next Thread: Choosing a Node in a Linked List
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






