Using delegate for WindowProc - Is possible and fun!
bls
bizprac at orange.fr
Thu Dec 29 13:40:17 PST 2011
On 12/28/2011 03:45 PM, Tal wrote:
> Can I do something like this :
> ______________________________________________________________________
> extern (Windows) LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,
> LPARAM lParam) MyWinProcDelegate;
>
> this() {
> MyWinProcDelegate =&Events;
> }
>
> extern (Windows) LRESULT Events (HWND hWnd, UINT message, WPARAM wParam,
> LPARAM lParam) {
> MessageBoxA(null , "Success!!!" , null ,0);
> return DefWindowProcA(hWnd, message, wParam, lParam);
> }
> ______________________________________________________________________
>
> The Events() doesn't seem to fire... am I missing something ?
Hi Tal.
I have added an other example using array of delegates. I guess I know
what you want to do... so do not miss the end of the document. Enjoy.
import std.stdio;
import std.functional;
int main(string[] argv)
{
// array of delegates
extern(Windows) int delegate( int i)[] dg;
alias dg callback;
// function to delegate
callback ~= toDelegate( &test ); // std.functional
writeln( callback[0]( 1 ) );
callback ~= toDelegate( &inc );
writeln( callback[1] (0) );
writeln (callback[0]( 1 ) );
readln();
return 0;
}
extern(Windows) int test(int i) { return 41 +i;}
extern(Windows) int inc(int i) { return ++i;}
------------------------------------------------------------------------------------
// Now an associative array of delegates indexed by (of course) HWND ;)
extern (Windows)
LRESULT delegate (HWND hWnd, UINT message, WPARAM wParam,LPARAM
lParam)[HWND] dg;
alias dg MyWinProcDelegate;
bjoern
More information about the Digitalmars-d-learn
mailing list