Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 KB | None | 0 0
  1. /**
  2.     @file
  3.     scrollmouse - send scroll messages to output
  4.    
  5.     @ingroup    examples
  6. */
  7.  
  8. #include "ext.h"                            // standard Max include, always required
  9. #include "ext_obex.h"                       // required for new style Max object
  10. #include "jit.common.h"
  11.  
  12.  
  13. #include <Windows.h>
  14.  
  15.  
  16. ////////////////////////// object struct
  17. typedef struct _scrollmouse
  18. {
  19.     t_object                    ob;         // the object itself (must be first)
  20.     void *m_outlet1;
  21.     WNDPROC oldproc;
  22.     HWND hWnd;
  23.     t_symbol *ctxt;
  24. } t_scrollmouse;
  25.  
  26. ///////////////////////// function prototypes
  27. //// standard set
  28. void *scrollmouse_new(t_symbol *s, long argc, t_atom *argv);
  29. void scrollmouse_free(t_scrollmouse *x);
  30. void scrollmouse_assist(t_scrollmouse *x, void *b, long m, long a, char *s);
  31. void scrollmouse_start(t_scrollmouse *x);
  32. LRESULT CALLBACK MyOwnWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam);
  33.  
  34. //////////////////////// global class pointer variable
  35. void *scrollmouse_class;
  36.  
  37. void ext_main(void *r)
  38. {
  39.     t_class *c;
  40.  
  41.     c = class_new("scrollmouse", (method)scrollmouse_new, (method)scrollmouse_free, (long)sizeof(t_scrollmouse),
  42.                   0L /* leave NULL!! */, A_GIMME, 0);
  43.  
  44.     // Methods
  45.     class_addmethod(c, (method)scrollmouse_assist, "assist", A_CANT, 0);
  46.     class_addmethod(c, (method)scrollmouse_start, "start", 0);
  47.     class_register(CLASS_BOX, c); /* CLASS_NOBOX */
  48.     scrollmouse_class = c;
  49. }
  50.  
  51. void scrollmouse_assist(t_scrollmouse *x, void *b, long m, long a, char *s)
  52. {
  53.     if (m == ASSIST_INLET) { // inlet
  54.         sprintf(s, "need a start message %ld", a);
  55.     }
  56.     else {  // outlet
  57.         sprintf(s, "scroll move %ld", a);
  58.     }
  59. }
  60.  
  61. void scrollmouse_free(t_scrollmouse *x)
  62. {
  63.     ;
  64. }
  65.  
  66.  
  67. void *scrollmouse_new(t_symbol *s, long argc, t_atom *argv)
  68. {
  69.     t_scrollmouse *x = NULL;
  70.     long i;
  71.  
  72.     if ((x = (t_scrollmouse *)object_alloc(scrollmouse_class))) {
  73.        
  74.         x->m_outlet1 = intout((t_object *)x);
  75.        
  76.     }
  77.     return (x);
  78. }
  79.  
  80.  
  81. void scrollmouse_start(t_scrollmouse *x)
  82. {
  83.     void *window;
  84.  
  85.     if(x->oldproc == NULL)
  86.     {
  87.         window = jit_object_findregistered(x->ctxt);
  88.         if(window)
  89.         {
  90.             jit_object_method(window, gensym("get_window_ptr"), &x->hWnd);
  91.         } else {
  92.             x->hWnd = main_get_client(); //if no argument, get the patcher window
  93.         }
  94.        
  95.         if(SetProp(x->hWnd,"scrollmouse", x)) {
  96.                 x->oldproc = (WNDPROC) SetWindowLongPtr(x->hWnd, GWLP_WNDPROC,(LONG)MyOwnWndProc);
  97.         } else {
  98.             post("Couldn't setProp()");
  99.         }  
  100.     }  
  101. }
  102.  
  103. LRESULT CALLBACK MyOwnWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
  104. {
  105.     t_scrollmouse *x = (t_scrollmouse*) GetProp(hwnd,"scrollmouse");
  106.     switch (umsg)
  107.     {
  108.         case WM_MOUSEWHEEL:
  109.             //post("a");
  110.             //post("%hd", GET_WHEEL_DELTA_WPARAM(wParam));
  111.             outlet_int(x->m_outlet1, (int) GET_WHEEL_DELTA_WPARAM(wParam));
  112.         return 0; // return, or can also pass to orig proc
  113.     }
  114.     if (x && x->oldproc) return CallWindowProc(x->oldproc, hwnd, umsg, wParam, lParam);
  115.     else return DefMDIChildProc(hwnd, umsg, wParam, lParam);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement