|
|
#include <lightbox.h>
LboxDlg *Dlg;
void MyFunc( HWND hWnd, LboxDlg *Dlg );
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message )
{
case WM_INITDIALOG:
Dlg = new LboxDlg( hDlg );
return TRUE;
case WM_COMMAND:
if( LOWORD(wParam) == IDCANCEL ) {
EndDialog(hDlg, LOWORD(wParam));
delete Dlg;
return TRUE;
}
if( LOWORD(wParam) == IDC_BUTTON1 ) {
void (*ptr)( HWND hWnd, LboxDlg *Dlg );
ptr = MyFunc;
ptr( hDlg, Dlg );
}
if( LOWORD(wParam) == IDC_BUTTON2 ) {
char *ptr;
ptr = (char *)MyFunc;
((void (*)(HWND, LboxDlg *))ptr)( hDlg, Dlg );
}
break;
}
return FALSE;
}
void MyFunc( HWND hWnd, LboxDlg *Dlg )
{
Dlg->MsgOk( hWnd, "関数呼び出し成功" );
}
| |
|
|
|
|
void (*ptr)( HWND hWnd, LboxDlg *Dlg );
| |
|
|
|
|
#include <lightbox.h>
LboxDlg *Dlg;
void MyFunc( HWND hWnd, LboxDlg *Dlg );
// 上記関数用の関数ポインタ変数を定義する為のマクロ
#define MyFuncPtr(a) void (*a)( HWND hWnd, LboxDlg *Dlg )
// 関数ポインタへキャストする為のマクロ
#define MyFuncCast(a) ((void (*)( HWND, LboxDlg * ))a)
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message )
{
case WM_INITDIALOG:
Dlg = new LboxDlg( hDlg );
return TRUE;
case WM_COMMAND:
if( LOWORD(wParam) == IDCANCEL ) {
EndDialog(hDlg, LOWORD(wParam));
delete Dlg;
return TRUE;
}
if( LOWORD(wParam) == IDC_BUTTON1 ) {
MyFuncPtr(ptr);
ptr = MyFunc;
ptr( hDlg, Dlg );
}
if( LOWORD(wParam) == IDC_BUTTON2 ) {
char *ptr;
ptr = (char *)MyFunc;
MyFuncCast(ptr)( hDlg, Dlg );
}
break;
}
return FALSE;
}
void MyFunc( HWND hWnd, LboxDlg *Dlg )
{
Dlg->MsgOk( hWnd, "関数呼び出し成功" );
}
| |
|
|
|