Ejemplo n.º 1
0
extern MRESULT EXPENTRY Button_Processor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {

   static PWINDOWPROC DefaultProcessor = 0 ;

   switch ( msg ) {

      case WM_CREATE: {
         CLASSINFO ClassInfo ;
         WinQueryClassInfo ( WinQueryAnchorBlock(hwnd), WC_BUTTON, &ClassInfo ) ;
         DefaultProcessor = ClassInfo.pfnWindowProc ;
         break; }

      case WM_SETFOCUS: {
         USHORT Id = WinQueryWindowUShort ( hwnd, QWS_ID ) ;
         if ( mp2 ) {
            Sys_SendMessage( hwnd, BM_SETDEFAULT, MPFROMSHORT(TRUE), 0 ) ;
            Sys_SendMessage( OWNER(hwnd), WM_CONTROL, MPFROM2SHORT(Id,BN_SETFOCUS), 0 ) ;
         } else {
            Sys_SendMessage( hwnd, BM_SETDEFAULT, MPFROMSHORT(FALSE), 0 ) ;
            Sys_SendMessage( OWNER(hwnd), WM_CONTROL, MPFROM2SHORT(Id,BN_KILLFOCUS), 0 ) ;
         } /* endif */
         break; }

   } /* endswitch */

   return ( DefaultProcessor ? DefaultProcessor ( hwnd, msg, mp1, mp2 ) : 0 ) ;
}
Ejemplo n.º 2
0
extern MRESULT EXPENTRY ComboBox_Processor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {

   static PWINDOWPROC DefaultProcessor = 0 ;

   switch ( msg ) {

      case WM_CREATE: {
         CLASSINFO ClassInfo ;
         WinQueryClassInfo ( WinQueryAnchorBlock(hwnd), WC_COMBOBOX, &ClassInfo ) ;
         DefaultProcessor = ClassInfo.pfnWindowProc ;
         MRESULT Result = DefaultProcessor ( hwnd, msg, mp1, mp2 ) ;
         HWND Entryfield = WinWindowFromID ( hwnd, CBID_EDIT ) ;
         ULONG Style = WinQueryWindowULong ( hwnd, QWL_STYLE ) ;
         if ( Style & CBS_DROPDOWNLIST ) {
            OldComboEntry_Processor1 = WinSubclassWindow ( Entryfield, ComboEntry_Processor1 ) ;
         } else {
            OldComboEntry_Processor2 = WinSubclassWindow ( Entryfield, ComboEntry_Processor2 ) ;
         } /* endif */
         return ( Result ) ; }

      case WM_CONTROL: {
         USHORT Id = WinQueryWindowUShort ( hwnd, QWS_ID ) ;
         SHORT Control = SHORT1FROMMP ( mp1 ) ;
         SHORT Message = SHORT2FROMMP ( mp1 ) ;
         switch ( Control ) {
            case CBID_EDIT: {
               switch ( Message ) {
                  case EN_SETFOCUS: {
                     Sys_SendMessage( OWNER(hwnd), WM_CONTROL, MPFROM2SHORT(Id,CBN_SETFOCUS), 0 ) ;
                     break; }
                  case EN_KILLFOCUS: {
                     Sys_SendMessage( OWNER(hwnd), WM_CONTROL, MPFROM2SHORT(Id,CBN_KILLFOCUS), 0 ) ;
                     break; }
               } /* endswitch */
               break; }
            case CBID_LIST: {
               switch ( Message ) {
                  case LN_SETFOCUS: {
                     Sys_SendMessage( OWNER(hwnd), WM_CONTROL, MPFROM2SHORT(Id,CBN_SETFOCUS), 0 ) ;
                     break; }
                  case LN_KILLFOCUS: {
                     Sys_SendMessage( OWNER(hwnd), WM_CONTROL, MPFROM2SHORT(Id,CBN_KILLFOCUS), 0 ) ;
                     break; }
               } /* endswitch */
               break; }
         } /* endswitch */
         break; }

      case WM_MEASUREITEM:
         return ( Sys_SendMessage( OWNER(hwnd), msg, mp1, mp2 ) ) ;

      case WM_DRAWITEM: 
         return ( Sys_SendMessage( OWNER(hwnd), msg, mp1, mp2 ) ) ;

   } /* endswitch */

   return ( DefaultProcessor ? DefaultProcessor ( hwnd, msg, mp1, mp2 ) : 0 ) ;
}
Ejemplo n.º 3
0
extern void RegisterControls ( HAB Anchor ) {

   CLASSINFO ClassInfo ;
   WinQueryClassInfo ( Anchor, WC_BUTTON, &ClassInfo ) ;
   ClassInfo.flClassStyle = (unsigned long) ( ClassInfo.flClassStyle & (unsigned long)(~CS_PUBLIC) ) ;

   if ( ! WinRegisterClass ( Anchor, PSZ(BUTTON_CLASS), PWINDOWPROC(Button_Processor),
      ClassInfo.flClassStyle, ClassInfo.cbWindowData ) )
      Log ( "WARNING: Unable to register class '%s'", BUTTON_CLASS ) ;

   WinQueryClassInfo ( Anchor, WC_COMBOBOX, &ClassInfo ) ;
   ClassInfo.flClassStyle = (unsigned long) ( ClassInfo.flClassStyle & (unsigned long)(~CS_PUBLIC) ) ;

   if ( ! WinRegisterClass ( Anchor, PSZ(COMBOBOX_CLASS), PWINDOWPROC(ComboBox_Processor),
      ClassInfo.flClassStyle, ClassInfo.cbWindowData ) )
      Log ( "WARNING: Unable to register class '%s'", COMBOBOX_CLASS ) ;

   WinQueryClassInfo ( Anchor, WC_ENTRYFIELD, &ClassInfo ) ;
   ClassInfo.flClassStyle = (unsigned long) ( ClassInfo.flClassStyle & (unsigned long)(~CS_PUBLIC) ) ;

   if ( ! WinRegisterClass ( Anchor, PSZ(ENTRYFIELD_CLASS), PWINDOWPROC(EntryField_Processor),
      ClassInfo.flClassStyle, ClassInfo.cbWindowData ) )
      Log ( "WARNING: Unable to register class '%s'", ENTRYFIELD_CLASS ) ;
}
Ejemplo n.º 4
0
extern MRESULT EXPENTRY EntryField_Processor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {

   static PWINDOWPROC DefaultProcessor = 0 ;

   switch ( msg ) {

      case WM_CREATE: {
         CLASSINFO ClassInfo ;
         WinQueryClassInfo ( WinQueryAnchorBlock(hwnd), WC_ENTRYFIELD, &ClassInfo ) ;
         DefaultProcessor = ClassInfo.pfnWindowProc ;
         break; }

      case WM_SETFOCUS: {
         Sys_SendMessage( hwnd, EM_SETSEL, MPFROM2SHORT(0,9999), 0 ) ;
         break; }

   } /* endswitch */

   return ( DefaultProcessor ? DefaultProcessor ( hwnd, msg, mp1, mp2 ) : 0 ) ;
}
Ejemplo n.º 5
0
/* ARGSUSED5 */  /* Only Win32 uses gameMode parameter. */
GLUTwindow *
__glutCreateWindow(GLUTwindow * parent,
  int x, int y, int width, int height, int gameMode)
{
  GLUTwindow *window;
  XSetWindowAttributes wa;
  unsigned long attribMask;
  int winnum;
  int i;
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
  GLXFBConfigSGIX fbc;
#else
  void *fbc;
#endif

#if defined(__OS2PM__)
 {
    extern HAB   hab;      /* PM anchor block handle         */
    CLASSINFO classinfo;

    if(!WinQueryClassInfo(hab,"GLUT", &classinfo) )
                               __glutOpenOS2Connection(NULL);
  }
#elif defined(_WIN32)
  WNDCLASS wc;
  int style;

  if (!GetClassInfo(GetModuleHandle(NULL), "GLUT", &wc)) {
    __glutOpenWin32Connection(NULL);
  }
#else
  if (!__glutDisplay) {
    __glutOpenXConnection(NULL);
  }
#endif

#ifndef __OS2PM__
  if (__glutGameModeWindow) {
    __glutFatalError("cannot create windows in game mode.");
  }
#endif

  winnum = getUnusedWindowSlot();
  window = (GLUTwindow *) malloc(sizeof(GLUTwindow));
  if (!window) {
    __glutFatalError("out of memory.");
  }
  window->num = winnum;

#if defined(__OS2PM__)
  /* Add this new window to the window list. */
  __glutWindowList[winnum] = window;
  window->shownState = -1;
#endif

#if !defined(_WIN32)  && !defined(__OS2PM__)
  window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
    &window->visAlloced, (void**) &fbc);
  if (!window->vis) {
    __glutFatalError(
      "visual with necessary capabilities not found.");
  }
  __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
#endif
  window->eventMask = StructureNotifyMask | ExposureMask;

  attribMask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
  wa.background_pixmap = None;
  wa.border_pixel = 0;
  wa.colormap = window->cmap;
  wa.event_mask = window->eventMask;
  if (parent) {
    if (parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
      wa.event_mask |= GLUT_HACK_STOP_PROPAGATE_MASK;
    attribMask |= CWDontPropagate;
    wa.do_not_propagate_mask = parent->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
  } else {
    wa.do_not_propagate_mask = 0;
  }

  /* Stash width and height before Win32's __glutAdjustCoords
     possibly overwrites the values. */
  window->width = width;
  window->height = height;
  window->forceReshape = True;
  window->ignoreKeyRepeat = False;

#if defined(__OS2PM__)

 {  ULONG flStyle=0;
    int ii;
    ERRORID  erridErrorCode;/* last error id code */
    extern HAB   hab;      /* PM anchor block handle         */

  if (parent) {
    flStyle = WS_CLIPCHILDREN|WS_VISIBLE;
  } else {
    if (gameMode) {
      /* Game mode window should be a WS_POPUP window to
         ensure that the taskbar is hidden by it.  A standard
         WS_OVERLAPPEDWINDOW does not hide the task bar. */
      flStyle = FCF_STANDARD |  WS_MAXIMIZED;
    } else {
      /* A standard toplevel window with borders and such. */
      flStyle = FCF_STANDARD | WS_CLIPCHILDREN;
//      flStyle = WS_OVERLAPPEDWINDOW;
    }
  }
{
 HWND  hwnd;                           /* Window     */
 ULONG ListBoxId;                      /* Window id  */
                                       /* (supplied by application) */


 HWND hwndClient;        /* handle to the client                 */
 HWND hwndFrame;         /* handle to the frame                  */
 PFNWP GenericWndProc;
 FRAMECDATA  fcd;
 RECTL  rect;     /* Boundary rectangle                   */



/************************************************/
// flCreate = (FCF_STANDARD) & ~FCF_TASKLIST;
/**********************************/
  if (parent)
  {   window->frame = NULL;

 hwnd = WinCreateWindow(parent->win,  /* Parent window             */
                        "GLUTCHILD",        /* Class name                */
                        "",    /* Window text               */
                        flStyle,       /* Window style              */
                        x, y,          /* Position (x,y)            */
                        width, height,      /* Size (width,height)       */
                        parent->win,    /* Owner window              */
                        HWND_TOP,      /* Sibling window            */
                        0,             /* Window id                 */
                        NULL,          /* Control data              */
                        NULL);         /* Pres parameters           */

 erridErrorCode = WinGetLastError(hab);
    window->win = hwnd;

  window->hdc = WinOpenWindowDC(window->win);
  window->hpsBuffer = hpsCurrent;


 rect.xLeft = x;
 rect.xRight = x+width;
 rect.yBottom = y;
 rect.yTop = y + height;

/***** else parent *****************************/
  } else {
        hwnd = WinCreateStdWindow(HWND_DESKTOP,
           0,       /* WS_VISIBLE frame-window style        */
           &flStyle,        /* window style                 */
           "GLUT",          /* class name                   */
           "GLUT",/* window title                  */
            0L,                  /* default client style          */
            NULLHANDLE,          /* resource in executable file   */
            ID_WINDOW,           /* resource id                   */
            &hwndClient);        /* receives client window handle */

 erridErrorCode = WinGetLastError(hab);
       window->win = hwndClient;
       window->frame = hwnd;
  window->hdc = WinOpenWindowDC(window->win);

  window->hpsBuffer = hpsCurrent;


/* converts a client window's boundaries into  an equivalent frame rectangle */
 rect.xLeft = x;
 rect.xRight = x+width;
 rect.yBottom = y;
 rect.yTop = y + height;

 /* calculate equivalent frame boundary from boundary data */
  WinCalcFrameRect(window->frame, &rect, FALSE);
 }
/***** endof if(parent) *****************************/

  /* Must set the XHDC for fake glXChooseVisual & fake
     glXCreateContext & fake XAllocColorCells. */
  XHDC = window->hdc;
  XHWND = window->win;
  window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
    &window->visAlloced, &fbc);
    if (!window->vis)
    {   __glutFatalError(
        "pixel format with necessary capabilities not found.");
    }
    { int rc;
      rc = wglChoosePixelFormat(window->hdc, window->vis),

//     evglSetPixelFormat(2); /* int iPixelFormat 1 - doublebuffer/2 - single buffer ??*/
      wglSetPixelFormat(window->hdc,rc,window->vis);
    }
   __glutSetupColormap(window->vis, &window->colormap, &window->cmap);

  window->ctx = glXCreateContext(window->hpsBuffer, window->vis,
    None, __glutTryDirect);

  WinSetWindowPos(hwnd,
                  HWND_TOP,rect.xLeft,rect.yBottom,
                  rect.xRight-rect.xLeft, rect.yTop-rect.yBottom,
      SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW|SWP_ZORDER); /* flags*/

  /* Make sure subwindows get a windowStatus callback. */
  if (parent)
       WinPostMsg(parent->win, WM_ACTIVATE, 0, 0);

  }
}

#elif defined(_WIN32)

  __glutAdjustCoords(parent ? parent->win : NULL,
    &x, &y, &width, &height);
  if (parent) {
    style = WS_CHILD;
  } else {
    if (gameMode) {
      /* Game mode window should be a WS_POPUP window to
         ensure that the taskbar is hidden by it.  A standard
         WS_OVERLAPPEDWINDOW does not hide the task bar. */
      style = WS_POPUP | WS_MAXIMIZE;
    } else {
      /* A standard toplevel window with borders and such. */
      style = WS_OVERLAPPEDWINDOW;
    }
  }
  window->win = CreateWindow("GLUT", "GLUT",
    WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
    x, y, width, height, parent ? parent->win : __glutRoot,
    NULL, GetModuleHandle(NULL), 0);
  window->hdc = GetDC(window->win);
  /* Must set the XHDC for fake glXChooseVisual & fake
     glXCreateContext & fake XAllocColorCells. */
  XHDC = window->hdc;
  window->vis = __glutDetermineWindowVisual(&window->treatAsSingle,
    &window->visAlloced, &fbc);
  if (!window->vis) {
    __glutFatalError(
      "pixel format with necessary capabilities not found.");
  }
  if (!SetPixelFormat(window->hdc,
      ChoosePixelFormat(window->hdc, window->vis),
      window->vis)) {
    __glutFatalError("SetPixelFormat failed during window create.");
  }
  __glutSetupColormap(window->vis, &window->colormap, &window->cmap);
  /* Make sure subwindows get a windowStatus callback. */
  if (parent) {
    PostMessage(parent->win, WM_ACTIVATE, 0, 0);
  }
  window->renderDc = window->hdc;
#else
  window->win = XCreateWindow(__glutDisplay,
    parent == NULL ? __glutRoot : parent->win,
    x, y, width, height, 0,
    window->vis->depth, InputOutput, window->vis->visual,
    attribMask, &wa);
#endif
  window->renderWin = window->win;
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
  if (fbc) {
    window->ctx = __glut_glXCreateContextWithConfigSGIX(__glutDisplay, fbc,
      GLX_RGBA_TYPE_SGIX, None, __glutTryDirect);
  } else
#endif
#if defined(__OS2PM__)
//    window->ctx = glXCreateContext(window->hpsBuffer, window->vis,
//      None, __glutTryDirect);
#else
    window->ctx = glXCreateContext(__glutDisplay, window->vis,
      None, __glutTryDirect);
#endif
  if (!window->ctx) {
    __glutFatalError(
      "failed to create OpenGL rendering context.");
  }
  window->renderCtx = window->ctx;
#if !defined(_WIN32) && !defined(__OS2PM__)
  window->isDirect = glXIsDirect(__glutDisplay, window->ctx);
  if (__glutForceDirect) {
    if (!window->isDirect)
      __glutFatalError("direct rendering not possible.");
  }
#endif

  window->parent = parent;
  if (parent) {
    window->siblings = parent->children;
    parent->children = window;
  } else {
    window->siblings = NULL;
  }
  window->overlay = NULL;
  window->children = NULL;
  window->display = __glutDefaultDisplay;
  window->reshape = __glutDefaultReshape;
  window->mouse = NULL;
  window->motion = NULL;
  window->passive = NULL;
  window->entry = NULL;
  window->keyboard = NULL;
  window->keyboardUp = NULL;
  window->windowStatus = NULL;
  window->visibility = NULL;
  window->special = NULL;
  window->specialUp = NULL;
  window->buttonBox = NULL;
  window->dials = NULL;
  window->spaceMotion = NULL;
  window->spaceRotate = NULL;
  window->spaceButton = NULL;
  window->tabletMotion = NULL;
  window->tabletButton = NULL;
#ifdef _WIN32
  window->joystick = NULL;
  window->joyPollInterval = 0;
#endif

#if defined(__OS2PM__)
  window->wm_command = NULL;
#endif

  window->tabletPos[0] = -1;
  window->tabletPos[1] = -1;
#if defined(__OS2PM__)
  if(window->shownState == -1)
           window->shownState = 0;
   window->visState =  window->shownState;
#else
  window->shownState = 0;
  window->visState = -1;  /* not VisibilityUnobscured,
                             VisibilityPartiallyObscured, or
                             VisibilityFullyObscured */
#endif
  window->entryState = -1;  /* not EnterNotify or LeaveNotify */

  window->desiredConfMask = 0;
  window->buttonUses = 0;
  window->cursor = GLUT_CURSOR_INHERIT;

  /* Setup window to be mapped when glutMainLoop starts. */
  window->workMask = GLUT_MAP_WORK;
#ifdef _WIN32
  if (gameMode) {
    /* When mapping a game mode window, just show
       the window.  We have already created the game
       mode window with a maximize flag at creation
       time.  Doing a ShowWindow(window->win, SW_SHOWNORMAL)
       would be wrong for a game mode window since it
       would unmaximize the window. */
    window->desiredMapState = GameModeState;
  } else {
    window->desiredMapState = NormalState;
  }
#else
  window->desiredMapState = NormalState;
#endif
  window->prevWorkWin = __glutWindowWorkList;
  __glutWindowWorkList = window;

  /* Initially, no menus attached. */
  for (i = 0; i < GLUT_MAX_MENUS; i++) {
    window->menu[i] = 0;
  }

  /* Add this new window to the window list. */
  __glutWindowList[winnum] = window;

  /* Make the new window the current window. */
  __glutSetWindow(window);

  __glutDetermineMesaSwapHackSupport();

  if (window->treatAsSingle) {
    /* We do this because either the window really is single
       buffered (in which case this is redundant, but harmless,
       because this is the initial single-buffered context
       state); or we are treating a double buffered window as a
       single-buffered window because the system does not appear
       to export any suitable single- buffered visuals (in which
       the following are necessary). */
    glDrawBuffer(GL_FRONT);
    glReadBuffer(GL_FRONT);
  }
  return window;
}
Ejemplo n.º 6
0
void M_CWMenuFolder::wpclsInitData()
{
  somId mySomId;
  CLASSINFO ci;
  
  /* call parent */
  if((mySomId=somIdFromString("wpclsInitData"))!=NULLHANDLE) {
    ((somTD_M_WPObject_wpclsInitData)
     somParentNumResolve(__ClassObject->somGetPClsMtabs(),
                         1,
                         __ClassObject->
                         somGetMethodToken(mySomId))
     )(this);
    SOMFree(mySomId);
  }
  else
    M_WPFolder::wpclsInitData();

  if(!fInitDone) {
    /* Get install dir */
    queryInstallDir(chrInstallPath, sizeof(chrInstallPath));
    /* INI file path */
    queryIniFilePath(chrWPSWizIni, sizeof(chrWPSWizIni));

    /* Register new button class */
    if(WinQueryClassInfo(WinQueryAnchorBlock(HWND_DESKTOP),
                         (PSZ) WC_BUTTON,
                         &ci))
      {
        g_ulButtonDataOffset=ci.cbWindowData;
        g_pfnwpOrgButtonProc=ci.pfnWindowProc;
        
        ulQWP_WIZBUTTONDATA=g_ulButtonDataOffset;
        
        if (WinRegisterClass(WinQueryAnchorBlock(HWND_DESKTOP),
                             (PSZ) WC_WIZBUTTON,
                             fnwpWizButtonProc,
                             //  ci.pfnWindowProc, 
                             ci.flClassStyle&~CS_PUBLIC,
                             ci.cbWindowData + WIZBUTTON_DATASIZE))
          {
            /* */

          }
      }

    if(WinQueryClassInfo(WinQueryAnchorBlock(HWND_DESKTOP),
                         WC_STATIC,
                         &ci))
      {
        g_haveFlyOverClient=TRUE; /* Blended flyover window is only available if CWFolder is
                                     installed. */
      }
    
    /* Register percentbar class */
    if(!percentRegisterBarClass())
      SysWriteToTrapLog("Can't register percent bar window class.\n");
    
    /* Register REXX functions */
    RexxRegisterFunctionExe("WPSWizCallWPSFunc", (PFN)rxCallWPSFunc);
    RexxRegisterFunctionExe("WPSWizCallWinFunc", (PFN)rxCallPMFunc);
    RexxRegisterFunctionExe("WPSWizCallFunc", (PFN)rxCallCWWPSFunc);
    RexxRegisterFunctionExe("WPSWizCallWPSClsFunc", (PFN)rxCallWPSClassFunc);
    RexxRegisterFunctionExe("DevGetHash", (PFN)rxGetHash);
    /* Register the gadget REXX function */
    RexxRegisterFunctionExe("WPSWizGadgetFunc", (PFN)rxCallCWWPSFunc);
    RexxRegisterExitExe("WIZREXX", (PFN)cwRexxExitHandler, NULLHANDLE);

    /* Load Rexx error dialog */
    if(!g_hwndRexxError) {
      somTD_M_CWObject_wizclsSetRexxErrorWindowHWND methodPtr;

      g_hwndRexxError=WinLoadDlg(HWND_DESKTOP, HWND_DESKTOP, pfnwpRexxErrorProc, 
                                 queryModuleHandle(), IDDLG_REXXERROR, NULLHANDLE);

      TRY_LOUD(ERROR_HWND) {
        /* Make sure M_CWObject class is installed and replaces the normal M_WPObject
           class. If yes, the M_CWMenuFolder class has a new static method
           "wizclsSetRexxErrorWindowHWND". */
        methodPtr=(somTD_M_CWObject_wizclsSetRexxErrorWindowHWND)
          somResolveByName( this,
                          "wizclsSetRexxErrorWindowHWND");
        //   SysWriteToTrapLog("%s: %x\n", __FUNCTION__, methodPtr);
        if(methodPtr)
          methodPtr(this, g_hwndRexxError);
          }
      CATCH(ERROR_HWND)
        {
          SysWriteToTrapLog("%s: Error while setting REXX error window HWND.\n", __FUNCTION__);
        } END_CATCH;
        
    }
Ejemplo n.º 7
0
Archivo: kva_wo.c Proyecto: komh/kva
APIRET APIENTRY kvaWoInit( HWND hwnd, ULONG ulKeyColor, PKVAAPIS pkva )
{
    BOOL        fWOInited = FALSE;
    HWATTRIBUTE attr;
    int         i;
    CHAR        szClassName[ 80 ];
    CLASSINFO   ci;
    ULONG       rc;

    m_HWVideoHandle = NULLHANDLE;
    memset( &m_hwvc, 0, sizeof( HWVIDEOCAPS ));
    memset( &m_hwvs, 0, sizeof( HWVIDEOSETUP ));

    m_pfnwpOld = NULL;

    rc = KVAE_NO_ERROR;

    if( !LoadOverlay())
    {
        rc = KVAE_CANNOT_LOAD_WO;
        goto exit_error;
    }

    rc = m_pfnHWVIDEOInit();
    if( rc )
        goto exit_error;

    fWOInited = TRUE;

    // Query overlay capabilities
    m_hwvc.ulLength = sizeof( m_hwvc );

    // First time we need to call with zero value
    m_hwvc.ulNumColors = 0;
    m_hwvc.fccColorType = NULL;
    m_pfnHWVIDEOCaps( &m_hwvc );

    // this time hwvc.ulNumColors filled with actual count of supported FOURCCs
    // but need to check this
    if( m_hwvc.ulNumColors )
    {
        m_hwvc.fccColorType = malloc( m_hwvc.ulNumColors * sizeof( FOURCC ));
        m_pfnHWVIDEOCaps( &m_hwvc );
    }
    else
    {
        rc = KVAE_NO_SUPPORTED_FOURCC;
        goto exit_error;
    }

    if( m_hwvc.fccDstColor == FOURCC_LUT8 )
    {
        // WO doesn't supports palettized mode.
        rc = KVAE_WO_PALETTIZED_MODE;
        goto exit_error;
    }

    attr.ulLength = sizeof( HWATTRIBUTE );

    for( i = 0; i < m_hwvc.ulAttrCount; i++ )
    {
        m_pfnHWVIDEOGetAttrib( i, &attr );

        if( !strcmp( attr.szAttrDesc, ATTRIBUTE_BRIGHTNESS ))
            m_aulAttr[ KVAA_BRIGHTNESS ] = i;
        else if ( !strcmp( attr.szAttrDesc, ATTRIBUTE_CONTRAST ))
            m_aulAttr[ KVAA_CONTRAST ] = i;
        else if( !strcmp( attr.szAttrDesc, ATTRIBUTE_SATURATION ))
            m_aulAttr[ KVAA_SATURATION ] = i;
        else if( !strcmp( attr.szAttrDesc, ATTRIBUTE_HUE ))
            m_aulAttr[ KVAA_HUE ] = i;
    }

    m_hwndKVA = hwnd;
    m_hwvs.ulKeyColor = ulKeyColor;

    WinQueryClassName( m_hwndKVA, sizeof( szClassName ), szClassName );
    WinQueryClassInfo( WinQueryAnchorBlock( m_hwndKVA ), szClassName, &ci );

    if( !( ci.flClassStyle & CS_MOVENOTIFY ))
    {
        ci.flClassStyle |= CS_MOVENOTIFY;

        WinRegisterClass( WinQueryAnchorBlock( m_hwndKVA ),
                          szClassName,
                          ci.pfnWindowProc,
                          ci.flClassStyle,
                          ci.cbWindowData );
    }

    m_pfnwpOld = WinSubclassWindow( m_hwndKVA, woNewWindowProc );

    if( m_pfnwpOld )
    {
        pkva->pfnDone = woDone;
        pkva->pfnLockBuffer = woLockBuffer;
        pkva->pfnUnlockBuffer = woUnlockBuffer;
        pkva->pfnSetup = woSetup;
        pkva->pfnCaps = woCaps;
        pkva->pfnQueryAttr = woQueryAttr;
        pkva->pfnSetAttr = woSetAttr;
    }
    else
    {
        rc = KVAE_CANNOT_SUBCLASS;
        goto exit_error;
    }

    return KVAE_NO_ERROR;

exit_error :
    if( m_HWVideoHandle )
    {
        if( m_hwvc.fccColorType )
            free( m_hwvc.fccColorType );

        if( fWOInited )
            m_pfnHWVIDEOClose();

        DosFreeModule( m_HWVideoHandle );
    }

    return rc;
}