View Javadoc

1   /**
2    * .
3    */
4   package org.sirius.server.win32.classes;
5   
6   import org.sirius.server.win32.constants.IICCConsts;
7   import org.sirius.server.win32.core.CommCtl;
8   import org.sirius.server.win32.core.CommCtl.INITCOMMONCONTROLSEX;
9   import org.sirius.server.win32.core.DlgWin32API;
10  import org.sirius.server.win32.core.Kernel32Ext;
11  import org.sirius.server.win32.core.User32Ext;
12  
13  import com.sun.jna.Pointer;
14  import com.sun.jna.platform.win32.Shell32;
15  import com.sun.jna.platform.win32.WinDef.HMENU;
16  import com.sun.jna.platform.win32.WinDef.HWND;
17  import com.sun.jna.platform.win32.WinDef.LPARAM;
18  import com.sun.jna.platform.win32.WinDef.WPARAM;
19  
20  /**
21   * @author Myk Kolisnyk
22   * .
23   */
24  public class Common implements IICCConsts {
25  
26      /**
27       * .
28       */
29      private final int wordShift = 16;
30  
31      /**
32       * .
33       */
34      private Shell32     shell32   = Shell32.INSTANCE;
35      /**
36       * .
37       */
38      private User32Ext   user32    = User32Ext.INSTANCE;
39      /**
40       * .
41       */
42      private DlgWin32API dlg32     = DlgWin32API.INSTANCE;
43      /**
44       * .
45       */
46      private Kernel32Ext kernel32  = Kernel32Ext.INSTANCE;
47      /**
48       * .
49       */
50      private CommCtl     commCtl32 = CommCtl.INSTANCE;
51  
52      /**
53       * @return the shell32
54       */
55      public final Shell32 getShell32() {
56          return shell32;
57      }
58  
59      /**
60       * @return the user32
61       */
62      public final User32Ext getUser32() {
63          return user32;
64      }
65  
66      /**
67       * @return the dlg32
68       */
69      public final DlgWin32API getDlg32() {
70          return dlg32;
71      }
72  
73      /**
74       * @return the kernel32
75       */
76      public final Kernel32Ext getKernel32() {
77          return kernel32;
78      }
79  
80      /**
81       * @return the commCtl32
82       */
83      public final CommCtl getCommCtl32() {
84          return commCtl32;
85      }
86  
87      /**
88       * .
89       */
90      public Common() {
91          // TODO Auto-generated constructor stub
92      }
93  
94      /**
95       * .
96       */
97      public final void initCommonControls() {
98  
99          INITCOMMONCONTROLSEX lpInitCtrls = new INITCOMMONCONTROLSEX();
100         lpInitCtrls.dwICC = IICCConsts.ICC_ALL;
101         commCtl32.InitCommonControlsEx(lpInitCtrls);
102     }
103 
104     /**
105      * .
106      * @param input .
107      * @return .
108      */
109     public final HMENU longToHmenu(final long input) {
110         HMENU handle = new HMENU();
111         handle.setPointer(Pointer.createConstant(input));
112         return handle;
113     }
114 
115     /**
116      * .
117      * @param input .
118      * @return .
119      */
120     public final HWND longToHwnd(final long input) {
121         HWND handle = new HWND();
122         handle.setPointer(Pointer.createConstant(input));
123         return handle;
124     }
125 
126     /**
127      * .
128      * @param a .
129      * @param b .
130      * @return .
131      */
132     public final long makeLong(final int a, final int b) {
133         return a | (b << wordShift);
134     }
135 
136     /**
137      * .
138      * @param a .
139      * @param b .
140      * @return .
141      */
142     public final LPARAM makeLParam(final int a, final int b) {
143         LPARAM lParam = new LPARAM(makeLong(a, b));
144         return lParam;
145     }
146 
147     /**
148      * .
149      * @param a .
150      * @param b .
151      * @return .
152      */
153     public final WPARAM makeWParam(final int a, final int b) {
154         WPARAM wParam = new WPARAM(makeLong(a, b));
155         return wParam;
156     }
157 
158     /**
159      * .
160      * @param hwnd .
161      * @param msg .
162      * @param wparam .
163      * @param lparam .
164      */
165     public final void postMessage(final long hwnd, final int msg,
166             final int wparam, final int lparam) {
167         user32.PostMessage(longToHwnd(hwnd), msg, new WPARAM(wparam),
168                 new LPARAM(lparam));
169     }
170 
171     /**
172      * .
173      * @param hwnd .
174      * @param msg .
175      * @param wparam .
176      * @param lparam .
177      * @return .
178      */
179     public final int sendMessage(
180             final long hwnd,
181             final int msg,
182             final int wparam,
183             final int lparam) {
184         return user32.SendMessage(longToHwnd(hwnd), msg, new WPARAM(wparam),
185                 new LPARAM(lparam));
186     }
187 }