packages feed

Win32-extras-0.1.0.0: Graphics/Win32/SafeImport.hs

{-# LANGUAGE CPP #-}
{- |
   Module      :  Graphics.Win32.SafeImport
   Copyright   :  2012 shelarcy
   License     :  BSD-style

   Maintainer  :  shelarcy@gmail.com
   Stability   :  Provisional
   Portability :  Non-portable (Win32 API)

   Import Win32 API safety way.
-}

module Graphics.Win32.SafeImport
  ( messageBox
  , c_MessageBox
  ) where
import Graphics.Win32.Misc      ( MBStyle, MBStatus )
import Graphics.Win32.GDI.Types ( HWND )
import System.Win32.Types       ( LPCTSTR, withTString )
import System.Win32.Error       ( failIfZero )

----------------------------------------------------------------
-- Safe version of MessageBox Function
----------------------------------------------------------------

-- | When you want to make MessageBox, use this version instead of
-- "Graphics.Win32.Misc"'s one. See: <https://github.com/haskell/win32/pull/5>
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 safe "windows.h MessageBoxW"
  c_MessageBox :: HWND -> LPCTSTR -> LPCTSTR -> MBStyle -> IO MBStatus