| | |
assign number to function
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
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.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
•
•
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.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
•
•
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
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
•
•
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
Views: 306 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct studio temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






