Source

haskell-win32 / System / Win32 / Window.gc

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
module System.Win32.Window where

import Foreign.GreenCard
import System.Win32.Types
import System.Win32.GDITypes
import System.Win32.WinMessage

%#include <windows.h>
%#include "errors.h"
%#include "win32debug.h"
%#include "finalizers.h"

----------------------------------------------------------------
-- Window Class
----------------------------------------------------------------

-- The classname must not be deallocated until the corresponding class
-- is deallocated.  For this reason, we represent classnames by pointers
-- and explicitly allocate the className.

%dis className x = lPCTSTR x
type ClassName   = LPCTSTR

-- Note: this is one of those rare functions which doesnt free all 
-- its String arguments.
%fun mkClassName :: String -> ClassName
%code
%result (className {arg1})

%dis classStyle x = uINT x
type ClassStyle   = UINT

%const ClassStyle 
% [ CS_VREDRAW
% , CS_HREDRAW
% , CS_OWNDC
% , CS_CLASSDC
% , CS_PARENTDC
% , CS_SAVEBITS
% , CS_DBLCLKS
% , CS_BYTEALIGNCLIENT
% , CS_BYTEALIGNWINDOW
% , CS_NOCLOSE
% , CS_GLOBALCLASS
% ]

%dis wNDCLASS x = wndClass_ (addr ({WNDCLASS *} x))

type WNDCLASS =
 (ClassStyle,  -- style
  HINSTANCE,   -- hInstance
  MbHICON,     -- hIcon
  MbHCURSOR,   -- hCursor
  MbHBRUSH,    -- hbrBackground
  MbLPCSTR,    -- lpszMenuName
  ClassName)   -- lpszClassName

--ToDo!
--To avoid confusion with NULL, WNDCLASS requires you to add 1 to a SystemColor
--(which can be NULL)
-- %fun mkMbHBRUSH :: SystemColor -> MbHBRUSH
-- %code
-- %result ((HBRUSH)($0+1));

%fun marshall_wndClass_ :: WNDCLASS -> IO (Addr)
%call	( classStyle 	style
%     	, hINSTANCE  	hInstance
%     	, mbHICON    	hIcon
%     	, mbHCURSOR    	hCursor
%     	, mbHBRUSH	hbrBackground
%	, mbLPCTSTR	lpszMenuName
%	, className	lpszClassName
%	)
%code c = (WNDCLASS*) malloc(sizeof(WNDCLASS));
%     if (c) { 
%	  c->style 	   = style;
%	  c->hInstance 	   = hInstance;
%	  c->hIcon 	   = hIcon;
%	  c->hCursor 	   = hCursor;
%	  c->hbrBackground = hbrBackground;
%	  c->lpszMenuName  = lpszMenuName;
%	  c->lpszClassName = lpszClassName;
%     }
%fail {c==0} { MallocError("marshall_WNDCLASS") }
%result (addr ({WNDCLASS*} c))

%#include "WndProc.h"

%fun registerClass :: WNDCLASS -> IO MbATOM
%code arg1->lpfnWndProc = genericWndProc;
%     arg1->cbClsExtra = 0;
%     arg1->cbWndExtra =0;
%     res1 = RegisterClass(arg1);

%fun UnregisterClass :: ClassName -> HINSTANCE -> IO ()

----------------------------------------------------------------
-- Window Style
----------------------------------------------------------------

%dis windowStyle x = dWORD x
type WindowStyle   = DWORD

%const WindowStyle 
% [ WS_OVERLAPPED
% , WS_POPUP
% , WS_CHILD
% , WS_CLIPSIBLINGS
% , WS_CLIPCHILDREN
% , WS_VISIBLE
% , WS_DISABLED
% , WS_MINIMIZE
% , WS_MAXIMIZE
% , WS_CAPTION
% , WS_BORDER
% , WS_DLGFRAME
% , WS_VSCROLL
% , WS_HSCROLL
% , WS_SYSMENU
% , WS_THICKFRAME
% , WS_MINIMIZEBOX
% , WS_MAXIMIZEBOX
% , WS_GROUP
% , WS_TABSTOP
% , WS_OVERLAPPEDWINDOW
% , WS_POPUPWINDOW
% , WS_CHILDWINDOW
% , WS_TILED
% , WS_ICONIC
% , WS_SIZEBOX
% , WS_TILEDWINDOW
% ]

%dis windowStyleEx x = dWORD x
type WindowStyleEx   = DWORD

%const WindowStyleEx
% [ WS_EX_DLGMODALFRAME
% , WS_EX_NOPARENTNOTIFY
% , WS_EX_TOPMOST
% , WS_EX_ACCEPTFILES
% , WS_EX_TRANSPARENT
% , WS_EX_MDICHILD
% , WS_EX_TOOLWINDOW
% , WS_EX_WINDOWEDGE
% , WS_EX_CLIENTEDGE
% , WS_EX_CONTEXTHELP
% , WS_EX_RIGHT
% , WS_EX_LEFT
% , WS_EX_RTLREADING
% , WS_EX_LTRREADING
% , WS_EX_LEFTSCROLLBAR
% , WS_EX_RIGHTSCROLLBAR
% , WS_EX_CONTROLPARENT
% , WS_EX_STATICEDGE
% , WS_EX_APPWINDOW
% , WS_EX_OVERLAPPEDWINDOW
% , WS_EX_PALETTEWINDOW
% ]

%const Pos [ CW_USEDEFAULT ]

%dis pos x = int x
type Pos = Int

%dis mbPos x = maybeT {cW_USEDEFAULT} (pos x)
type MbPos = Maybe Pos

type WindowClosure = HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT

%dis windowClosure x = windowClosure_ (addr x)
 
marshall_windowClosure_ :: WindowClosure -> IO (Addr)
marshall_windowClosure_ cl = fmap castFunPtrToPtr (mkWindowClosure cl)

foreign import ccall "wrapper" mkWindowClosure :: WindowClosure -> IO (FunPtr WindowClosure)


%fun SetWindowClosure :: HWND -> WindowClosure -> IO ()
%call (hWND hwnd) (windowClosure closure)
%code SetWindowLong(hwnd, GWL_USERDATA, (LONG)closure);

%fun createWindow 
%  :: ClassName -> String -> WindowStyle -> 
%     Maybe Pos -> Maybe Pos -> Maybe Pos -> Maybe Pos -> 
%     MbHWND -> MbHMENU -> HINSTANCE -> WindowClosure -> 
%     IO HWND
%call (className name) (string windowName)  (windowStyle style)  
%     (mbPos x) (mbPos y) (mbPos width) (mbPos height) 
%     (mbHWND hwndParent) (mbHMENU hmenu) (hINSTANCE hinst) 
%     (windowClosure closure)
%code res1 = CreateWindow(name, windowName,style,x,y,width,height,hwndParent,hmenu,hinst,NULL);
%     if (res1 != NULL) { SetWindowLong(res1, GWL_USERDATA, (LONG)closure); }
%fail {res1 == NULL} {ErrorWin("CreateWindow")}

-- Freeing the title/window name has been reported
-- to cause a crash, so let's not do it.
-- %end free(windowName)  /* I think this is safe... */

%fun createWindowEx 
%  :: WindowStyle -> ClassName -> String -> WindowStyle 
%  -> Maybe Pos -> Maybe Pos -> Maybe Pos -> Maybe Pos 
%  -> MbHWND -> MbHMENU -> HINSTANCE -> WindowClosure
%  -> IO HWND
%call (windowStyle estyle)  (className cls) (string wname) 
%     (windowStyle wstyle) 
%     (mbPos x) (mbPos y) (mbPos nWidth) (mbPos nHeight) 
%     (mbHWND hwndParent) (mbHMENU hmenu) (hINSTANCE hinstance)
%     (windowClosure closure)
%code res1 = CreateWindowEx(estyle, cls, wname, wstyle,x,y,nWidth,nHeight,hwndParent,hmenu,hinstance,NULL);
%     if (res1 != NULL) { SetWindowLong(res1, GWL_USERDATA, (LONG)closure); }
%fail {res1 == NULL} {ErrorWin("CreateWindowEx")}

-- see CreateWindow comment.
-- %end free(wname)  /* I think this is safe... */

----------------------------------------------------------------

%fun DefWindowProc :: MbHWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
%safecode LRESULT res1 = DefWindowProc(arg1,arg2,arg3,arg4);

----------------------------------------------------------------

%fun GetClientRect  :: HWND -> IO RECT
%code BOOL success = GetClientRect(arg1,&res1)
%fail {!success} { ErrorString("GetClientRect") }
%result (declare {RECT} res1 in (rect {res1}))

%fun GetWindowRect  :: HWND -> IO RECT
%code BOOL success = GetWindowRect(arg1,&res1)
%fail {!success} { ErrorString("GetWindowRect") }
%result (declare {RECT} res1 in (rect {res1}))

-- Should it be MbRECT instead?
%fun InvalidateRect :: MbHWND -> MbLPRECT -> Bool -> IO ()
%safecode BOOL success = InvalidateRect(arg1,arg2,arg3)
%fail {!success} { ErrorString("InvalidateRect") }

%fun screenToClient :: HWND -> POINT -> IO POINT
%call (hWND arg1) (declare {POINT} scr in (point {scr}))
%code BOOL success = ScreenToClient(arg1, &scr);
%fail { !success } { ErrorString("ScreenToClient") }
%result (point {scr})

%fun clientToScreen :: HWND -> POINT -> IO POINT
%call (hWND hwnd) (declare {POINT} cli in (point {cli}))
%code BOOL success = ClientToScreen(hwnd,&cli);
%fail { !success } { ErrorString("ClientToScreen") }
%result (point {cli})

----------------------------------------------------------------
-- Setting window text/label
----------------------------------------------------------------
-- For setting the title bar text.  But inconvenient to make the LPCTSTR
%fun SetWindowText :: HWND -> String -> IO ()
%safecode BOOL success = SetWindowText(arg1,arg2)
%fail {!success} {ErrorString("SetWindowText")}
%end free(arg2)

----------------------------------------------------------------
-- Paint struct
----------------------------------------------------------------

type PAINTSTRUCT =
 ( HDC   -- hdc
 , Bool  -- fErase
 , RECT  -- rcPaint
 )

%dis lPPAINTSTRUCT x = addr ({LPPAINTSTRUCT} x)
type LPPAINTSTRUCT   = Addr

%fun sizeofPAINTSTRUCT :: DWORD
%code
%result (dWORD { sizeof(PAINTSTRUCT) })

%fun BeginPaint :: HWND -> LPPAINTSTRUCT -> IO HDC
%safecode HDC res1 = BeginPaint(arg1,arg2);
%fail {res1==NULL} {ErrorString("BeginPaint")}

%fun EndPaint   :: HWND -> LPPAINTSTRUCT -> IO ()
%safecode EndPaint((HWND)arg1,(LPPAINTSTRUCT)arg2);
-- Apparently always succeeds (return non-zero)

----------------------------------------------------------------
-- ShowWindow
----------------------------------------------------------------

%dis showWindowControl x = dWORD x
type ShowWindowControl   = DWORD

%const ShowWindowControl 
% [ SW_HIDE
% , SW_SHOWNORMAL
% , SW_SHOWMINIMIZED
% , SW_SHOWMAXIMIZED
% , SW_MAXIMIZE
% , SW_SHOWNOACTIVATE
% , SW_SHOW
% , SW_MINIMIZE
% , SW_SHOWMINNOACTIVE
% , SW_SHOWNA
% , SW_RESTORE
% ]

%fun ShowWindow :: HWND  -> ShowWindowControl  -> IO Bool
%safecode BOOL res1 = ShowWindow(arg1,arg2);

----------------------------------------------------------------
-- Misc
----------------------------------------------------------------

%fun AdjustWindowRect :: RECT -> WindowStyle -> Bool -> IO RECT
%call (declare {RECT} arg1 in (rect {arg1})) (windowStyle arg2) (bool arg3)
%code BOOL success = AdjustWindowRect(&arg1, arg2, arg3)
%fail { !success } { ErrorString("AdjustWindowRect") }
%result (rect {arg1})

%fun AdjustWindowRectEx :: RECT -> WindowStyle -> Bool -> WindowStyleEx -> IO RECT
%call (declare {RECT} arg1 in (rect {arg1})) (windowStyle arg2) (bool arg3) (windowStyleEx arg4)
%code BOOL success = AdjustWindowRectEx(&arg1, arg2, arg3, arg4)
%fail { !success } { ErrorString("AdjustWindowRectEx") }
%result (rect {arg1})

-- Win2K and later:
-- %fun AllowSetForegroundWindow :: DWORD -> IO ()

-- %
-- %dis animateWindowType x = dWORD x
-- type AnimateWindowType   = DWORD

-- %const AnimateWindowType
--        [ AW_SLIDE
--        , AW_ACTIVATE
--        , AW_BLEND
--        , AW_HIDE
--        , AW_CENTER
--        , AW_HOR_POSITIVE
--        , AW_HOR_NEGATIVE
--        , AW_VER_POSITIVE
--        , AW_VER_NEGATIVE
--        ]

-- Win98 or Win2K:
-- %fun AnimateWindow :: HWND -> DWORD -> AnimateWindowType -> IO ()
-- %code BOOL success = AnimateWindow(arg1,arg2,arg3)
-- %fail { !success } { ErrorWin("AnimateWindow") }

%fun AnyPopup :: IO Bool

%fun ArrangeIconicWindows :: HWND -> IO ()
%code UINT success = ArrangeIconicWindows(arg1);
%fail {success == 0} { ErrorWin("ArrangeIconicWindows") }

%fun BeginDeferWindowPos :: Int -> IO HDWP
%fail {res1 == NULL} { ErrorWin("BeginDeferWindowPos") }

%fun BringWindowToTop :: HWND -> IO ()
%safecode BOOL success = BringWindowToTop(arg1);
%fail { !success } { ErrorString("BringWindowToTop") }

%fun ChildWindowFromPoint :: HWND -> POINT -> IO MbHWND
%call (hWND hwnd) (declare {POINT} p in (point {p}))
%code BOOL success = ChildWindowFromPoint(hwnd,p);
%fail { !success } { ErrorString("ChildWindowFromPoint") }

%fun ChildWindowFromPointEx :: HWND -> POINT -> DWORD -> IO MbHWND
%call (hWND hwnd) (declare {POINT} p in (point {p})) (dWORD arg2)
%code BOOL success = ChildWindowFromPointEx(hwnd,p,arg2);
%fail { !success } { ErrorString("ChildWindowFromPointEx") }

%fun CloseWindow    :: HWND -> IO ()
%safecode BOOL success = DestroyWindow(arg1)
%fail { !success } { ErrorWin("CloseWindow") }

%fun DeferWindowPos :: HDWP -> HWND -> HWND -> Int -> Int -> Int -> Int -> SetWindowPosFlags -> IO HDWP
%fail {res1 == NULL} { ErrorWin("DeferWindowPos") }

%fun DestroyWindow    :: HWND -> IO ()
%safecode BOOL success = DestroyWindow(arg1)
%fail { !success } { ErrorWin("DestroyWindow") }

%fun EndDeferWindowPos :: HDWP -> IO ()
%code BOOL success = EndDeferWindowPos(arg1)
%fail { !success } { ErrorWin("EndDeferWindowPos") }

%fun FindWindow :: String -> String -> IO MbHWND

%fun FindWindowEx :: HWND -> HWND -> String -> String -> IO MbHWND

%fun FlashWindow      :: HWND -> Bool -> IO Bool
-- No error code

%fun MoveWindow :: HWND -> Int -> Int -> Int -> Int -> Bool -> IO ()
%safecode BOOL success = MoveWindow(arg1,arg2,arg3,arg4,arg5,arg6)
%fail { success==0 } { ErrorWin("MoveWindow") }

%fun GetDesktopWindow :: IO HWND

%fun GetForegroundWindow :: IO HWND

%fun GetParent :: HWND -> IO HWND
%code HWND res1 = GetParent(arg1)
%fail { res1 == NULL } { ErrorWin("GetParent") }

%fun GetTopWindow :: HWND -> IO HWND
%code HWND res1 = GetTopWindow(arg1)
%fail { res1 == NULL } { ErrorWin("GetTopWindow") }


type SetWindowPosFlags = UINT
%dis setWindowPosFlags x = uINT x

%const SetWindowPosFlags
% [ SWP_NOSIZE
% , SWP_NOMOVE
% , SWP_NOZORDER
% , SWP_NOREDRAW
% , SWP_NOACTIVATE
% , SWP_FRAMECHANGED
% , SWP_SHOWWINDOW
% , SWP_HIDEWINDOW
% , SWP_NOCOPYBITS
% , SWP_NOOWNERZORDER
% , SWP_NOSENDCHANGING
% , SWP_DRAWFRAME
% , SWP_NOREPOSITION
% ]

----------------------------------------------------------------
-- HDCs
----------------------------------------------------------------

%dis getDCExFlags x = dWORD x
type GetDCExFlags   = DWORD

%const GetDCExFlags 
% [ DCX_WINDOW
% , DCX_CACHE
% , DCX_CLIPCHILDREN
% , DCX_CLIPSIBLINGS
% , DCX_PARENTCLIP
% , DCX_EXCLUDERGN
% , DCX_INTERSECTRGN
% , DCX_LOCKWINDOWUPDATE
% ]

-- apparently mostly fails if you use invalid hwnds
%fun GetDCEx     :: HWND -> HRGN -> GetDCExFlags -> IO HDC
%fail {res1==NULL} {ErrorString("GetDCEx")}

%fun GetDC       :: MbHWND -> IO HDC
%fail {res1==NULL} {ErrorString("GetDC")}

%fun GetWindowDC :: MbHWND -> IO HDC
%fail {res1==NULL} {ErrorString("GetWindowDC")}

%fun ReleaseDC   :: MbHWND -> HDC -> IO ()
%code BOOL success = ReleaseDC(arg1,arg2)
%fail {!success} {ErrorString("ReleaseDC")}

%fun GetDCOrgEx :: HDC -> IO POINT
%code BOOL success = GetDCOrgEx(arg1,&res1)
%fail {!success} {ErrorString("GetDCOrgEx")}
%result (declare {POINT} res1 in (point {res1}))

----------------------------------------------------------------
-- Caret
----------------------------------------------------------------

%fun HideCaret    :: HWND -> IO ()
%code BOOL success = HideCaret(arg1)
%fail {!success} {ErrorString("HideCaret")}

%fun ShowCaret    :: HWND -> IO ()
%code BOOL success = ShowCaret(arg1)
%fail {!success} {ErrorString("ShowCaret")}

-- ToDo: allow arg2 to be NULL or {(HBITMAP)1}
%fun CreateCaret  :: HWND -> HBITMAP -> MbINT -> MbINT -> IO ()
%code BOOL success = CreateCaret(arg1,arg2,arg3,arg4)
%fail {!success} {ErrorWin("CreateCaret")}

%fun DestroyCaret :: IO ()
%code BOOL success = DestroyCaret()
%fail {!success} {ErrorWin("DestroyCaret")}

%fun getCaretPos :: IO POINT
%code  BOOL success = GetCaretPos(&res1)
%fail {!success} {ErrorWin("GetCaretPos")}
%result (declare {POINT} res1 in (point {res1}))

%fun SetCaretPos :: POINT -> IO ()
%call (declare {POINT} arg1 in (point {arg1}))
%code BOOL success = SetCaretPos(arg1.x, arg1.y)
%fail {!success} {ErrorWin("SetCaretPos")}

-- The remarks on SetCaretBlinkTime are either highly risible or very sad -
-- depending on whether you plan to use this function.

----------------------------------------------------------------
-- MSGs and event loops
--
-- Note that the following functions have to be reentrant:
--
--   DispatchMessage
--   SendMessage
--   UpdateWindow   (I think)
--   RedrawWindow   (I think)
--
-- The following dont have to be reentrant (according to documentation)
--
--   GetMessage
--   PeekMessage
--   TranslateMessage
--
-- For Hugs (and possibly NHC too?) this is no big deal.
-- For GHC, you have to use casm_GC instead of casm.
-- (It might be simpler to just put all this code in another
-- file and build it with the appropriate command line option...)
----------------------------------------------------------------

-- type MSG = 
--   ( HWND   -- hwnd;	
--   , UINT   -- message;
--   , WPARAM -- wParam;
--   , LPARAM -- lParam;
--   , DWORD  -- time;
--   , POINT  -- pt;
--   )

%dis lPMSG x = addr ({MSG *} x)
type LPMSG   = Addr

-- A NULL window requests messages for any window belonging to this thread.
-- a "success" value of 0 indicates that WM_QUIT was received
%fun GetMessage :: MbHWND -> IO LPMSG
%safecode static MSG msg;
%     BOOL success = GetMessage(&msg, arg1, 0, 0);
%fail { success == -1 } {ErrorString("GetMessage")}
%result (lPMSG {&msg})

%fun GetMessage2 :: MbHWND -> IO (LPMSG, Bool)
%safecode static MSG msg;
%     BOOL success = GetMessage(&msg, arg1, 0, 0);
%fail { success == -1 } {ErrorString("GetMessage")}
%result (lPMSG {&msg}, bool {success !=0})

-- A NULL window requests messages for any window belonging to this thread.
-- Arguably the code block shouldn't be a 'safe' one, but it shouldn't really
-- hurt.
%fun PeekMessage :: MbHWND -> UINT -> UINT -> UINT -> IO LPMSG
%safecode static MSG msg;
%     BOOL success = PeekMessage(&msg, arg1, arg2, arg3,arg4);
%fail { success == -1 } {ErrorString("PeekMessage")}
%result (lPMSG {&msg})

-- Note: youre not supposed to call this if youre using accelerators
%fun TranslateMessage :: LPMSG -> IO BOOL
%safecode BOOL res1 = TranslateMessage(arg1);

%fun UpdateWindow     :: HWND -> IO ()
%safecode BOOL success = UpdateWindow(arg1)
%fail { !success } { ErrorString("UpdateWindow") }

-- Return value of DispatchMessage is usually ignored
%fun DispatchMessage  :: LPMSG -> IO LONG
%safecode LONG res1 = DispatchMessage(arg1);

%fun SendMessage :: HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
%safecode LRESULT res1 = SendMessage(arg1,arg2,arg3,arg4);

----------------------------------------------------------------

-- ToDo: figure out reentrancy stuff
-- ToDo: catch error codes
--
-- ToDo: how to send HWND_BROADCAST to PostMessage
-- %fun PostMessage       :: MbHWND -> WindowMessage -> WPARAM -> LPARAM -> IO ()
-- %fun PostQuitMessage   :: Int -> IO ()
-- %fun PostThreadMessage :: DWORD -> WindowMessage -> WPARAM -> LPARAM -> IO ()
-- %fun InSendMessage     :: IO Bool

----------------------------------------------------------------
-- End
----------------------------------------------------------------