www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - mousehandler

reply "hr" <hr hr.com> writes:
hi,
could anyone please explain how an array of Handlers is defined?


void Handler(int, int);

struct WData {
     POINTS mouse;               // Current location of the mouse
     Queue clicks[WM_MOUSELAST - WM_MOUSEFIRST + 1];           // 
Array to hold the coordinates of the clicks
     int mouse_queuing[WM_MOUSELAST - WM_MOUSEFIRST + 1];      // 
Array to tell whether mouse events should be queued
     Handler mouse_handlers[WM_MOUSELAST - WM_MOUSEFIRST + 1]; // 
Array of mouse event handlers
     int refreshing;             // True if autorefershing should 
be done after each drawing event
};


how is that: Handler mouse_handlers[WM_MOUSELAST - WM_MOUSEFIRST 
+ 1] translated to D?

thank you
Oct 27 2012
parent reply "Tobias Pankrath" <tobias pankrath.net> writes:
try:

Handler[] mouse_handlers = new [WM_MOUSELAST - WM_MOUSEFIRST
+ 1]

or if the size is statically known:
Handler[WM_MOUSELAST - WM_MOUSEFIRST + 1] handler;
Oct 27 2012
parent reply "hr" <hr hr.com> writes:
On Saturday, 27 October 2012 at 11:59:16 UTC, Tobias Pankrath 
wrote:
 try:

 Handler[] mouse_handlers = new [WM_MOUSELAST - WM_MOUSEFIRST
 + 1]

 or if the size is statically known:
 Handler[WM_MOUSELAST - WM_MOUSEFIRST + 1] handler;
Thank you for your help. after doing what you propose, i get the error message: Error 1 Error: function Handler is used as a type void Handler(int, int); is function prototype. any other suggestions?
Oct 27 2012
parent "Tobias Pankrath" <tobias pankrath.net> writes:
On Saturday, 27 October 2012 at 14:05:20 UTC, hr wrote:
 On Saturday, 27 October 2012 at 11:59:16 UTC, Tobias Pankrath 
 wrote:
 try:

 Handler[] mouse_handlers = new [WM_MOUSELAST - WM_MOUSEFIRST
 + 1]

 or if the size is statically known:
 Handler[WM_MOUSELAST - WM_MOUSEFIRST + 1] handler;
Thank you for your help. after doing what you propose, i get the error message: Error 1 Error: function Handler is used as a type void Handler(int, int); is function prototype. any other suggestions?
This works for me: void handler(int a, int b) {} ; void main() { alias void function(int, int) Handler; Handler[] handlers = new Handler[12]; handlers[0] = &handler; }
Oct 27 2012