001: /* Copyright (c) 2007 Timothy Wall, All Rights Reserved
002: *
003: * This library is free software; you can redistribute it and/or
004: * modify it under the terms of the GNU Lesser General Public
005: * License as published by the Free Software Foundation; either
006: * version 2.1 of the License, or (at your option) any later version.
007: * <p/>
008: * This library is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: */
013: package org.netbeans.core.nativeaccess.transparency.win32;
014:
015: import com.sun.jna.FromNativeContext;
016: import com.sun.jna.IntegerType;
017: import com.sun.jna.Native;
018: import com.sun.jna.NativeMapped;
019: import com.sun.jna.Pointer;
020: import com.sun.jna.Structure;
021: import org.netbeans.core.nativeaccess.transparency.win32.GDI32.RECT;
022: import com.sun.jna.ptr.ByteByReference;
023: import com.sun.jna.ptr.IntByReference;
024:
025: /** Provides access to the w32 user32 library.
026: * Incomplete implementation to support demos.
027: *
028: * @author Todd Fast, todd.fast@sun.com
029: * @author twall@users.sf.net
030: */
031: public interface User32 extends W32API {
032:
033: User32 INSTANCE = (User32) Native.loadLibrary("user32",
034: User32.class, DEFAULT_OPTIONS);
035:
036: HDC GetDC(HWND hWnd);
037:
038: int ReleaseDC(HWND hWnd, HDC hDC);
039:
040: int FLASHW_STOP = 0;
041: int FLASHW_CAPTION = 1;
042: int FLASHW_TRAY = 2;
043: int FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY);
044: int FLASHW_TIMER = 4;
045: int FLASHW_TIMERNOFG = 12;
046:
047: public static class FLASHWINFO extends Structure {
048: public int cbSize;
049: public HANDLE hWnd;
050: public int dwFlags;
051: public int uCount;
052: public int dwTimeout;
053: }
054:
055: int IMAGE_BITMAP = 0;
056: int IMAGE_ICON = 1;
057: int IMAGE_CURSOR = 2;
058: int IMAGE_ENHMETAFILE = 3;
059:
060: int LR_DEFAULTCOLOR = 0x0000;
061: int LR_MONOCHROME = 0x0001;
062: int LR_COLOR = 0x0002;
063: int LR_COPYRETURNORG = 0x0004;
064: int LR_COPYDELETEORG = 0x0008;
065: int LR_LOADFROMFILE = 0x0010;
066: int LR_LOADTRANSPARENT = 0x0020;
067: int LR_DEFAULTSIZE = 0x0040;
068: int LR_VGACOLOR = 0x0080;
069: int LR_LOADMAP3DCOLORS = 0x1000;
070: int LR_CREATEDIBSECTION = 0x2000;
071: int LR_COPYFROMRESOURCE = 0x4000;
072: int LR_SHARED = 0x8000;
073:
074: HWND FindWindow(String winClass, String title);
075:
076: int GetClassName(HWND hWnd, byte[] lpClassName, int nMaxCount);
077:
078: public static class GUITHREADINFO extends Structure {
079: public int cbSize = size();
080: public int flags;
081: HWND hwndActive;
082: HWND hwndFocus;
083: HWND hwndCapture;
084: HWND hwndMenuOwner;
085: HWND hwndMoveSize;
086: HWND hwndCaret;
087: RECT rcCaret;
088: }
089:
090: boolean GetGUIThreadInfo(int idThread, GUITHREADINFO lpgui);
091:
092: public static class WINDOWINFO extends Structure {
093: public int cbSize = size();
094: public RECT rcWindow;
095: public RECT rcClient;
096: public int dwStyle;
097: public int dwExStyle;
098: public int dwWindowStatus;
099: public int cxWindowBorders;
100: public int cyWindowBorders;
101: public short atomWindowType;
102: public short wCreatorVersion;
103: }
104:
105: boolean GetWindowInfo(HWND hWnd, WINDOWINFO pwi);
106:
107: boolean GetWindowRect(HWND hWnd, RECT rect);
108:
109: int GetWindowText(HWND hWnd, byte[] lpString, int nMaxCount);
110:
111: int GetWindowTextLength(HWND hWnd);
112:
113: int GetWindowModuleFileName(HWND hWnd, byte[] lpszFileName,
114: int cchFileNameMax);
115:
116: int GetWindowThreadProcessId(HWND hWnd, IntByReference lpdwProcessId);
117:
118: interface WNDENUMPROC extends StdCallCallback {
119: /** Return whether to continue enumeration. */
120: boolean callback(HWND hWnd, Pointer data);
121: }
122:
123: boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer data);
124:
125: boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc,
126: Pointer data);
127:
128: boolean FlashWindowEx(FLASHWINFO info);
129:
130: HICON LoadIcon(HINSTANCE hInstance, String iconName);
131:
132: HANDLE LoadImage(HINSTANCE hinst, // handle to instance
133: String name, // image to load
134: int type, // image type
135: int xDesired, // desired width
136: int yDesired, // desired height
137: int load // load options
138: );
139:
140: boolean DestroyIcon(HICON hicon);
141:
142: int GWL_EXSTYLE = -20;
143: int GWL_STYLE = -16;
144: int GWL_WNDPROC = -4;
145: int GWL_HINSTANCE = -6;
146: int GWL_ID = -12;
147: int GWL_USERDATA = -21;
148: int DWL_DLGPROC = 4;
149: int DWL_MSGRESULT = 0;
150: int DWL_USER = 8;
151: int WS_EX_COMPOSITED = 0x20000000;
152: int WS_EX_LAYERED = 0x80000;
153: int WS_EX_TRANSPARENT = 32;
154:
155: int GetWindowLong(HWND hWnd, int nIndex);
156:
157: int SetWindowLong(HWND hWnd, int nIndex, int dwNewLong);
158:
159: // Do not use this version on win64
160: Pointer SetWindowLong(HWND hWnd, int nIndex, Pointer dwNewLong);
161:
162: LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex);
163:
164: LONG_PTR SetWindowLongPtr(HWND hWnd, int nIndex,
165: LONG_PTR dwNewLongPtr);
166:
167: Pointer SetWindowLongPtr(HWND hWnd, int nIndex, Pointer dwNewLongPtr);
168:
169: int LWA_COLORKEY = 1;
170: int LWA_ALPHA = 2;
171: int ULW_COLORKEY = 1;
172: int ULW_ALPHA = 2;
173: int ULW_OPAQUE = 4;
174:
175: boolean SetLayeredWindowAttributes(HWND hwnd, int crKey,
176: byte bAlpha, int dwFlags);
177:
178: boolean GetLayeredWindowAttributes(HWND hwnd,
179: IntByReference pcrKey, ByteByReference pbAlpha,
180: IntByReference pdwFlags);
181:
182: /** Defines the x- and y-coordinates of a point. */
183: public static class POINT extends Structure {
184: public int x, y;
185: }
186:
187: /** Specifies the width and height of a rectangle. */
188: public static class SIZE extends Structure {
189: public int cx, cy;
190: }
191:
192: int AC_SRC_OVER = 0x00;
193: int AC_SRC_ALPHA = 0x01;
194: int AC_SRC_NO_PREMULT_ALPHA = 0x01;
195: int AC_SRC_NO_ALPHA = 0x02;
196:
197: public static class BLENDFUNCTION extends Structure {
198: public byte BlendOp = AC_SRC_OVER; // only valid value
199: public byte BlendFlags = 0; // only valid value
200: public byte SourceConstantAlpha;
201: public byte AlphaFormat;
202: }
203:
204: boolean UpdateLayeredWindow(HWND hwnd, HDC hdcDst, POINT pptDst,
205: SIZE psize, HDC hdcSrc, POINT pptSrc, int crKey,
206: BLENDFUNCTION pblend, int dwFlags);
207:
208: int SetWindowRgn(HWND hWnd, HRGN hRgn, boolean bRedraw);
209:
210: int VK_SHIFT = 16;
211: int VK_LSHIFT = 0xA0;
212: int VK_RSHIFT = 0xA1;
213: int VK_CONTROL = 17;
214: int VK_LCONTROL = 0xA2;
215: int VK_RCONTROL = 0xA3;
216: int VK_MENU = 18;
217: int VK_LMENU = 0xA4;
218: int VK_RMENU = 0xA5;
219:
220: boolean GetKeyboardState(byte[] state);
221:
222: short GetAsyncKeyState(int vKey);
223:
224: int WH_KEYBOARD = 2;
225: int WH_MOUSE = 7;
226: int WH_KEYBOARD_LL = 13;
227: int WH_MOUSE_LL = 14;
228:
229: public static class HHOOK extends HANDLE {
230: }
231:
232: public static interface HOOKPROC extends StdCallCallback {
233: }
234:
235: int WM_KEYDOWN = 256;
236: int WM_KEYUP = 257;
237: int WM_SYSKEYDOWN = 260;
238: int WM_SYSKEYUP = 261;
239:
240: public static class KBDLLHOOKSTRUCT extends Structure {
241: public int vkCode;
242: public int scanCode;
243: public int flags;
244: public int time;
245: public ULONG_PTR dwExtraInfo;
246: }
247:
248: public static interface LowLevelKeyboardProc extends HOOKPROC {
249: LRESULT callback(int nCode, WPARAM wParam,
250: KBDLLHOOKSTRUCT lParam);
251: }
252:
253: HHOOK SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod,
254: int dwThreadId);
255:
256: LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam,
257: LPARAM lParam);
258:
259: LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam,
260: Pointer lParam);
261:
262: boolean UnhookWindowsHookEx(HHOOK hhk);
263:
264: public static class MSG extends Structure {
265: public HWND hWnd;
266: public int message;
267: public WPARAM wParam;
268: public LPARAM lParam;
269: public int time;
270: public POINT pt;
271: }
272:
273: int GetMessage(MSG lpMsg, HWND hWnd, int wMsgFilterMin,
274: int wMsgFilterMax);
275:
276: boolean PeekMessage(MSG lpMsg, HWND hWnd, int wMsgFilterMin,
277: int wMsgFilterMax, int wRemoveMsg);
278:
279: boolean TranslateMessage(MSG lpMsg);
280:
281: LRESULT DispatchMessage(MSG lpMsg);
282:
283: void PostMessage(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam);
284:
285: void PostQuitMessage(int nExitCode);
286: }
|