3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/cursor.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
38 CopyBitmap(HBITMAP bmp
);
40 /* INTERNAL ******************************************************************/
42 /* This callback routine is called directly after switching to gui mode */
44 User32SetupDefaultCursors(PVOID Arguments
, ULONG ArgumentLength
)
46 BOOL
*DefaultCursor
= (BOOL
*)Arguments
;
47 LRESULT Result
= TRUE
;
51 /* set default cursor */
52 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
56 /* FIXME load system cursor scheme */
58 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
61 return(ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
));
64 /* FUNCTIONS *****************************************************************/
71 CopyCursor(HCURSOR pcur
)
75 if(NtUserGetCursorIconInfo((HANDLE
)pcur
, &IconInfo
))
77 return (HCURSOR
)NtUserCreateCursorIconHandle(&IconInfo
, FALSE
);
86 CreateCursor(HINSTANCE hInst
,
91 CONST VOID
*pvANDPlane
,
92 CONST VOID
*pvXORPlane
)
95 BYTE BitmapInfoBuffer
[sizeof(BITMAPINFOHEADER
) + 2 * sizeof(RGBQUAD
)];
96 BITMAPINFO
*bwBIH
= (BITMAPINFO
*)BitmapInfoBuffer
;
99 hScreenDc
= CreateCompatibleDC(NULL
);
100 if (hScreenDc
== NULL
)
103 bwBIH
->bmiHeader
.biBitCount
= 1;
104 bwBIH
->bmiHeader
.biWidth
= nWidth
;
105 bwBIH
->bmiHeader
.biHeight
= -nHeight
* 2;
106 bwBIH
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
107 bwBIH
->bmiHeader
.biPlanes
= 1;
108 bwBIH
->bmiHeader
.biSizeImage
= 0;
109 bwBIH
->bmiHeader
.biCompression
= BI_RGB
;
110 bwBIH
->bmiHeader
.biClrImportant
= 0;
111 bwBIH
->bmiHeader
.biClrUsed
= 0;
112 bwBIH
->bmiHeader
.biXPelsPerMeter
= 0;
113 bwBIH
->bmiHeader
.biYPelsPerMeter
= 0;
115 bwBIH
->bmiColors
[0].rgbBlue
= 0;
116 bwBIH
->bmiColors
[0].rgbGreen
= 0;
117 bwBIH
->bmiColors
[0].rgbRed
= 0;
118 bwBIH
->bmiColors
[0].rgbReserved
= 0;
120 bwBIH
->bmiColors
[1].rgbBlue
= 0xff;
121 bwBIH
->bmiColors
[1].rgbGreen
= 0xff;
122 bwBIH
->bmiColors
[1].rgbRed
= 0xff;
123 bwBIH
->bmiColors
[1].rgbReserved
= 0;
125 IconInfo
.hbmMask
= CreateDIBitmap(hScreenDc
, &bwBIH
->bmiHeader
, 0,
126 NULL
, bwBIH
, DIB_RGB_COLORS
);
127 if (IconInfo
.hbmMask
)
129 SetDIBits(hScreenDc
, IconInfo
.hbmMask
, 0, nHeight
,
130 pvXORPlane
, bwBIH
, DIB_RGB_COLORS
);
131 SetDIBits(hScreenDc
, IconInfo
.hbmMask
, nHeight
, nHeight
,
132 pvANDPlane
, bwBIH
, DIB_RGB_COLORS
);
141 IconInfo
.fIcon
= FALSE
;
142 IconInfo
.xHotspot
= xHotSpot
;
143 IconInfo
.yHotspot
= yHotSpot
;
144 IconInfo
.hbmColor
= 0;
146 return (HCURSOR
)NtUserCreateCursorIconHandle(&IconInfo
, FALSE
);
154 DestroyCursor(HCURSOR hCursor
)
156 return (BOOL
)NtUserDestroyCursorIcon((HANDLE
)hCursor
, 0);
164 GetClipCursor(LPRECT lpRect
)
166 return NtUserGetClipCursor(lpRect
);
177 ci
.cbSize
= sizeof(CURSORINFO
);
178 if(NtUserGetCursorInfo(&ci
))
189 GetCursorInfo(PCURSORINFO pci
)
191 return (BOOL
)NtUserGetCursorInfo(pci
);
199 GetCursorPos(LPPOINT lpPoint
)
202 /* Windows doesn't check if lpPoint == NULL, we do */
205 SetLastError(ERROR_INVALID_PARAMETER
);
209 res
= NtUserGetCursorPos(lpPoint
);
219 LoadCursorA(HINSTANCE hInstance
,
222 return(LoadImageA(hInstance
, lpCursorName
, IMAGE_CURSOR
, 0, 0,
223 LR_SHARED
| LR_DEFAULTSIZE
));
231 LoadCursorFromFileA(LPCSTR lpFileName
)
233 UNICODE_STRING FileName
;
235 RtlCreateUnicodeStringFromAsciiz(&FileName
, (LPSTR
)lpFileName
);
236 Result
= LoadImageW(0, FileName
.Buffer
, IMAGE_CURSOR
, 0, 0,
237 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
238 RtlFreeUnicodeString(&FileName
);
247 LoadCursorFromFileW(LPCWSTR lpFileName
)
249 return(LoadImageW(0, lpFileName
, IMAGE_CURSOR
, 0, 0,
250 LR_LOADFROMFILE
| LR_DEFAULTSIZE
));
258 LoadCursorW(HINSTANCE hInstance
,
259 LPCWSTR lpCursorName
)
261 return(LoadImageW(hInstance
, lpCursorName
, IMAGE_CURSOR
, 0, 0,
262 LR_SHARED
| LR_DEFAULTSIZE
));
274 return NtUserClipCursor((RECT
*)lpRect
);
282 SetCursor(HCURSOR hCursor
)
284 return NtUserSetCursor(hCursor
);
297 Input
.type
= INPUT_MOUSE
;
298 Input
.mi
.dx
= (LONG
)X
;
299 Input
.mi
.dy
= (LONG
)Y
;
300 Input
.mi
.mouseData
= 0;
301 Input
.mi
.dwFlags
= MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
;
303 Input
.mi
.dwExtraInfo
= 0;
305 NtUserSendInput(1, &Input
, sizeof(INPUT
));
314 SetSystemCursor(HCURSOR hcur
,
326 ShowCursor(BOOL bShow
)
333 CursorIconToCursor(HICON hIcon
, BOOL SemiTransparent
)