[Haskell-cafe] Problem with a Win32 API

Eric eeoam at ukfsn.org
Mon Dec 17 10:34:42 EST 2007

Dear all,

When I run the program below a window appears for a split second, then 
disappears and the program exits. Can you help me figure out what's 
going wrong?


import Graphics.Win32.Misc
import Graphics.Win32.GDI.Types
import Graphics.Win32.Window
import System.Win32.DLL
import Foreign.Marshal.Alloc

main = do hInst <- loadLibrary "ole32.dll"
                res <- registerClass (style, hInst, Nothing, Nothing, 
Nothing, Nothing, classname)
                if res == Nothing then do{putStrLn "Unable to register." 
                  else putStrLn "Registered."
                hwnd <- createWindow classname "Kleer 0" wS_VISIBLE 
Nothing Nothing Nothing Nothing Nothing Nothing hInst handler
                b <- showWindow hwnd sW_SHOWNORMAL
                if b then putStrLn "Window showing" else do{putStrLn 
"Unable to show window."; return()}
                updateWindow hwnd
                ptr <- mallocBytes 4
                getMessage ptr Nothing
                loop ptr

loop msg =  do translateMessage msg
                       dispatchMessage msg
                       loop msg

handler :: WindowClosure
handler hwnd msg w l = case msg of
                                       wM_CLOSE -> do{destroyWindow 
hwnd; return 0}
                                       _ -> defWindowProc (Just hwnd) 
msg w l
style :: ClassStyle
style = 0

classname = mkClassName "KleerWnd"



More information about the Haskell-Cafe mailing list