module Graphics.Win32.Misc where
import Graphics.Win32.GDI.Types
import System.Win32.Types
import Data.Maybe
import Foreign
#include "windows_cconv.h"
type Accelerator = LPCTSTR
type Cursor = LPTSTR
type Icon = LPTSTR
loadAccelerators :: Maybe HINSTANCE -> Accelerator -> IO HACCEL
loadAccelerators mb_inst accel =
failIfNull "LoadAccelerators" $ c_LoadAccelerators (maybePtr mb_inst) accel
foreign import WINDOWS_CCONV unsafe "windows.h LoadAcceleratorsW"
c_LoadAccelerators :: HINSTANCE -> Accelerator -> IO HACCEL
loadCursor :: Maybe HINSTANCE -> Cursor -> IO HCURSOR
loadCursor mb_inst cursor =
failIfNull "LoadCursor" $ c_LoadCursor (maybePtr mb_inst) cursor
foreign import WINDOWS_CCONV unsafe "windows.h LoadCursorW"
c_LoadCursor :: HINSTANCE -> Cursor -> IO HCURSOR
loadIcon :: Maybe HINSTANCE -> Icon -> IO HICON
loadIcon mb_inst icon =
failIfNull "LoadIcon" $ c_LoadIcon (maybePtr mb_inst) icon
foreign import WINDOWS_CCONV unsafe "windows.h LoadIconW"
c_LoadIcon :: HINSTANCE -> Icon -> IO HICON
iDC_ARROW :: Cursor
iDC_ARROW = castUINTPtrToPtr 32512
iDC_IBEAM :: Cursor
iDC_IBEAM = castUINTPtrToPtr 32513
iDC_WAIT :: Cursor
iDC_WAIT = castUINTPtrToPtr 32514
iDC_CROSS :: Cursor
iDC_CROSS = castUINTPtrToPtr 32515
iDC_UPARROW :: Cursor
iDC_UPARROW = castUINTPtrToPtr 32516
iDC_SIZENWSE :: Cursor
iDC_SIZENWSE = castUINTPtrToPtr 32642
iDC_SIZENESW :: Cursor
iDC_SIZENESW = castUINTPtrToPtr 32643
iDC_SIZEWE :: Cursor
iDC_SIZEWE = castUINTPtrToPtr 32644
iDC_SIZENS :: Cursor
iDC_SIZENS = castUINTPtrToPtr 32645
iDI_APPLICATION :: Icon
iDI_APPLICATION = castUINTPtrToPtr 32512
iDI_HAND :: Icon
iDI_HAND = castUINTPtrToPtr 32513
iDI_QUESTION :: Icon
iDI_QUESTION = castUINTPtrToPtr 32514
iDI_EXCLAMATION :: Icon
iDI_EXCLAMATION = castUINTPtrToPtr 32515
iDI_ASTERISK :: Icon
iDI_ASTERISK = castUINTPtrToPtr 32516
type MBStyle = UINT
mB_OK :: MBStyle
mB_OK = 0
mB_OKCANCEL :: MBStyle
mB_OKCANCEL = 1
mB_ABORTRETRYIGNORE :: MBStyle
mB_ABORTRETRYIGNORE = 2
mB_YESNOCANCEL :: MBStyle
mB_YESNOCANCEL = 3
mB_YESNO :: MBStyle
mB_YESNO = 4
mB_RETRYCANCEL :: MBStyle
mB_RETRYCANCEL = 5
mB_ICONHAND :: MBStyle
mB_ICONHAND = 16
mB_ICONQUESTION :: MBStyle
mB_ICONQUESTION = 32
mB_ICONEXCLAMATION :: MBStyle
mB_ICONEXCLAMATION = 48
mB_ICONASTERISK :: MBStyle
mB_ICONASTERISK = 64
mB_ICONINFORMATION :: MBStyle
mB_ICONINFORMATION = 64
mB_ICONSTOP :: MBStyle
mB_ICONSTOP = 16
mB_DEFBUTTON1 :: MBStyle
mB_DEFBUTTON1 = 0
mB_DEFBUTTON2 :: MBStyle
mB_DEFBUTTON2 = 256
mB_DEFBUTTON3 :: MBStyle
mB_DEFBUTTON3 = 512
mB_APPLMODAL :: MBStyle
mB_APPLMODAL = 0
mB_SYSTEMMODAL :: MBStyle
mB_SYSTEMMODAL = 4096
mB_TASKMODAL :: MBStyle
mB_TASKMODAL = 8192
mB_SETFOREGROUND :: MBStyle
mB_SETFOREGROUND = 65536
type MBStatus = UINT
iDABORT :: MBStatus
iDABORT = 3
iDCANCEL :: MBStatus
iDCANCEL = 2
iDIGNORE :: MBStatus
iDIGNORE = 5
iDNO :: MBStatus
iDNO = 7
iDOK :: MBStatus
iDOK = 1
iDRETRY :: MBStatus
iDRETRY = 4
iDYES :: MBStatus
iDYES = 6
messageBox :: HWND -> String -> String -> MBStyle -> IO MBStatus
messageBox wnd text caption style =
withTString text $ \ c_text ->
withTString caption $ \ c_caption ->
failIfZero "MessageBox" $ c_MessageBox wnd c_text c_caption style
foreign import WINDOWS_CCONV unsafe "windows.h MessageBoxW"
c_MessageBox :: HWND -> LPCTSTR -> LPCTSTR -> MBStyle -> IO MBStatus
type StdHandleId = DWORD
sTD_INPUT_HANDLE :: StdHandleId
sTD_INPUT_HANDLE = 4294967286
sTD_OUTPUT_HANDLE :: StdHandleId
sTD_OUTPUT_HANDLE = 4294967285
sTD_ERROR_HANDLE :: StdHandleId
sTD_ERROR_HANDLE = 4294967284
getStdHandle :: StdHandleId -> IO HANDLE
getStdHandle hid =
failIf (== iNVALID_HANDLE_VALUE) "GetStdHandle" $ c_GetStdHandle hid
foreign import WINDOWS_CCONV unsafe "windows.h GetStdHandle"
c_GetStdHandle :: StdHandleId -> IO HANDLE
transformedEllipse :: HDC -> POINT -> POINT -> POINT -> IO ()
transformedEllipse dc (x0,y0) (x1,y1) (x2,y2) =
failIfFalse_ "transformedEllipse" $ c_transformedEllipse dc x0 y0 x1 y1 x2 y2
foreign import ccall unsafe "ellipse.h transformedEllipse"
c_transformedEllipse :: HDC -> LONG -> LONG -> LONG -> LONG -> LONG -> LONG -> IO Bool
getCursorPos :: IO POINT
getCursorPos =
allocaPOINT $ \ p_pt -> do
failIfFalse_ "GetCursorPos" $ c_GetCursorPos p_pt
peekPOINT p_pt
foreign import WINDOWS_CCONV unsafe "windows.h GetCursorPos"
c_GetCursorPos :: Ptr POINT -> IO Bool
setCursorPos :: POINT -> IO ()
setCursorPos (x,y) =
failIfFalse_ "setCursorPos" $ c_SetCursorPos x y
foreign import WINDOWS_CCONV unsafe "windows.h SetCursorPos"
c_SetCursorPos :: LONG -> LONG -> IO Bool
clipCursor :: RECT -> IO ()
clipCursor rect =
withRECT rect $ \ p_rect ->
failIfFalse_ "ClipCursor" $ c_ClipCursor p_rect
foreign import WINDOWS_CCONV unsafe "windows.h ClipCursor"
c_ClipCursor :: Ptr RECT -> IO Bool
getClipCursor :: IO RECT
getClipCursor =
allocaRECT $ \ p_rect -> do
failIfFalse_ "GetClipCursor" $ c_GetClipCursor p_rect
peekRECT p_rect
foreign import WINDOWS_CCONV unsafe "windows.h GetClipCursor"
c_GetClipCursor :: Ptr RECT -> IO Bool
type ExitOption = UINT
eWX_FORCE :: ExitOption
eWX_FORCE = 4
eWX_LOGOFF :: ExitOption
eWX_LOGOFF = 0
eWX_POWEROFF :: ExitOption
eWX_POWEROFF = 8
eWX_REBOOT :: ExitOption
eWX_REBOOT = 2
eWX_SHUTDOWN :: ExitOption
eWX_SHUTDOWN = 1
exitWindowsEx :: ExitOption -> IO ()
exitWindowsEx opt =
failIfFalse_ "ExitWindowsEx" $ c_ExitWindowsEx opt 0
foreign import WINDOWS_CCONV unsafe "windows.h ExitWindowsEx"
c_ExitWindowsEx :: ExitOption -> DWORD -> IO Bool
exitWindows :: IO ()
exitWindows = exitWindowsEx 0
type Beep = UINT
type MbBeep = Maybe Beep
maybeBeep :: Maybe Beep -> Beep
maybeBeep = fromMaybe 0xffffffff
type Duration = Int
type MbDuration = Maybe Duration
maybeDuration :: Maybe Duration -> Duration
maybeDuration = fromMaybe (1)
messageBeep :: Maybe Beep -> IO ()
messageBeep mb_beep =
c_MessageBeep (maybeBeep mb_beep)
foreign import WINDOWS_CCONV unsafe "windows.h MessageBeep"
c_MessageBeep :: Beep -> IO ()
beep :: WORD -> MbDuration -> IO ()
beep freq mb_dur =
failIfFalse_ "Beep" $ c_Beep freq (maybeDuration mb_dur)
foreign import WINDOWS_CCONV unsafe "windows.h Beep"
c_Beep :: WORD -> Duration -> IO Bool
type TimerId = UINT
type TIMERPROC = FunPtr (HWND -> UINT -> TimerId -> DWORD -> IO ())
setWinTimer :: HWND -> TimerId -> UINT -> IO TimerId
setWinTimer wnd timer elapse =
failIfZero "SetTimer" $ c_SetTimer wnd timer elapse nullFunPtr
foreign import WINDOWS_CCONV unsafe "windows.h SetTimer"
c_SetTimer :: HWND -> TimerId -> UINT -> TIMERPROC -> IO TimerId
killTimer :: Maybe HWND -> TimerId -> IO ()
killTimer mb_wnd timer =
failIfFalse_ "KillTimer" $ c_KillTimer (maybePtr mb_wnd) timer
foreign import WINDOWS_CCONV unsafe "windows.h KillTimer"
c_KillTimer :: HWND -> TimerId -> IO Bool
type MilliSeconds = DWORD
foreign import WINDOWS_CCONV unsafe "windows.h timeGetTime"
timeGetTime :: IO MilliSeconds