0

みんな何かやってみたいし、少し助けが必要です。私がやりたいのは、いくつかの関数を作成し、それらのポインターを配列に格納してから、Windowsメッセージプロシージャ内でそれらを呼び出すことです。例えば:

int create_functions[10];
int paint_functions[10];

int func1() {
    // code
}

void func2(int arg1) {
    // code
}

create_functions[0] = *func1; // add pointer of func1 to the first array
create_functions[1] = *func2; // add pointer of func2 to the second array

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch (message) {
        case WM_CREATE:
            // execute create_functions[0] - How do I do it?
        case WM_PAINT:
            // execute paint_functions[0] - How do I do it?
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
             return DefWindowProc(hWnd, message, wParam, lParam);
             break;
        }
        return 0;
    }

私は誰かが尋ねるのを知っています:なぜfunc1 /func2を直接実行しないのですか?実行時に実行する関数を決定するためです。皆さんの助けに感謝します!

編集: コールバック関数はどうですか?使い方がよくわかりませんか?

4

3 に答える 3

3

質問が次のようなものである場合: 関数ポインターを実行するにはどうすればよいですか? http://www.newty.de/fpt/index.htmlなどのトピックに関する記事を参照することをお勧めします。

これがあなたの質問でない場合は、編集して詳細を追加してください。

于 2012-05-11T20:58:48.533 に答える
2

これ

int create_functions[10];
int paint_functions[10];

する必要があります

void (*create_functions[10])(void);
void (*create_functions[10])(int);

// execute create_functions[0] - How do I do it?
// execute paint_functions[0] - How do I do it?

する必要があります

create_functions[0]();
paint_functions[0](some_integer_here);

また

create_functions[0] = *func1; // add pointer of func1 to the first array
create_functions[1] = *func2; // add pointer of func2 to the second array

する必要があります

create_functions[0] = func1; // add pointer of func1 to the first array
create_functions[1] = func2; // add pointer of func2 to the second array

また

create_functions[0] = &func1; // add pointer of func1 to the first array
create_functions[1] = &func2; // add pointer of func2 to the second array

あなたの好みや気分に応じて。

于 2012-05-11T21:01:24.793 に答える
0

wParam で配列へのポインターを渡すことができます。

于 2012-05-11T20:57:53.657 に答える