import winim/[ lean
             ]

import winim/inc/[ windef
                ]

, ../../wain/[ waindow_object
                 , keyboard 
                  ]

, utils

proc WindowProc*( hwnd: HWND
                , message: UINT
                , wParam: WPARAM
                , lParam: LPARAM
                ): LRESULT {.stdcall.} =
 var 
  hdc: HDC 
  bOpened: bool
  a_waindow = cast[ptr Waindow]( GetWindowLongPtr( hwnd
                                                  ,  GWLP_USERDATA
                                                  )
                                           )
  the_struct: LPCREATESTRUCT = cast[LPCREATESTRUCT](lParam)
 
 case message
 
 of WM_NULL: 
  echo "WM_NULL"

 of WM_CREATE: 
  echo "WM_CREATE"
  a_waindow = create(Waindow)
  a_waindow = cast[ptr Waindow]( the_struct.lpCreateParams) 
  SetWindowLongPtr( hwnd, GWLP_USERDATA, cast[LONG_PTR]( a_waindow) )
  SetWindowPos(hwnd, hwnd, 0, 0, 0, 0, SWP_NOSIZE)
#[   SetProp( hwnd
                 , "portal_0"
                 , cast[HANDLE] (a_waindow)
                 ) ]#

 of WM_DESTROY:
   PostQuitMessage(0)
   return 0
 
 of WM_MOVE:
  echo "WM_MOVE"
 
 of WM_SIZE:
  echo "WM_SIZE"
 
 of WM_ACTIVATE:
  echo "WM_ACTIVATE"

 of WM_SETFOCUS:
  echo "WM_SET_FOCUS"
 
 of WM_ENABLE:
  echo "WM_ENABLE"
 
 of WM_SETREDRAW:
  echo "WM_SET_REDRAW"
 
 of WM_SETTEXT:
  echo "WM_SET_TEXT"
 
 of WM_GETTEXT:
  echo "WM_GET_TEXT"
 
 of WM_GET_TEXTLENGTH:
  echo "WM_WM_GET_TEXT_LENGTH"
 
 of WM_PAINT:
   var 
    ps: PAINTSTRUCT
    hdc = BeginPaint(hwnd, ps)
   
   defer: EndPaint(hwnd, ps)
   var rect: RECT
   GetClientRect(hwnd, rect)
   #DrawText(hdc, "Hello, Windows!", -1, rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER)
   return 0
 
 of WM_CLOSE:
  
  discard DestroyWindow(hwnd)
  a_waindow[].relays.window_closed_relay(a_waindow[])
 
 of WM_CHAR: discard
  
 of WM_KEYUP ,WM_SYSKEYUP: 
  var 
   virtual_key_code: WORD = LOWORD(wParam)      
   the_wain_key = wain_keyboard_key_from_windows_virtual_key_code(virtual_key_code)                   
  
  echo "up: ", virtual_key_code
  update_keyboard( the_wain_key
                               , ord Release
                               )

  a_waindow[].relays.key_relay(a_waindow[]
                                            , the_wain_key.key
                                            , ord Release 
                                            )
 of WM_KEYDOWN, WM_SYSKEYDOWN: 
  var 
   virtual_key_code: WORD = LOWORD(wParam)                        
  
   key_flags: WORD = HIWORD(lParam)
   scan_code: WORD = LOBYTE(keyFlags)
   is_extended_key: bool = (keyFlags and KF_EXTENDED) == KF_EXTENDED # true if scancode has 0xE0 prefix
   wasKeyDown: bool = (keyFlags and KF_REPEAT) == KF_REPEAT          # previous key-state flag, 1 on autorepeat
   repeatCount: uint16 = LOWORD(lParam)                              # repeat count, > 0 if several keydown messages was combined into one message
   isKeyReleased: bool = (keyFlags and  KF_UP) == KF_UP             # transition-state flag, 1 on keyup

  if is_extended_key: 
   scan_code = MAKEWORD(scanCode, 0xE0)
    
  # if we want to distinguish these keys:
  case virtual_key_code
   # converts to VK_LSHIFT or VK_RSHIFT
   # converts to VK_LCONTROL or VK_RCONTROL
   # converts to VK_LMENU or VK_RMENU
   of VK_SHIFT, VK_CONTROL, VK_MENU:    
    virtual_key_code = LOWORD( MapVirtualKey( UINT(scan_code)
                                   , UINT(MAPVK_VSC_TO_VK_EX))
                                   )
   else: discard 
  
  echo "down: ", virtual_key_code
  var the_wain_key = wain_keyboard_key_from_windows_virtual_key_code(virtual_key_code)
  
  update_keyboard( the_wain_key
                               , ord Press
                               ) 
  a_waindow[].relays.key_relay( a_waindow[]
                                                 , the_wain_key.key
                                                 , Press.ord
                                                 )
  
 of WM_INPUTLANGCHANGE: 
    # determine the thread that'll receive this event
  var 
   window = GetForegroundWindow()
   thread = GetWindowThreadProcessId( window 
                                                               , nil
                                                               )
   
   # get keyboard layout for the thread
   hkl: HKL  = GetKeyboardLayout(thread)
   the_actual_layout_name: LPWSTR = ""
   layout_name_bool =  GetKeyboardLayoutName(the_actual_layout_name)

  LoadKeyboardLayout( $the_actual_layout_name
                                    , KLF_ACTIVATE
                                    )
  ActivateKeyboardLayout( hkl
                        , KLF_ACTIVATE
                        )  

  echo "now using: ",  $the_actual_layout_name
 
#[  of WM_QUERYENDSESSION: echo " WM_QUERYENDSESSION" 
 of WM_QUIT: echo " WM_QUIT"
 of WM_QUERYOPEN: echo " WM_QUERYOPEN"
 #of WM_ERASEBKGND: echo " WM_ERASEBKGND"
 of WM_SYSCOLORCHANGE: echo " WM_SYSCOLORCHANGE"
 of WM_ENDSESSION: echo " WM_ENDSESSION"
 of WM_SHOWWINDOW: echo " WM_SHOWWINDOW"
 #of WM_CTLCOLOR: echo " WM_CTLCOLOR"
 of WM_WININICHANGE: echo " WM_WININICHANGE"
 of WM_DEVMODECHANGE: echo " WM_DEVMODECHANGE"
 of WM_ACTIVATEAPP: echo " WM_ACTIVATEAPP"
 of WM_FONTCHANGE: echo " WM_FONTCHANGE"
 of WM_TIMECHANGE: echo " WM_TIMECHANGE"
 of WM_CANCELMODE: echo " WM_CANCELMODE"
 #of WM_SETCURSOR: echo " WM_SETCURSOR"
 of WM_MOUSEACTIVATE: echo " WM_MOUSEACTIVATE"
 of WM_CHILDACTIVATE: echo " WM_CHILDACTIVATE"
 of WM_QUEUESYNC: echo " WM_QUEUESYNC"
 #of WM_GETMINMAXINFO: echo " WM_GETMINMAXINFO"
 of WM_PAINTICON: echo " WM_PAINTICON"
 of WM_ICONERASEBKGND: echo " WM_ICONERASEBKGND"
 of WM_NEXTDLGCTL: echo " WM_NEXTDLGCTL"
 of WM_SPOOLERSTATUS: echo " WM_SPOOLERSTATUS"
 of WM_DRAWITEM: echo " WM_DRAWITEM"
 of WM_MEASUREITEM: echo " WM_MEASUREITEM"
 of WM_DELETEITEM: echo " WM_DELETEITEM"
 of WM_VKEYTOITEM: echo " WM_VKEYTOITEM"
 of WM_CHARTOITEM: echo " WM_CHARTOITEM"
 of WM_SETFONT: echo " WM_SETFONT"
 of WM_GETFONT: echo " WM_GETFONT"
 of WM_SETHOTKEY: echo " WM_SETHOTKEY"
 of WM_GETHOTKEY: echo " WM_GETHOTKEY"
 of WM_QUERYDRAGICON: echo " WM_QUERYDRAGICON"
 of WM_COMPAREITEM: echo " WM_COMPAREITEM"
 of WM_GETOBJECT: echo " WM_GETOBJECT"
 of WM_COMPACTING: echo " WM_COMPACTING"
 of WM_COMMNOTIFY: echo " WM_COMMNOTIFY"
 of WM_WINDOWPOSCHANGING: echo " WM_WINDOWPOSCHANGING"
 of WM_WINDOWPOSCHANGED: echo " WM_WINDOWPOSCHANGED"
 of WM_POWER: echo " WM_POWER"
 #of WM_COPYGLOBALDATA: echo " WM_COPYGLOBALDATA"
 of WM_COPYDATA: echo " WM_COPYDATA"
 of WM_CANCELJOURNAL: echo " WM_CANCELJOURNAL"
 of WM_NOTIFY: echo " WM_NOTIFY"
 of WM_INPUTLANGCHANGEREQUEST: echo " WM_INPUTLANGCHANGEREQUEST"
 of WM_TCARD: echo " WM_TCARD"
 of WM_HELP: echo " WM_HELP"
 of WM_USERCHANGED: echo " WM_USERCHANGED"
 of WM_NOTIFYFORMAT: echo " WM_NOTIFYFORMAT"
 of WM_CONTEXTMENU: echo " WM_CONTEXTMENU"
 of WM_STYLECHANGING: echo " WM_STYLECHANGING"
 of WM_STYLECHANGED: echo " WM_STYLECHANGED"
 of WM_DISPLAYCHANGE: echo " WM_DISPLAYCHANGE"
 #of WM_GETICON: echo " WM_GETICON"
 #of WM_SETICON: echo " WM_SETICON"
 #of WM_NCCREATE: echo " WM_NCCREATE"
 #of WM_NCDESTROY: echo " WM_NCDESTROY"
 of WM_NCCALCSIZE: echo " WM_NCCALCSIZE"
 #of WM_NCHITTEST: echo " WM_NCHITTEST"
 of WM_NCPAINT: echo " WM_NCPAINT"
 of WM_NCACTIVATE: echo " WM_NCACTIVATE"
 of WM_GETDLGCODE: echo " WM_GETDLGCODE"
 of WM_SYNCPAINT: echo " WM_SYNCPAINT"
 of WM_NCMOUSEMOVE: echo " WM_NCMOUSEMOVE"
 of WM_NCLBUTTONDOWN: echo " WM_NCLBUTTONDOWN"
 of WM_NCLBUTTONUP: echo " WM_NCLBUTTONUP"
 of WM_NCLBUTTONDBLCLK: echo " WM_NCLBUTTONDBLCLK"
 of WM_NCRBUTTONDOWN: echo " WM_NCRBUTTONDOWN"
 of WM_NCRBUTTONUP: echo " WM_NCRBUTTONUP"
 of WM_NCRBUTTONDBLCLK: echo " WM_NCRBUTTONDBLCLK"
 of WM_NCMBUTTONDOWN: echo " WM_NCMBUTTONDOWN"
 of WM_NCMBUTTONUP: echo " WM_NCMBUTTONUP"
 of WM_NCMBUTTONDBLCLK: echo " WM_NCMBUTTONDBLCLK"
 of WM_NCXBUTTONDOWN: echo " WM_NCXBUTTONDOWN"
 of WM_NCXBUTTONUP: echo " WM_NCXBUTTONUP"
 of WM_NCXBUTTONDBLCLK: echo " WM_NCXBUTTONDBLCLK"
 of EM_GETSEL: echo " EM_GETSEL"
 of EM_SETSEL: echo " EM_SETSEL"
 of EM_GETRECT: echo " EM_GETRECT"
 of EM_SETRECT: echo " EM_SETRECT"
 of EM_SETRECTNP: echo " EM_SETRECTNP"
 of EM_SCROLL: echo " EM_SCROLL"
 of EM_LINESCROLL: echo " EM_LINESCROLL"
 of EM_SCROLLCARET: echo " EM_SCROLLCARET"
 of EM_GETMODIFY: echo " EM_GETMODIFY"
 of EM_SETMODIFY: echo " EM_SETMODIFY"
 of EM_GETLINECOUNT: echo " EM_GETLINECOUNT"
 of EM_LINEINDEX: echo " EM_LINEINDEX"
 of EM_SETHANDLE: echo " EM_SETHANDLE"
 of EM_GETHANDLE: echo " EM_GETHANDLE"
 of EM_GETTHUMB: echo " EM_GETTHUMB"
 of EM_LINELENGTH: echo " EM_LINELENGTH"
 of EM_REPLACESEL: echo " EM_REPLACESEL"
 #of EM_SETFONT: echo " EM_SETFONT"
 of EM_GETLINE: echo " EM_GETLINE"
 of EM_LIMITTEXT: echo " EM_LIMITTEXT"
 #of EM_SETLIMITTEXT: echo " EM_SETLIMITTEXT"
 of EM_CANUNDO: echo " EM_CANUNDO"
 of EM_UNDO: echo " EM_UNDO"
 of EM_FMTLINES: echo " EM_FMTLINES"
 of EM_LINEFROMCHAR: echo " EM_LINEFROMCHAR"
 #of EM_SETWORDBREAK: echo " EM_SETWORDBREAK"
 of EM_SETTABSTOPS: echo " EM_SETTABSTOPS"
 of EM_SETPASSWORDCHAR: echo " EM_SETPASSWORDCHAR"
 of EM_EMPTYUNDOBUFFER: echo " EM_EMPTYUNDOBUFFER"
 of EM_GETFIRSTVISIBLELINE: echo " EM_GETFIRSTVISIBLELINE"
 of EM_SETREADONLY: echo " EM_SETREADONLY"
 of EM_SETWORDBREAKPROC: echo " EM_SETWORDBREAKPROC"
 of EM_GETWORDBREAKPROC: echo " EM_GETWORDBREAKPROC"
 of EM_GETPASSWORDCHAR: echo " EM_GETPASSWORDCHAR"
 of EM_SETMARGINS: echo " EM_SETMARGINS"
 of EM_GETMARGINS: echo " EM_GETMARGINS"
 of EM_GETLIMITTEXT: echo " EM_GETLIMITTEXT"
 of EM_POSFROMCHAR: echo " EM_POSFROMCHAR"
 of EM_CHARFROMPOS: echo " EM_CHARFROMPOS"
 of EM_SETIMESTATUS: echo " EM_SETIMESTATUS"
 of EM_GETIMESTATUS: echo " EM_GETIMESTATUS"
 of SBM_SETPOS: echo " SBM_SETPOS"
 of SBM_GETPOS: echo " SBM_GETPOS"
 of SBM_SETRANGE: echo " SBM_SETRANGE"
 of SBM_GETRANGE: echo " SBM_GETRANGE"
 of SBM_ENABLE_ARROWS: echo " SBM_ENABLE_ARROWS"
 of SBM_SETRANGEREDRAW: echo " SBM_SETRANGEREDRAW"
 of SBM_SETSCROLLINFO: echo " SBM_SETSCROLLINFO"
 of SBM_GETSCROLLINFO: echo " SBM_GETSCROLLINFO"
 of SBM_GETSCROLLBARINFO: echo " SBM_GETSCROLLBARINFO"
 of BM_GETCHECK: echo " BM_GETCHECK"
 of BM_SETCHECK: echo " BM_SETCHECK"
 of BM_GETSTATE: echo " BM_GETSTATE"
 of BM_SETSTATE: echo " BM_SETSTATE"
 of BM_SETSTYLE: echo " BM_SETSTYLE"
 of BM_CLICK: echo " BM_CLICK"
 of BM_GETIMAGE: echo " BM_GETIMAGE"
 of BM_SETIMAGE: echo " BM_SETIMAGE"
 of BM_SETDONTCLICK: echo " BM_SETDONTCLICK"
 of WM_INPUT: echo " WM_INPUT"
 #of WM_KEYFIRST: echo " WM_KEYFIRST"
 of WM_DEADCHAR: echo " WM_DEADCHAR"
 of WM_SYSCHAR: echo " WM_SYSCHAR"
 of WM_SYSDEADCHAR: echo " WM_SYSDEADCHAR"
 of WM_UNICHAR: echo " WM_UNICHAR"
  #of WM_WNT_CONVERTREQUESTEX: echo " WM_WNT_CONVERTREQUESTEX"
 #of WM_CONVERTREQUEST: echo " WM_CONVERTREQUEST"
 #of WM_CONVERTRESULT: echo " WM_CONVERTRESULT"
 #of WM_INTERIM: echo " WM_INTERIM"
 of WM_IME_STARTCOMPOSITION: echo " WM_IME_STARTCOMPOSITION"
 of WM_IME_ENDCOMPOSITION: echo " WM_IME_ENDCOMPOSITION"
 of WM_IME_COMPOSITION: echo " WM_IME_COMPOSITION"
 of WM_INITDIALOG: echo " WM_INITDIALOG"
 of WM_COMMAND: echo " WM_COMMAND"
 of WM_SYSCOMMAND: echo " WM_SYSCOMMAND"
 of WM_TIMER: echo " WM_TIMER"
 of WM_HSCROLL: echo " WM_HSCROLL"
 of WM_VSCROLL: echo " WM_VSCROLL"
 of WM_INITMENU: echo " WM_INITMENU"
 of WM_INITMENUPOPUP: echo " WM_INITMENUPOPUP"
 #of WM_SYSTIMER: echo " WM_SYSTIMER"
 of WM_MENUSELECT: echo " WM_MENUSELECT"
 of WM_MENUCHAR: echo " WM_MENUCHAR"
 of WM_ENTERIDLE: echo " WM_ENTERIDLE"
 of WM_MENURBUTTONUP: echo " WM_MENURBUTTONUP"
 of WM_MENUDRAG: echo " WM_MENUDRAG"
 of WM_MENUGETOBJECT: echo " WM_MENUGETOBJECT"
 of WM_UNINITMENUPOPUP: echo " WM_UNINITMENUPOPUP"
 of WM_MENUCOMMAND: echo " WM_MENUCOMMAND"
 of WM_CHANGEUISTATE: echo " WM_CHANGEUISTATE"
 of WM_UPDATEUISTATE: echo " WM_UPDATEUISTATE"
 of WM_QUERYUISTATE: echo " WM_QUERYUISTATE"
 #of WM_LBTRACKPOINT: echo " WM_LBTRACKPOINT"
 of WM_CTLCOLORMSGBOX: echo " WM_CTLCOLORMSGBOX"
 of WM_CTLCOLOREDIT: echo " WM_CTLCOLOREDIT"
 of WM_CTLCOLORLISTBOX: echo " WM_CTLCOLORLISTBOX"
 of WM_CTLCOLORBTN: echo " WM_CTLCOLORBTN"
 of WM_CTLCOLORDLG: echo " WM_CTLCOLORDLG"
 of WM_CTLCOLORSCROLLBAR: echo " WM_CTLCOLORSCROLLBAR"
 of WM_CTLCOLORSTATIC: echo " WM_CTLCOLORSTATIC"
 of CB_GETEDITSEL: echo " CB_GETEDITSEL"
 of CB_LIMITTEXT: echo " CB_LIMITTEXT"
 of CB_SETEDITSEL: echo " CB_SETEDITSEL"
 of CB_ADDSTRING: echo " CB_ADDSTRING"
 of CB_DELETESTRING: echo " CB_DELETESTRING"
 of CB_DIR: echo " CB_DIR"
 of CB_GETCOUNT: echo " CB_GETCOUNT"
 of CB_GETCURSEL: echo " CB_GETCURSEL"
 of CB_GETLBTEXT: echo " CB_GETLBTEXT"
 of CB_GETLBTEXTLEN: echo " CB_GETLBTEXTLEN"
 of CB_INSERTSTRING: echo " CB_INSERTSTRING"
 of CB_RESETCONTENT: echo " CB_RESETCONTENT"
 of CB_FINDSTRING: echo " CB_FINDSTRING"
 of CB_SELECTSTRING: echo " CB_SELECTSTRING"
 of CB_SETCURSEL: echo " CB_SETCURSEL"
 of CB_SHOWDROPDOWN: echo " CB_SHOWDROPDOWN"
 of CB_GETITEMDATA: echo " CB_GETITEMDATA"
 of CB_SETITEMDATA: echo " CB_SETITEMDATA"
 of CB_GETDROPPEDCONTROLRECT: echo " CB_GETDROPPEDCONTROLRECT"
 of CB_SETITEMHEIGHT: echo " CB_SETITEMHEIGHT"
 of CB_GETITEMHEIGHT: echo " CB_GETITEMHEIGHT"
 of CB_SETEXTENDEDUI: echo " CB_SETEXTENDEDUI"
 of CB_GETEXTENDEDUI: echo " CB_GETEXTENDEDUI"
 of CB_GETDROPPEDSTATE: echo " CB_GETDROPPEDSTATE"
 of CB_FINDSTRINGEXACT: echo " CB_FINDSTRINGEXACT"
 of CB_SETLOCALE: echo " CB_SETLOCALE"
 of CB_GETLOCALE: echo " CB_GETLOCALE"
 of CB_GETTOPINDEX: echo " CB_GETTOPINDEX"
 of CB_SETTOPINDEX: echo " CB_SETTOPINDEX"
 of CB_GETHORIZONTALEXTENT: echo " CB_GETHORIZONTALEXTENT"
 of CB_SETHORIZONTALEXTENT: echo " CB_SETHORIZONTALEXTENT"
 of CB_GETDROPPEDWIDTH: echo " CB_GETDROPPEDWIDTH"
 of CB_SETDROPPEDWIDTH: echo " CB_SETDROPPEDWIDTH"
 of CB_INITSTORAGE: echo " CB_INITSTORAGE"
 of CB_MULTIPLEADDSTRING: echo " CB_MULTIPLEADDSTRING"
 of CB_GETCOMBOBOXINFO: echo " CB_GETCOMBOBOXINFO"
 of CB_MSGMAX: echo " CB_MSGMAX"
 #of WM_MOUSEFIRST: echo " WM_MOUSEFIRST"
 of WM_LBUTTONDOWN: echo " WM_LBUTTONDOWN"
 of WM_LBUTTONUP: echo " WM_LBUTTONUP"
 of WM_LBUTTONDBLCLK: echo " WM_LBUTTONDBLCLK"
 of WM_RBUTTONDOWN: echo " WM_RBUTTONDOWN"
 of WM_RBUTTONUP: echo " WM_RBUTTONUP"
 of WM_RBUTTONDBLCLK: echo " WM_RBUTTONDBLCLK"
 of WM_MBUTTONDOWN: echo " WM_MBUTTONDOWN"
 of WM_MBUTTONUP: echo " WM_MBUTTONUP"
 of WM_MBUTTONDBLCLK: echo " WM_MBUTTONDBLCLK"
 of WM_MOUSELAST: echo " WM_MOUSELAST"
 of WM_MOUSEWHEEL: echo " WM_MOUSEWHEEL"
 of WM_XBUTTONDOWN: echo " WM_XBUTTONDOWN"
 of WM_XBUTTONUP: echo " WM_XBUTTONUP"
 of WM_XBUTTONDBLCLK: echo " WM_XBUTTONDBLCLK"
 #of WM_MOUSEHWHEEL: echo " WM_MOUSEHWHEEL"
 of WM_PARENTNOTIFY: echo " WM_PARENTNOTIFY"
 of WM_ENTERMENULOOP: echo " WM_ENTERMENULOOP"
 of WM_EXITMENULOOP: echo " WM_EXITMENULOOP"
 of WM_NEXTMENU: echo " WM_NEXTMENU"
 of WM_SIZING: echo " WM_SIZING"
 of WM_CAPTURECHANGED: echo " WM_CAPTURECHANGED"
 of WM_MOVING: echo " WM_MOVING"
 of WM_POWERBROADCAST: echo " WM_POWERBROADCAST"
 of WM_DEVICECHANGE: echo " WM_DEVICECHANGE"
 of WM_MDICREATE: echo " WM_MDICREATE"
 of WM_MDIDESTROY: echo " WM_MDIDESTROY"
 of WM_MDIACTIVATE: echo " WM_MDIACTIVATE"
 of WM_MDIRESTORE: echo " WM_MDIRESTORE"
 of WM_MDINEXT: echo " WM_MDINEXT"
 of WM_MDIMAXIMIZE: echo " WM_MDIMAXIMIZE"
 of WM_MDITILE: echo " WM_MDITILE"
 of WM_MDICASCADE: echo " WM_MDICASCADE"
 of WM_MDIICONARRANGE: echo " WM_MDIICONARRANGE"
 of WM_MDIGETACTIVE: echo " WM_MDIGETACTIVE"
 of WM_MDISETMENU: echo " WM_MDISETMENU"
 of WM_ENTERSIZEMOVE: echo " WM_ENTERSIZEMOVE"
 of WM_EXITSIZEMOVE: echo " WM_EXITSIZEMOVE"
 of WM_DROPFILES: echo " WM_DROPFILES"
 of WM_MDIREFRESHMENU: echo " WM_MDIREFRESHMENU"
 #of WM_IME_REPORT: echo " WM_IME_REPORT"
 of WM_IME_SETCONTEXT: echo " WM_IME_SETCONTEXT"
 of WM_IME_NOTIFY: echo " WM_IME_NOTIFY"
 of WM_IME_CONTROL: echo " WM_IME_CONTROL"
 of WM_IME_COMPOSITIONFULL: echo " WM_IME_COMPOSITIONFULL"
 of WM_IME_SELECT: echo " WM_IME_SELECT"
 of WM_IME_CHAR: echo " WM_IME_CHAR"
 of WM_IME_REQUEST: echo " WM_IME_REQUEST"
 of WM_IMEKEYDOWN: echo " WM_IMEKEYDOWN"
 #of WM_IME_KEYDOWN: echo " WM_IME_KEYDOWN"
 of WM_IMEKEYUP: echo " WM_IMEKEYUP"
 #of WM_IME_KEYUP: echo " WM_IME_KEYUP"
 of WM_NCMOUSEHOVER: echo " WM_NCMOUSEHOVER"
 of WM_MOUSEHOVER: echo " WM_MOUSEHOVER"
 of WM_NCMOUSELEAVE: echo " WM_NCMOUSELEAVE"
 of WM_MOUSELEAVE: echo " WM_MOUSELEAVE"
 of WM_CUT: echo " WM_CUT"
 of WM_COPY: echo " WM_COPY"
 of WM_PASTE: echo " WM_PASTE"
 of WM_CLEAR: echo " WM_CLEAR"
 of WM_UNDO: echo " WM_UNDO"
 of WM_RENDERFORMAT: echo " WM_RENDERFORMAT"
 of WM_RENDERALLFORMATS: echo " WM_RENDERALLFORMATS"
 of WM_DESTROYCLIPBOARD: echo " WM_DESTROYCLIPBOARD"
 of WM_DRAWCLIPBOARD: echo " WM_DRAWCLIPBOARD"
 of WM_PAINTCLIPBOARD: echo " WM_PAINTCLIPBOARD"
 of WM_VSCROLLCLIPBOARD: echo " WM_VSCROLLCLIPBOARD"
 of WM_SIZECLIPBOARD: echo " WM_SIZECLIPBOARD"
 of WM_ASKCBFORMATNAME: echo " WM_ASKCBFORMATNAME"
 of WM_CHANGECBCHAIN: echo " WM_CHANGECBCHAIN"
 of WM_HSCROLLCLIPBOARD: echo " WM_HSCROLLCLIPBOARD"
 of WM_QUERYNEWPALETTE: echo " WM_QUERYNEWPALETTE"
 of WM_PALETTEISCHANGING: echo " WM_PALETTEISCHANGING"
 of WM_PALETTECHANGED: echo " WM_PALETTECHANGED"
 of WM_HOTKEY: echo " WM_HOTKEY"
 of WM_PRINT: echo " WM_PRINT"
 of WM_PRINTCLIENT: echo " WM_PRINTCLIENT"
 of WM_APPCOMMAND: echo " WM_APPCOMMAND"
 of WM_HANDHELDFIRST: echo " WM_HANDHELDFIRST"
 of WM_HANDHELDLAST: echo " WM_HANDHELDLAST"
 of WM_AFXFIRST: echo " WM_AFXFIRST"
 of WM_AFXLAST: echo " WM_AFXLAST"
 of WM_PENWINFIRST: echo " WM_PENWINFIRST"
 of DM_GETDEFID: echo " DM_GETDEFID"
 of DM_SETDEFID: echo " DM_SETDEFID"
 of DM_REPOSITION: echo " DM_REPOSITION"
 ]#
  
 else:
  return DefWindowProc( hwnd
                                      , message
                                      , wParam
                                      , lParam
                                      )