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 ******************************************************************/
37 CopyBitmap(HBITMAP bmp
);
39 /* INTERNAL ******************************************************************/
41 /* This callback routine is called directly after switching to gui mode */
43 User32SetupDefaultCursors(PVOID Arguments
, ULONG ArgumentLength
)
45 BOOL
*DefaultCursor
= (BOOL
*)Arguments
;
46 LRESULT Result
= TRUE
;
50 /* set default cursor */
51 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
55 /* FIXME load system cursor scheme */
57 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
60 return(ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
));
63 /* FUNCTIONS *****************************************************************/
70 CopyCursor(HCURSOR pcur
)
74 if(NtUserGetCursorIconInfo((HANDLE
)pcur
, &IconInfo
))
76 return (HCURSOR
)NtUserCreateCursorIconHandle(&IconInfo
, FALSE
);
85 CreateCursor(HINSTANCE hInst
,
90 CONST VOID
*pvANDPlane
,
91 CONST VOID
*pvXORPlane
)
94 BYTE BitmapInfoBuffer
[sizeof(BITMAPINFOHEADER
) + 2 * sizeof(RGBQUAD
)];
95 BITMAPINFO
*bwBIH
= (BITMAPINFO
*)BitmapInfoBuffer
;
98 hScreenDc
= CreateCompatibleDC(NULL
);
99 if (hScreenDc
== NULL
)
102 bwBIH
->bmiHeader
.biBitCount
= 1;
103 bwBIH
->bmiHeader
.biWidth
= nWidth
;
104 bwBIH
->bmiHeader
.biHeight
= -nHeight
* 2;
105 bwBIH
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
106 bwBIH
->bmiHeader
.biPlanes
= 1;
107 bwBIH
->bmiHeader
.biSizeImage
= 0;
108 bwBIH
->bmiHeader
.biCompression
= BI_RGB
;
109 bwBIH
->bmiHeader
.biClrImportant
= 0;
110 bwBIH
->bmiHeader
.biClrUsed
= 0;
111 bwBIH
->bmiHeader
.biXPelsPerMeter
= 0;
112 bwBIH
->bmiHeader
.biYPelsPerMeter
= 0;
114 bwBIH
->bmiColors
[0].rgbBlue
= 0;
115 bwBIH
->bmiColors
[0].rgbGreen
= 0;
116 bwBIH
->bmiColors
[0].rgbRed
= 0;
117 bwBIH
->bmiColors
[0].rgbReserved
= 0;
119 bwBIH
->bmiColors
[1].rgbBlue
= 0xff;
120 bwBIH
->bmiColors
[1].rgbGreen
= 0xff;
121 bwBIH
->bmiColors
[1].rgbRed
= 0xff;
122 bwBIH
->bmiColors
[1].rgbReserved
= 0;
124 IconInfo
.hbmMask
= CreateDIBitmap(hScreenDc
, &bwBIH
->bmiHeader
, 0,
125 NULL
, bwBIH
, DIB_RGB_COLORS
);
126 if (IconInfo
.hbmMask
)
128 SetDIBits(hScreenDc
, IconInfo
.hbmMask
, 0, nHeight
,
129 pvXORPlane
, bwBIH
, DIB_RGB_COLORS
);
130 SetDIBits(hScreenDc
, IconInfo
.hbmMask
, nHeight
, nHeight
,
131 pvANDPlane
, bwBIH
, DIB_RGB_COLORS
);
140 IconInfo
.fIcon
= FALSE
;
141 IconInfo
.xHotspot
= xHotSpot
;
142 IconInfo
.yHotspot
= yHotSpot
;
143 IconInfo
.hbmColor
= 0;
145 return (HCURSOR
)NtUserCreateCursorIconHandle(&IconInfo
, FALSE
);
153 DestroyCursor(HCURSOR hCursor
)
155 return (BOOL
)NtUserDestroyCursorIcon((HANDLE
)hCursor
, 0);
163 GetClipCursor(LPRECT lpRect
)
165 return NtUserGetClipCursor(lpRect
);
176 ci
.cbSize
= sizeof(CURSORINFO
);
177 if(NtUserGetCursorInfo(&ci
))
188 GetCursorInfo(PCURSORINFO pci
)
190 return (BOOL
)NtUserGetCursorInfo(pci
);
198 GetCursorPos(LPPOINT lpPoint
)
201 /* Windows doesn't check if lpPoint == NULL, we do */
204 SetLastError(ERROR_INVALID_PARAMETER
);
208 res
= NtUserGetCursorPos(lpPoint
);
218 LoadCursorA(HINSTANCE hInstance
,
221 return(LoadImageA(hInstance
, lpCursorName
, IMAGE_CURSOR
, 0, 0,
222 LR_SHARED
| LR_DEFAULTSIZE
));
230 LoadCursorFromFileA(LPCSTR lpFileName
)
232 UNICODE_STRING FileName
;
234 RtlCreateUnicodeStringFromAsciiz(&FileName
, (LPSTR
)lpFileName
);
235 Result
= LoadImageW(0, FileName
.Buffer
, IMAGE_CURSOR
, 0, 0,
236 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
237 RtlFreeUnicodeString(&FileName
);
246 LoadCursorFromFileW(LPCWSTR lpFileName
)
248 return(LoadImageW(0, lpFileName
, IMAGE_CURSOR
, 0, 0,
249 LR_LOADFROMFILE
| LR_DEFAULTSIZE
));
257 LoadCursorW(HINSTANCE hInstance
,
258 LPCWSTR lpCursorName
)
260 return(LoadImageW(hInstance
, lpCursorName
, IMAGE_CURSOR
, 0, 0,
261 LR_SHARED
| LR_DEFAULTSIZE
));
273 return NtUserClipCursor((RECT
*)lpRect
);
281 SetCursor(HCURSOR hCursor
)
283 return NtUserSetCursor(hCursor
);
296 Input
.type
= INPUT_MOUSE
;
297 Input
.mi
.dx
= (LONG
)X
;
298 Input
.mi
.dy
= (LONG
)Y
;
299 Input
.mi
.mouseData
= 0;
300 Input
.mi
.dwFlags
= MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
;
302 Input
.mi
.dwExtraInfo
= 0;
304 NtUserSendInput(1, &Input
, sizeof(INPUT
));
313 SetSystemCursor(HCURSOR hcur
,
325 ShowCursor(BOOL bShow
)
332 CursorIconToCursor(HICON hIcon
, BOOL SemiTransparent
)