63 newAccel[1] = 0;
64 newAccel[2] = 0;
65 newSpeed = 10;
66
67 // Save the Current Mouse Acceleration Constants
68 bResult = SystemParametersInfo(SPI_GETMOUSE,0,oldAccel,0);
69 bResult = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &oldSpeed,0);
70 // Set the new Mouse Acceleration Constants (Disabled).
71 bResult = SystemParametersInfo(SPI_SETMOUSE,0,newAccel,SPIF_SENDCHANGE);
72 bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0,
73 // 4504963: Though the third argument to SystemParameterInfo is
74 // declared as a PVOID, as of Windows 2000 it is apparently
75 // interpreted as an int. (The MSDN docs for SPI_SETMOUSESPEED
76 // say that it's an integer between 1 and 20, the default being
77 // 10). Instead of passing the @ of the desired value, the
78 // value itself is now passed, cast as a PVOID so as to
79 // compile. -bchristi 10/02/2001
80 (PVOID)newSpeed,
81 SPIF_SENDCHANGE);
82
83 POINT curPos;
84 ::GetCursorPos(&curPos);
85 x -= curPos.x;
86 y -= curPos.y;
87
88 mouse_event(MOUSEEVENTF_MOVE,x,y,0,0);
89 // Move the cursor to the desired coordinates.
90
91 // Restore the old Mouse Acceleration Constants.
92 bResult = SystemParametersInfo(SPI_SETMOUSE,0, oldAccel, SPIF_SENDCHANGE);
93 bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)oldSpeed,
94 SPIF_SENDCHANGE);
95 }
96
97 void AwtRobot::MousePress( jint buttonMask )
98 {
99 DWORD dwFlags = 0L;
100 // According to MSDN: Software Driving Software
101 // application should consider SM_SWAPBUTTON to correctly emulate user with
102 // left handed mouse setup
200 HDC hdcScreen = ::CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
201 HDC hdcMem = ::CreateCompatibleDC(hdcScreen);
202 HBITMAP hbitmap;
203 HBITMAP hOldBitmap;
204 HPALETTE hOldPalette = NULL;
205 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
206
207 // create an offscreen bitmap
208 hbitmap = ::CreateCompatibleBitmap(hdcScreen, width, height);
209 if (hbitmap == NULL) {
210 throw std::bad_alloc();
211 }
212 hOldBitmap = (HBITMAP)::SelectObject(hdcMem, hbitmap);
213
214 // REMIND: not multimon-friendly...
215 int primaryIndex = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
216 hOldPalette =
217 AwtWin32GraphicsDevice::SelectPalette(hdcMem, primaryIndex);
218 AwtWin32GraphicsDevice::RealizePalette(hdcMem, primaryIndex);
219
220 // copy screen image to offscreen bitmap
221 // CAPTUREBLT flag is required to capture WS_EX_LAYERED windows' contents
222 // correctly on Win2K/XP
223 VERIFY(::BitBlt(hdcMem, 0, 0, width, height, hdcScreen, x, y,
224 SRCCOPY|CAPTUREBLT) != 0);
225
226 static const int BITS_PER_PIXEL = 32;
227 static const int BYTES_PER_PIXEL = BITS_PER_PIXEL/8;
228
229 if (!IS_SAFE_SIZE_MUL(width, height)) throw std::bad_alloc();
230 int numPixels = width*height;
231 if (!IS_SAFE_SIZE_MUL(BYTES_PER_PIXEL, numPixels)) throw std::bad_alloc();
232 int pixelDataSize = BYTES_PER_PIXEL*numPixels;
233 DASSERT(pixelDataSize > 0 && pixelDataSize % 4 == 0);
234 // allocate memory for BITMAPINFO + pixel data
235 // 4620932: When using BI_BITFIELDS, GetDIBits expects an array of 3
236 // RGBQUADS to follow the BITMAPINFOHEADER, but we were only allocating the
237 // 1 that is included in BITMAPINFO. Thus, GetDIBits was writing off the
238 // end of our block of memory. Now we allocate sufficient memory.
239 // See MSDN docs for BITMAPINFOHEADER -bchristi
240
241 if (!IS_SAFE_SIZE_ADD(sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD), pixelDataSize)) {
242 throw std::bad_alloc();
243 }
244 BITMAPINFO * pinfo = (BITMAPINFO *)(new BYTE[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD) + pixelDataSize]);
|
63 newAccel[1] = 0;
64 newAccel[2] = 0;
65 newSpeed = 10;
66
67 // Save the Current Mouse Acceleration Constants
68 bResult = SystemParametersInfo(SPI_GETMOUSE,0,oldAccel,0);
69 bResult = SystemParametersInfo(SPI_GETMOUSESPEED, 0, &oldSpeed,0);
70 // Set the new Mouse Acceleration Constants (Disabled).
71 bResult = SystemParametersInfo(SPI_SETMOUSE,0,newAccel,SPIF_SENDCHANGE);
72 bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0,
73 // 4504963: Though the third argument to SystemParameterInfo is
74 // declared as a PVOID, as of Windows 2000 it is apparently
75 // interpreted as an int. (The MSDN docs for SPI_SETMOUSESPEED
76 // say that it's an integer between 1 and 20, the default being
77 // 10). Instead of passing the @ of the desired value, the
78 // value itself is now passed, cast as a PVOID so as to
79 // compile. -bchristi 10/02/2001
80 (PVOID)newSpeed,
81 SPIF_SENDCHANGE);
82
83 int primaryIndex = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
84 Devices::InstanceAccess devices;
85 AwtWin32GraphicsDevice *device = devices->GetDevice(primaryIndex);
86
87 x = (device == NULL) ? x : device->ScaleUpX(x);
88 y = (device == NULL) ? y : device->ScaleUpY(y);
89
90 POINT curPos;
91 ::GetCursorPos(&curPos);
92 x -= curPos.x;
93 y -= curPos.y;
94
95 mouse_event(MOUSEEVENTF_MOVE,x,y,0,0);
96 // Move the cursor to the desired coordinates.
97
98 // Restore the old Mouse Acceleration Constants.
99 bResult = SystemParametersInfo(SPI_SETMOUSE,0, oldAccel, SPIF_SENDCHANGE);
100 bResult = SystemParametersInfo(SPI_SETMOUSESPEED, 0, (PVOID)oldSpeed,
101 SPIF_SENDCHANGE);
102 }
103
104 void AwtRobot::MousePress( jint buttonMask )
105 {
106 DWORD dwFlags = 0L;
107 // According to MSDN: Software Driving Software
108 // application should consider SM_SWAPBUTTON to correctly emulate user with
109 // left handed mouse setup
207 HDC hdcScreen = ::CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
208 HDC hdcMem = ::CreateCompatibleDC(hdcScreen);
209 HBITMAP hbitmap;
210 HBITMAP hOldBitmap;
211 HPALETTE hOldPalette = NULL;
212 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
213
214 // create an offscreen bitmap
215 hbitmap = ::CreateCompatibleBitmap(hdcScreen, width, height);
216 if (hbitmap == NULL) {
217 throw std::bad_alloc();
218 }
219 hOldBitmap = (HBITMAP)::SelectObject(hdcMem, hbitmap);
220
221 // REMIND: not multimon-friendly...
222 int primaryIndex = AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
223 hOldPalette =
224 AwtWin32GraphicsDevice::SelectPalette(hdcMem, primaryIndex);
225 AwtWin32GraphicsDevice::RealizePalette(hdcMem, primaryIndex);
226
227 Devices::InstanceAccess devices;
228 AwtWin32GraphicsDevice *device = devices->GetDevice(primaryIndex);
229 int sWidth = (device == NULL) ? width : device->ScaleUpX(width);
230 int sHeight = (device == NULL) ? height : device->ScaleUpY(height);
231
232 // copy screen image to offscreen bitmap
233 // CAPTUREBLT flag is required to capture WS_EX_LAYERED windows' contents
234 // correctly on Win2K/XP
235 if (width == sWidth && height == sHeight) {
236 VERIFY(::BitBlt(hdcMem, 0, 0, width, height, hdcScreen, x, y,
237 SRCCOPY | CAPTUREBLT) != 0);
238 } else {
239 int sX = (device == NULL) ? x : device->ScaleUpX(x);
240 int sY = (device == NULL) ? y : device->ScaleUpY(y);
241 VERIFY(::StretchBlt(hdcMem, 0, 0, width, height,
242 hdcScreen, sX, sY, sWidth, sHeight,
243 SRCCOPY | CAPTUREBLT) != 0);
244 }
245
246 static const int BITS_PER_PIXEL = 32;
247 static const int BYTES_PER_PIXEL = BITS_PER_PIXEL/8;
248
249 if (!IS_SAFE_SIZE_MUL(width, height)) throw std::bad_alloc();
250 int numPixels = width*height;
251 if (!IS_SAFE_SIZE_MUL(BYTES_PER_PIXEL, numPixels)) throw std::bad_alloc();
252 int pixelDataSize = BYTES_PER_PIXEL*numPixels;
253 DASSERT(pixelDataSize > 0 && pixelDataSize % 4 == 0);
254 // allocate memory for BITMAPINFO + pixel data
255 // 4620932: When using BI_BITFIELDS, GetDIBits expects an array of 3
256 // RGBQUADS to follow the BITMAPINFOHEADER, but we were only allocating the
257 // 1 that is included in BITMAPINFO. Thus, GetDIBits was writing off the
258 // end of our block of memory. Now we allocate sufficient memory.
259 // See MSDN docs for BITMAPINFOHEADER -bchristi
260
261 if (!IS_SAFE_SIZE_ADD(sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD), pixelDataSize)) {
262 throw std::bad_alloc();
263 }
264 BITMAPINFO * pinfo = (BITMAPINFO *)(new BYTE[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD) + pixelDataSize]);
|