コード例 #1
0
//----------------------------------------------------------------------------
// NPP_SetWindow:
//----------------------------------------------------------------------------
NPError NP_LOADDS
NPP_SetWindow(NPP instance, NPWindow* window) {
  pprintf( szPPR, "NPP_SetWindow\n\r" );
  if ( instance == 0 ) return NPERR_INVALID_INSTANCE_ERROR;

  PluginInstance* This = (PluginInstance*) instance->pdata;

  //
  // *Developers*: Before setting fWindow to point to the
  // new window, you may wish to compare the new window
  // info to the previous window (if any) to note window
  // size changes, etc.
  //

  // if window handle changed
  if ( This->hWnd != (HWND)window->window ) {
    pprintf( szPPR, "HWND (hmf %x) changed, %x --> %x\n\r", This->hmf, (int)This->hWnd, (int)window->window );
    // remember the new window
    This->fWindow = window;
    if ( This->hWnd ) {
      // Remove the subclass for the old client window
      WinSubclassWindow(This->hWnd, This->lpfnOldWndProc);
    }
    // remember the new window handle
    This->hWnd = (HWND)This->fWindow->window;
    // subclass the window
    This->lpfnOldWndProc = WinSubclassWindow(This->hWnd, SubClassFunc);
    AssociateInstance( This->hWnd, This );
    /* paint a background for the drawing */
    WinQueryWindowRect( This->hWnd, &This->rclWnd );
//    WinFillRect( This->hps, &This->rclWnd, CLR_PALEGRAY );
    // destroy old PS and create new PS
    if ( This->hps ) GpiDestroyPS( This->hps );
    HDC hdc = WinQueryWindowDC( This->hWnd );
    if ( !hdc ) hdc = WinOpenWindowDC( This->hWnd );
    SIZEL siz={ 0, 0 };
    HAB hab=WinQueryAnchorBlock( This->hWnd );
    This->hps = GpiCreatePS( hab, hdc, &siz,
                                  PU_PELS | GPIT_NORMAL | GPIA_ASSOC );
    pprintf( szPPR, "GpiCreatePS, hdc=%x, hps=%x\n\r", (int)hdc, (int)This->hps );
    if ( !This->hps ) {
      pprintf( szPPR, "GpiCreatePS failed, Err=%x\n\r",
        WinGetLastError( hab ) );
    }
    SetTransform( This, This->hps, &This->rclWnd );
  } else { // check if window coordinates changed.
           //It may happens for full-screan
    RECTL rcl;
    WinQueryWindowRect( This->hWnd, &rcl );
    if ( memcmp( &This->rclWnd, &rcl, sizeof( rcl ) ) ) {
      pprintf( szPPR, "Rect (hmf %x) changed, ( %d, %d ) - ( %d, %d ) --> ( %d, %d ) - ( %d, %d )\n\r",
        This->hmf,
        This->rclWnd.xLeft, This->rclWnd.yBottom, This->rclWnd.xRight, This->rclWnd.yTop,
        rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop );
      memcpy( &This->rclWnd, &rcl, sizeof( rcl ) );
      SetTransform( This, This->hps, &This->rclWnd );
    }
  }
  return NPERR_NO_ERROR;
}
コード例 #2
0
/**************************************************************************
 *
 *  Name       : InitClientArea()
 *
 *  Description: Prepares the client area to accept the images
 *
 *  Concepts   : Called once by the Init() routine
 *               - obtain a window device context
 *               - define the image presentation space
 *               - associate the two
 *               - set foreground/background colours &
 *                 background mix for the presentation space
 *
 *  API's      :  WinOpenWindowDC
 *                GpiCreatePS
 *                GpiSetColor
 *                GpiSetBackColor
 *                GpiSetBackMix
 *
 *  Parameters :  hwnd = client window handle
 *
 *  Return     :  TRUE - client area successfully set up
 *                FALSE - client area setup failed
 *
 *************************************************************************/
BOOL InitClientArea(HWND hwnd)
{
   SIZEL  sizl;

   sizl.cx = 0L;                /* set size to default for device    */
   sizl.cy = 0L;                /*  (full screen)                    */

   vhdc = WinOpenWindowDC(hwnd);
   if (!vhdc)
       return FALSE;

   vhps = GpiCreatePS(vhab,
                      vhdc,
                      &sizl,
                      (ULONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC
                      );
   if (!vhps)
       return FALSE;

   GpiSetColor(vhps, vlForeClr);
   GpiSetBackColor(vhps, vlBackClr);
   GpiSetBackMix(vhps, BM_OVERPAINT);

   return TRUE;
}   /* End of InitClientArea */
コード例 #3
0
void SelectMetaFile( PluginInstance *This, HMF hmf ) {
  if ( This->hmf ) GpiDeleteMetaFile( This->hmf );
  This->hmf=hmf;
  HAB hab=WinQueryAnchorBlock( This->hWnd );
  HPS hps=This->hps;
  if ( !hps ) {
    pprintf( szPPR, "No hps ???\n\r" );
    return;
  }
  //calculate bounds
  HDC hdc = WinQueryWindowDC( This->hWnd );
  if ( !hdc ) hdc = WinOpenWindowDC( This->hWnd );
  GpiResetBoundaryData( hps );
  if ( GpiAssociate( hps, NULL ) ) {
    GpiSetDrawControl( hps, DCTL_BOUNDARY, DCTL_ON );
    Draw( This, hps, FALSE, FALSE );
    if ( GpiQueryBoundaryData( hps, &This->rclMeta ) && (This->rclMeta.xLeft<This->rclMeta.xRight) ) {
      if ( !GpiAssociate( hps, hdc ) ) pprintf( szPPR, "GpfAssociate( hps, hdc ) failed\n\r" );
      GpiSetDrawControl( hps, DCTL_BOUNDARY, DCTL_OFF );
      GpiResetPS( hps, GRES_ALL);
      SetTransform( This, hps, &This->rclWnd );
    } else {
      pprintf( szPPR, "GpiQueryBoundaryData failed, Err=%x\n\r",
        WinGetLastError( hab ) );
    }
  } else pprintf( szPPR, "GpfAssociate( hps, NULL ) failed\n\r" );
  // invalidate window to ensure a redraw
  WinInvalidateRect( This->hWnd, 0, TRUE );
}
コード例 #4
0
ファイル: video_gpi.c プロジェクト: BigBoss21X/vice-emu
void PM_mainloop(VOID *arg)
{
    SIZEL sizelHps = {0,0};
    HAB   hab;  // Anchor Block to PM
    HMQ   hmq;  // Handle to Msg Queue
    HDC   hdc;  // Handle to Device (Window-Screen)
    QMSG  qmsg; // Msg Queue Event
    video_canvas_t *ptr=(video_canvas_t*)arg;

    hab = WinInitialize(0);            // Initialize PM
    hmq = WinCreateMsgQueue(hab, 0);   // Create Msg Queue

    // 2048 Byte Memory (Used eg for the Anchor Blocks
    WinRegisterClass(hab, szClientClass, PM_winProc, CS_SIZEREDRAW, 2048);

    (*ptr)->hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
                                   WS_ANIMATE, &flFrameFlags,
                                   szClientClass, szTitleBarText, 0L, 0, 0,
                                   &((*ptr)->hwndClient));

    WinSetWindowPos((*ptr)->hwndFrame, HWND_TOP, 0, 0,
                    (*ptr)->width*stretch,
                    (*ptr)->height*stretch+
                    WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR), // +1 with gcc?
                    SWP_SIZE|SWP_SHOW|SWP_ZORDER|SWP_ACTIVATE);    // Make visible, resize, top window
    WinSetWindowPtr((*ptr)->hwndClient, QWL_USER, (VOID*)(*ptr));
    // --------------------
    // maybe ---> WM_CREATE
    // --------------------
    hdc         = WinOpenWindowDC((*ptr)->hwndFrame);
    (*ptr)->hps = GpiCreatePS(WinQueryAnchorBlock((*ptr)->hwndFrame),
                              hdc, &sizelHps,
                              PU_PELS|GPIF_DEFAULT|GPIT_MICRO|GPIA_ASSOC); // GPIT_NORMAL does also work with vac++

    (*ptr)->pbmi = lib_calloc(1, 16+sizeof(RGB2)*256);
    (*ptr)->pbmi->cbFix      = 16; // Size of cbFix, cPlanes, cBitCount = Begin of RGB2
    (*ptr)->pbmi->cPlanes    =  1;
    (*ptr)->pbmi->cBitCount  =  8; // Using 8-bit color mode
    (*ptr)->palette=(RGB2*)((ULONG)(*ptr)->pbmi+(*ptr)->pbmi->cbFix);

    vidlog("pbmiAllocated",0);
    (*ptr)->pbmi_initialized = TRUE;    // All stuff for pbmi created
    //    DosReleaseMutexSem(hmtx); // gfx init end
    //-----------------------
    
    while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
        WinDispatchMsg (hab, &qmsg) ;

    //    (*ptr)->pbmi_initialized = FALSE;
    DosRequestMutexSem(hmtx, SEM_INDEFINITE_WAIT);
    GpiDestroyPS((*ptr)->hps);
    WinDestroyWindow ((*ptr)->hwndFrame); // why was this commented out? --> WM_CLOSE ??
    WinDestroyMsgQueue(hmq);  // Destroy Msg Queue
    WinTerminate (hab);       // Release Anchor to PM
    lib_free((*ptr)->pbmi);   // is this the right moment to do this???
    //    lib_free(*ptr); // Vice crashes... why??? This must be done in the main thread!
    exit(0);                  // Kill VICE, All went OK
}
コード例 #5
0
/*
	SaverWindowProc
	This is the window procedure of the screen-size window that is
	created when the saver starts.
	There should be no reason to alter the code.
	Note that we do not process WM_PAINT messages. They are forwarded to
	the default window procedure, which just validates the window area
	and does no drawing. All drawing to the window should be done in
	the drawing-thread. Therefore, if you want to blank the screen before
	drawing on it for instance, issue a WinFillRect call at the beginning
	of your drawing-thread.
*/
MRESULT EXPENTRY SaverWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
	static	SIZEL	pagesize={0, 0};
	switch(msg){
	case WM_CREATE:
		// reset the "stop" flag
		stop_draw_thread = FALSE;
		// store window handle
		hwndSaver = hwnd;
		// get hdc and create normal presentation space
		hdc = WinOpenWindowDC (hwnd);
		hps = GpiCreatePS (hab, hdc, &pagesize, GPIA_ASSOC|PU_PELS|GPIT_NORMAL);
		// start the drawing-thread
		tidDraw = _beginthread(draw_thread, NULL, STACKSIZE, NULL);
		// create thread to control priority of drawing thread
		if(low_priority){
			stop_priority_thread = FALSE;
			DosCreateThread(&tidPriority, (PFNTHREAD)priority_thread, 0, 2L, 1000);
		}
		// create timer that moves the saver window to top regularly
		WinStartTimer(hab, hwndSaver, IDT_ZORDERTIMER, ZORDERTIMERSTEP);
		return (MRESULT)FALSE;
	case WM_TIMER:
		if(SHORT1FROMMP(mp1) == IDT_ZORDERTIMER){
			// move saver window to top
			WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
			return (MRESULT)0;
		}
		break;
	case WM_DESTROY:
		// destroy the presentation space
		GpiDestroyPS(hps);
		// stop the z-order timer
		WinStopTimer(hab, hwndSaver, IDT_ZORDERTIMER);
		break;
	case WM_PAINT:
		// just validate the update area. all drawing is done
		// in the drawing-thread.
		return WinDefWindowProc(hwnd, msg, mp1, mp2);
	}
	return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
コード例 #6
0
ファイル: wndproc.c プロジェクト: NicoleRauch/BermudaTriangle
/****************************************************************\
 *
 *--------------------------------------------------------------
 *  Name:ClkCreate()
 *
 *  Purpose:Intialize a newly created client window
 *
 *  Returns:
 *	    1 - if sucessful execution completed
 *	    0 - if error
\****************************************************************/
VOID ClkCreate ( HWND hwnd )
{
    LONG cxScreen , cyScreen;  /* screen dimensions */
    LONG xLeft , yBottom ;	/* frame window location */
    ULONG cbBuf;
    LONG cyHeight;
    LONG cxWidth;

//    hwndClient = hwnd;

// extern SIZEL sizl;   clkdata.h
// SIZEL sizl = { 200 , 200 }; clkdata.c


    /* determine screen dimensions */
    /* open a device context and create a presentation space */

    hdc = WinOpenWindowDC (hwnd);
    hps = GpiCreatePS (hab, hdc, &sizl, PU_ARBITRARY | GPIT_MICRO |
	    GPIA_ASSOC);

    /*
     * Create our off-screen 'buffer'.
     */
    hdcBuffer = DevOpenDC ( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdc);
    hpsBuffer = GpiCreatePS (hab, hdcBuffer, &sizl, PU_ARBITRARY |
			       GPIT_MICRO | GPIA_ASSOC);

    GpiCreateLogColorTable (hpsBuffer, 0, LCOLF_RGB, 0, 0, (PLONG)NULL);

// ULONG cxRes , cyRes; clkdata.c
// ULONG cColorPlanes, cColorBitcount; clkdata.c


    /* get the device resolutions so we can make the face appear circular */
    DevQueryCaps (hdc, (LONG)CAPS_VERTICAL_RESOLUTION,(LONG) 1L, &cyRes);
    DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &cxRes);
    DevQueryCaps (hdc, CAPS_COLOR_PLANES, 1L, &cColorPlanes);
    DevQueryCaps (hdc, CAPS_COLOR_BITCOUNT, 1L, &cColorBitcount);

}
コード例 #7
0
ファイル: pmgame.cpp プロジェクト: kidaa/BermudaTriangle
// initializes the window PS and the off-screen buffer
VOID InitPS( const HWND hwnd )
{
    SIZEL g = { 0, 0 };

    /* we are called before the global hwndFrame is valid */
    hwndFrame = WinQueryWindow ( hwnd , QW_PARENT) ;
    wcprintf("Muell: %x", WinGetLastError( hab ) );
    hdcGlob = WinOpenWindowDC( hwnd );
    hpsGlob = GpiCreatePS( hab, hdcGlob, &g, PU_ARBITRARY | GPIT_MICRO |
			   GPIA_ASSOC );
    /*
     * Create our off-screen 'buffer'.
     */
    // hdcGlob als letzten Parameter ist neu:
    hdcBufferGlob = DevOpenDC( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdcGlob );
    hpsBufferGlob = GpiCreatePS( hab, hdcBufferGlob, &g, PU_ARBITRARY |
				 GPIT_MICRO | GPIA_ASSOC );

    /* get the device resolutions  */
    DevQueryCaps( hdcGlob, CAPS_COLOR_PLANES, 1L, &cColorPlanes );
    DevQueryCaps( hdcGlob, CAPS_COLOR_BITCOUNT, 1L, &cColorBitCount );
}
// ------------------------------------------------------------------------------------------------------------
MRESULT EXPENTRY ClientWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
  BOOL                fOK;
  RECTL               rectl;
  SIZEL               sizel;
  HPS                 hps;

  switch( msg ) {
  case WM_CLOSE:
    globals.fCloseMsgSent = TRUE;
    WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
    WinPostMsg( globals.hwndObject, WM_QUIT, 0, 0 );
    return 0;
  case WM_COMMAND:
    switch( SHORT1FROMMP( mp1 )) {
    case ID_RUN:
      WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
      WinInvalidateRect( hwnd, NULL, FALSE );
      WinPostMsg( globals.hwndObject, WM_USER_START_REXX, (MPARAM)hwnd, 0 );
      break;
    }
    return 0;
  case WM_CREATE:
    // disable client window until application initializes
    WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
    globals.hwndFrame    = WinQueryWindow( hwnd, QW_PARENT );
    globals.hwndTitlebar = WinWindowFromID( globals.hwndFrame, FID_TITLEBAR );
    globals.hwndMenubar  = WinWindowFromID( globals.hwndFrame, FID_MENU );
    // create title bar text; set into title bar
    sprintf( globals.szCaption, "%s - %s", CAPTION, globals.szRexxFileName );
    WinSetWindowText( globals.hwndTitlebar, globals.szCaption );
    // get window DC
    globals.hdcScreen = WinOpenWindowDC( hwnd );
    assert( globals.hdcScreen );
    // create a normal PS for the screen; coordinate system is 1/100 inch per unit of measure
    sizel.cx = sizel.cy = 0;
    globals.hpsScreen = GpiCreatePS( globals.hab, globals.hdcScreen, &sizel, PU_LOENGLISH | GPIF_LONG | GPIT_NORMAL | GPIA_ASSOC );
    assert( globals.hpsScreen );
    // object window operates on thread 2
    globals.tidObject = _beginthread( threadmain, NULL, LEN_STACK, NULL );
    assert( globals.tidObject );
    return 0;
  case WM_MOUSEMOVE:
    WinSetPointer( HWND_DESKTOP, WinQuerySysPointer( HWND_DESKTOP, globals.fBusy ? SPTR_WAIT:SPTR_ARROW, FALSE ));
    return (MRESULT)1;
  case WM_PAINT:
    hps = WinBeginPaint( hwnd, globals.hpsScreen, &rectl );
    fOK = WinFillRect( hps, &rectl, SYSCLR_WINDOW );
    assert( fOK );
    if( !globals.fBusy ) {
      // playback the retained GPI drawing orders
      GpiDrawChain( globals.hpsScreen );
    }
    WinEndPaint( hps );
    return 0;
  case WM_USER_ACK:
    // object window has posted ack; re-enable the window
    WinSendMsg( hwnd, WM_USER_ENABLE_CLIENT, 0, 0 );
    return 0;
  case WM_USER_DISABLE_CLIENT:
    globals.fBusy = TRUE;
    WinEnableWindow( globals.hwndClient, FALSE );
    WinEnableMenuItem( globals.hwndMenubar, ID_RUN, FALSE );
    return 0;
  case WM_USER_ENABLE_CLIENT:
    globals.fBusy = FALSE;
    WinEnableWindow( globals.hwndClient, TRUE );
    WinEnableMenuItem( globals.hwndMenubar, ID_RUN, TRUE );
    return 0;
  }
  return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
コード例 #9
0
static MRESULT APIENTRY Create ( HWND Window, MESG, MPARAM1 mp1, MPARAM2 ) {

  /**************************************************************************
   * Allocate instance data.                                                *
   **************************************************************************/

   PDATA Data = PDATA ( malloc ( sizeof(DATA) ) ) ;

   if ( Data == NULL ) {
      Log ( "ERROR: Unable to allocate instance memory for horizontal ruler." ) ;
      return ( MRFROMSHORT ( 1 ) ) ;
   } /* endif */

   Sys_SetWindowData ( Window, Data ) ;

  /**************************************************************************
   * Grab any parameters from the WM_CREATE message.                        *
   **************************************************************************/

   PHORZRULER_PARMS Parms = PHORZRULER_PARMS ( PVOIDFROMMP ( mp1 ) ) ;

   Data->IniData = Parms->IniData ;
   Data->MainWindow = Parms->MainWindow ;

  /**************************************************************************
   * Create the device context object for the window.                       *
   **************************************************************************/

   WinOpenWindowDC ( Window ) ;
   Data->pDevice = new DeviceContext ( "HRuler", Window ) ;

  /**************************************************************************
   * Load the pointers.                                                     *
   **************************************************************************/

   Data->MarginPtr = WinLoadPointer ( HWND_DESKTOP, 0, ID_MARGIN ) ;
   Data->TabstopPtr = WinLoadPointer ( HWND_DESKTOP, 0, ID_TABSTOP ) ;

  /**************************************************************************
   * Perform all other instance initializations.                            *
   **************************************************************************/

   Data->Metric = FALSE ;
   Data->fxZoom = MAKEFIXED ( 1, 0 ) ;
   Data->PageWidth = 9000 ;
   Data->TopLeft = 9000 ;
   Data->LeftMargin = 0 ;
   Data->RightMargin = 9000 ;
   Data->TabCount = 0 ;
   memset ( Data->Tabs, 0, sizeof(Data->Tabs) ) ;
   Data->Tick = 0 ;
   Data->Capture = FALSE ;
   Data->Mode = NOTMOVING ;
   Data->SettingFont = FALSE ;

  /**************************************************************************
   * Success?  Return no error.                                             *
   **************************************************************************/

   return ( MRFROMSHORT ( 0 ) ) ;
}
コード例 #10
0
ファイル: winstall.c プロジェクト: OS2World/APP-COMM-ComScope
BOOL CreatePS(HWND hwnd)
  {
  HPS hps;
  int iIndex;
  LONG lWidth;
  LONG lBiggest;
  LONG lFontCount;
  PFONTMETRICS pfmFonts;
  int iBigFont;

  hdcPs = WinOpenWindowDC(hwnd);
  hps = WinGetPS(hwnd);

  lFontCount = 0;
  lFontCount = GpiQueryFonts(hps,
                         QF_PUBLIC,
                         "Helv",
                         &lFontCount,
                         sizeof(FONTMETRICS),
                         NULL);
  if (lFontCount > 0)
    {
    DosAllocMem((PVOID)&pfmFonts,(lFontCount * sizeof(FONTMETRICS)),(PAG_COMMIT | PAG_READ| PAG_WRITE));
    lBiggest = GpiQueryFonts(hps,
                           QF_PUBLIC,
                           "Helv",
                           &lFontCount,
                           sizeof(FONTMETRICS),
                           pfmFonts);

    lBiggest = 0;
    for (iIndex = 0;iIndex < lFontCount;iIndex++)
      {
      lWidth = pfmFonts[iIndex].lAveCharWidth;
      if (lWidth > lBiggest)
        {
        lBiggest = lWidth;
        iBigFont = iIndex;
        }
      }

    fattBigFont.usRecordLength = sizeof(FATTRS);
    fattBigFont.fsSelection = 0;
    fattBigFont.lMatch = pfmFonts[iBigFont].lMatch;
    strcpy(fattBigFont.szFacename,pfmFonts[iBigFont].szFacename);
    fattBigFont.idRegistry = pfmFonts[iBigFont].idRegistry;
    fattBigFont.usCodePage = pfmFonts[iBigFont].usCodePage;
    fattBigFont.lMaxBaselineExt = pfmFonts[iBigFont].lMaxBaselineExt;
    fattBigFont.lAveCharWidth = pfmFonts[iBigFont].lAveCharWidth;
    fattBigFont.fsType = 0;
    fattBigFont.fsFontUse = FATTR_FONTUSE_NOMIX;
    stBigCell.cx = pfmFonts[iBigFont].lAveCharWidth;
    stBigCell.cy = pfmFonts[iBigFont].lXHeight;
    DosFreeMem(pfmFonts);
    }

  lFontCount = 0;
  lFontCount = GpiQueryFonts(hps,
                         QF_PUBLIC,
                         "System VIO",
                         &lFontCount,
                         sizeof(FONTMETRICS),
                         NULL);
  if (lFontCount > 0)
    {
    DosAllocMem((PVOID)&pfmFonts,(lFontCount * sizeof(FONTMETRICS)),(PAG_COMMIT | PAG_READ| PAG_WRITE));
    lBiggest = GpiQueryFonts(hps,
                           QF_PUBLIC,
                           "System VIO",
                           &lFontCount,
                           sizeof(FONTMETRICS),
                           pfmFonts);

    for (iIndex = 0;iIndex < lFontCount;iIndex++)
      if (pfmFonts[iIndex].lAveCharWidth == 8)
        break;
    if (iIndex >= lFontCount)
      iIndex = 0;
    fattMsgFont.usRecordLength = sizeof(FATTRS);
    fattMsgFont.fsSelection = 0;
    fattMsgFont.lMatch = pfmFonts[iIndex].lMatch;
    strcpy(fattMsgFont.szFacename,pfmFonts[iIndex].szFacename);
    fattMsgFont.idRegistry = pfmFonts[iIndex].idRegistry;
    fattMsgFont.usCodePage = pfmFonts[iIndex].usCodePage;
    fattMsgFont.lMaxBaselineExt = pfmFonts[iIndex].lMaxBaselineExt;
    fattMsgFont.lAveCharWidth = pfmFonts[iIndex].lAveCharWidth;
    fattMsgFont.fsType = 0;
    fattMsgFont.fsFontUse = FATTR_FONTUSE_NOMIX;
    stMsgCell.cx = pfmFonts[iIndex].lAveCharWidth;
    stMsgCell.cy = pfmFonts[iIndex].lXHeight;
    DosFreeMem(pfmFonts);
    }
  else
    {
    // this stuff is here because OS/2 version 2.0 does not have System VIO fonts
    lFontCount = 0;
    lFontCount = GpiQueryFonts(hps,
                         QF_PUBLIC,
                         "System Monospaced",
                         &lFontCount,
                         sizeof(FONTMETRICS),
                         NULL);
    if (lFontCount > 0)
      {
      DosAllocMem((PVOID)&pfmFonts,(lFontCount * sizeof(FONTMETRICS)),(PAG_COMMIT | PAG_READ| PAG_WRITE));
      lBiggest = GpiQueryFonts(hps,
                             QF_PUBLIC,
                             "System Monospaced",
                             &lFontCount,
                             sizeof(FONTMETRICS),
                             pfmFonts);

      for (iIndex = 0;iIndex < lFontCount;iIndex++)
        if (pfmFonts[iIndex].lAveCharWidth == 10)
          break;
      if (iIndex >= lFontCount)
        iIndex = 0;
      fattMsgFont.usRecordLength = sizeof(FATTRS);
      fattMsgFont.fsSelection = 0;
      fattMsgFont.lMatch = pfmFonts[iIndex].lMatch;
      strcpy(fattMsgFont.szFacename,pfmFonts[iIndex].szFacename);
      fattMsgFont.idRegistry = pfmFonts[iIndex].idRegistry;
      fattMsgFont.usCodePage = pfmFonts[iIndex].usCodePage;
      fattMsgFont.lMaxBaselineExt = pfmFonts[iIndex].lMaxBaselineExt;
      fattMsgFont.lAveCharWidth = pfmFonts[iIndex].lAveCharWidth;
      fattMsgFont.fsType = 0;
      fattMsgFont.fsFontUse = FATTR_FONTUSE_NOMIX;
      stMsgCell.cx = pfmFonts[iIndex].lAveCharWidth;
      stMsgCell.cy = pfmFonts[iIndex].lXHeight;
      DosFreeMem(pfmFonts);
      }
    }
  WinReleasePS(hps);
  return(TRUE);
  }
コード例 #11
0
ファイル: glut_win.cpp プロジェクト: astrofimov/vgallium
/* 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;
}
MRESULT EXPENTRY miscMainWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
static HPS hpsMain;
static ULONG lCodePage;
static LONG lFontHeight, lAveWidth;
static LONG desk_cx, desk_cy;
    RECTL rectl;
    HWND hwndEditorWin, hwndEditorClient;
    ULONG flCreate;
    FONTDLG fontDlg;
    char szFamilyname[FACESIZE];
    char szExmpl[128];
    ULONG stringID[NUM_MAINTEXT] = {IDS_MAINTEXT1, IDS_MAINTEXT2,
                                    IDS_MAINTEXT3 };
    static char* sText=NULL;
    static char* sTextEnjoy;
    void setFont( HWND hwnd, HPS hps, PFATTRS pAttrs );

    switch(msg)
    {
        case WM_CREATE:
        {
        int i;
        SIZEL sizl;
        HDC hdc;
        HWND hwndFrame;
        ULONG dataLength;
        char buf[BUFSIZ];
        LONG x,y,cx,cy;

            /* Read message text */
            for (i = 0; i < NUM_MAINTEXT; i++)
            {
              WinLoadString( hab, NULLHANDLE,
                             stringID[i], sizeof(buf), buf );
              if( sText == NULL )
              {
                 sText = malloc(strlen(buf)+1);
                 *sText = '\0';
              }
              else
                 sText = realloc( sText, strlen(sText)+strlen(buf)+1 );

              strcat( sText, buf );
            }

            WinLoadString( hab, NULLHANDLE,
                           IDS_TEXTENJOY, sizeof(buf), buf );

            sTextEnjoy = malloc( strlen(buf)+1 );
            strcpy( sTextEnjoy, buf );

            sizl.cx = 0L;
            sizl.cy = 0L;

            hdc = WinOpenWindowDC( hwnd );
            hpsMain = GpiCreatePS( hab,
                                   hdc,
                                   (PSIZEL)&sizl,
                                   (ULONG)PU_PELS | GPIT_MICRO | GPIA_ASSOC
                                  );
            /* Query the environment */
            DosQueryCp( sizeof(lCodePage), &lCodePage, &dataLength );

            GetFontSize( hpsMain, &lAveWidth, &lFontHeight );

            hwndFrame = WinQueryWindow(hwnd, QW_PARENT);

            desk_cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
            desk_cy = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );

            /* set window width to show maximum 40 SBCS characters */
            cx = (lAveWidth*MAIN_WIN_WIDTH>desk_cx) ? desk_cx : lAveWidth*MAIN_WIN_WIDTH;
            /* set window height large enough to show a string pointed to by sText.*/
            cy = (((strlen(sText)/MAIN_WIN_WIDTH)+10)*lFontHeight>desk_cy) ?
                  desk_cy : ((strlen(sText)/40) + 10)*lFontHeight;

            x = (cx<desk_cx) ? (desk_cx-cx)/2 : 0;
            y = (cy<desk_cy) ? (desk_cy-cy)/2 : 0;
            WinSetWindowPos(hwndFrame,
                            HWND_BOTTOM,
                            x, y, cx, cy,
                            SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);

            return(MRESULT)(FALSE);
        }

        case WM_COMMAND:
            switch (SHORT1FROMMP(mp1))
            {
                case MID_CONV:    /* CPCONV */
                {
                  WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) cpConvDlgProc,
                            NULLHANDLE, DID_CONV, &lCodePage);
                  break;
                }

                case MID_EDITOR:  /* Simple Editor */
                  flCreate= FCF_SIZEBORDER | FCF_MENU | FCF_MAXBUTTON | FCF_MINBUTTON
                          | FCF_SYSMENU | FCF_TITLEBAR | FCF_DBE_APPSTAT;
                  hwndEditorWin = WinCreateStdWindow(HWND_DESKTOP,
                                                    WS_VISIBLE,
                                                    &flCreate,
                                                    "editorWindow",
                                                    "Simple Editor",
                                                    0L,
                                                    NULLHANDLE,
                                                    WID_EDITOR,
                                                    (PHWND) & hwndEditorClient);

                  WinSetWindowPos(hwndEditorWin,
                                  HWND_BOTTOM,
                                  190, 130, 500, 300,
                                  SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);
                  break;

                case MID_WORD:    /* Word Break */
                {
                  WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) wordDlgProc,
                            NULLHANDLE, DID_WORD, &lCodePage);
                  break;
                }

                case MID_EXIT:    /* Exit */
                  WinSendMsg (hwnd, WM_CLOSE,mp1,mp2);
                  break;
            }
            break;

        case WM_PAINT:
        {
         int i;
         LONG lTotLen, lWrittenLen, lDrawn;
         SWP swp;

            WinBeginPaint( hwnd, hpsMain, (PRECTL)&rectl );
            /* Always update whole window - CS_SIZEREDRAW? */
            WinQueryWindowPos( hwnd, &swp );
            rectl.xLeft = rectl.yBottom = 0;
            rectl.xRight = swp.cx;
            rectl.yTop = swp.cy;

            WinFillRect( hpsMain, (PRECTL) &rectl, CLR_BACKGROUND );

            lTotLen = (LONG)strlen(sText);

            /* make some space between the text and the frame window */
            rectl.xLeft+=lAveWidth;
            rectl.xRight-=lAveWidth;
            rectl.yTop-=lFontHeight;

            for (lWrittenLen = 0; lWrittenLen != lTotLen; rectl.yTop -= lFontHeight)
            {
              lDrawn = WinDrawText( hpsMain, lTotLen - lWrittenLen,
                                    sText+lWrittenLen, &rectl, 0L, 0L,
                                    DT_WORDBREAK | DT_TOP | DT_LEFT | DT_TEXTATTRS);

              if( lDrawn != 0 )
                lWrittenLen  += lDrawn;
              else
                break;
            }

            rectl.yTop -= lFontHeight;
            WinDrawText( hpsMain, strlen(sTextEnjoy), sTextEnjoy, &rectl,
                         CLR_RED, CLR_BACKGROUND,
                         DT_TOP | DT_CENTER );
            WinEndPaint( hpsMain );
            break;
        }

        case WM_DESTROY:
            GpiDestroyPS( hpsMain );
            break;

        default:
            return(WinDefWindowProc(hwnd,msg,mp1,mp2));
    }
  return(MRFROMLONG(NULL));
}
コード例 #13
0
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static DATETIME   dtPrevious ;
     static HDC        hdc ;
     static LONG       xPixelsPerMeter, yPixelsPerMeter ;
     static POINTL     aptlHour   [5] = { 0,-15, 10,0, 0,60, -10,0, 0,-15 },
                       aptlMinute [5] = { 0,-20,  5,0, 0,80,  -5,0, 0,-20 },
                       aptlSecond [2] = { 0,  0,  0,80 } ;
     static WINDOWINFO wi ;
     DATETIME          dt ;
     HPS               hps ;
     INT               iDiamMM, iAngle ;
     POINTL            aptl [3] ;

     switch (msg)
          {
          case WM_CREATE:
               hdc = WinOpenWindowDC (hwnd) ;

               DevQueryCaps (hdc, CAPS_VERTICAL_RESOLUTION,
                                  1L, &yPixelsPerMeter) ;
               DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION,
                                  1L, &xPixelsPerMeter) ;

               DosGetDateTime (&dtPrevious) ;
               dtPrevious.hours = (dtPrevious.hours * 5) % 60 +
                                   dtPrevious.minutes / 12 ;
               return 0 ;

          case WM_SIZE:
               wi.cxClient = SHORT1FROMMP (mp2) ;
               wi.cyClient = SHORT2FROMMP (mp2) ;

               iDiamMM = min (wi.cxClient * 1000L / xPixelsPerMeter,
                              wi.cyClient * 1000L / yPixelsPerMeter) ;

               wi.cxPixelDiam = xPixelsPerMeter * iDiamMM / 1000 ;
               wi.cyPixelDiam = yPixelsPerMeter * iDiamMM / 1000 ;
               return 0 ;

          case WM_TIMER:
               DosGetDateTime (&dt) ;
               dt.hours = (dt.hours * 5) % 60 + dt.minutes / 12 ;

               hps = WinGetPS (hwnd) ;
               GpiSetColor (hps, CLR_BACKGROUND) ;

               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               if (dt.hours   != dtPrevious.hours ||
                   dt.minutes != dtPrevious.minutes)
                    {
                    DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
                    DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
                    }

               GpiSetColor (hps, CLR_NEUTRAL) ;

               DrawHand (hps, aptlHour,   5, dt.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dt.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dt.seconds, &wi) ;

               WinReleasePS (hps) ;
               dtPrevious = dt ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;
               GpiErase (hps) ;

               for (iAngle = 0 ; iAngle < 60 ; iAngle++)
                    {
                    aptl[0].x = 0 ;
                    aptl[0].y = 90 ;

                    RotatePoint    (aptl, 1, iAngle) ;
                    ScalePoint     (aptl, 1, &wi) ;
                    TranslatePoint (aptl, 1, &wi) ;

                    aptl[2].x = aptl[2].y = iAngle % 5 ? 2 : 10 ;

                    ScalePoint (aptl + 2, 1, &wi) ;

                    aptl[0].x -= aptl[2].x / 2 ;
                    aptl[0].y -= aptl[2].y / 2 ;

                    aptl[1].x = aptl[0].x + aptl[2].x ;
                    aptl[1].y = aptl[0].y + aptl[2].y ;

                    GpiMove (hps, aptl) ;
                    GpiBox (hps, DRO_OUTLINEFILL, aptl + 1,
                                 aptl[2].x, aptl[2].y) ;
                    }
               DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
コード例 #14
0
ファイル: column.c プロジェクト: OS2World/APP-COMM-ComScope
MRESULT EXPENTRY fnwpReadColumnClient(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
  {
  static HDC hdcPs;
  RECTL   rclRect;
  POINTL ptl;
  LONG lSaveEdge;
  SWP swp;
  HWND hwndMenu;
  static USHORT usMenuStyle;
  static CLRDLG stColor;
  static USHORT usLastPopupItem;

  switch(msg)
    {
    case WM_CHAR:
      if (bSendNextKeystroke)
        if (ProcessKeystroke(&stCFG,mp1,mp2))
          return((MRESULT)TRUE);
      return( WinDefWindowProc(hwnd,msg,mp1,mp2));
    case WM_CREATE:
      hdcPs = WinOpenWindowDC(hwnd);
      usLastPopupItem = IDMPU_SYNC;
      stRead.lBackgrndColor = stCFG.lReadColBackgrndColor;
      stRead.bActive = FALSE;
      stRead.lScrollIndex = 0;
      stRead.hwndScroll = (HWND)NULL;
      stRead.wDirection = CS_READ;
      stColor.cbSize = sizeof(CLRDLG);
      usMenuStyle = (PU_POSITIONONITEM | PU_MOUSEBUTTON2 | PU_HCONSTRAIN | PU_VCONSTRAIN | PU_KEYBOARD | PU_MOUSEBUTTON1);
      WinSendMsg(hwnd,UM_TRACKFRAME,0L,0L);
      break;
    case WM_ACTIVATE:
      if(SHORT1FROMMP(mp1))
        {
        if (!bFrameActivated)
          {
          WinSetFocus(HWND_DESKTOP,hwndFrame);
          WinSendMsg(WinQueryHelpInstance(hwndClient),HM_SET_ACTIVE_WINDOW,0L,0L);
          bFrameActivated = TRUE;
          }
        }
      else
        bFrameActivated = FALSE;
      break;
    case WM_VSCROLL:
      switch(HIUSHORT(mp2))
        {
        case SB_LINEDOWN:
          ColScroll(&stRead,1,FALSE);
          break;
        case SB_LINEUP:
          ColScroll(&stRead,-1,FALSE);
          break;
        case SB_PAGEDOWN:
          ColScroll(&stRead,stRead.lCharHeight,FALSE);
          break;
        case SB_PAGEUP:
          ColScroll(&stRead,-stRead.lCharHeight,FALSE);
          break;
        case SB_SLIDERPOSITION:
          ColScroll(&stRead,LOUSHORT(mp2),TRUE);
          break;
        }
      break;
    case WM_COMMAND:
      switch (SHORT1FROMMP(mp1))
        {
        case IDMPU_ASCII_FONT:
          if (!stCFG.bStickyMenus)
            usLastPopupItem = IDMPU_FONT;
          else
            usLastPopupItem = IDMPU_SYNC;
          if (stCFG.wColReadFont != wASCIIfont)
            {
            stCFG.wColReadFont = wASCIIfont;
            WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE);
            }
          break;
        case IDMPU_HEX_FONT:
          if (!stCFG.bStickyMenus)
            usLastPopupItem = IDMPU_FONT;
          else
            usLastPopupItem = IDMPU_SYNC;
          if (stCFG.wColReadFont != wHEXfont)
            {
            stCFG.wColReadFont = wHEXfont;
            WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE);
            }
          break;
        case IDMPU_SYNC:
          usLastPopupItem = IDMPU_SYNC;
          if (bStopDisplayThread)
            stRead.lScrollIndex = stWrite.lScrollIndex;
          else
            stRead.lScrollIndex = 0;
          stRead.lScrollRow = GetColScrollRow(&stRead,0);
          WinSendMsg(stRead.hwndScroll,
                     SBM_SETPOS,
                     MPFROMSHORT(stRead.lScrollRow),
                     MPFROMSHORT(0));
          if (stRead.bSync)
            {
            stRow.lScrollIndex = stRead.lScrollIndex;
            stRow.lScrollRow = GetRowScrollRow(&stRow);
            }
          WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE);
          break;
         case IDMPU_COLORS:
          if (!stCFG.bStickyMenus)
            usLastPopupItem = IDMPU_COLORS;
          else
            usLastPopupItem = IDMPU_SYNC;
          stColor.lForeground = stCFG.lReadColForegrndColor;
          stColor.lBackground = stCFG.lReadColBackgrndColor;
          sprintf(stColor.szCaption,"Lexical Receive Data Display Colors");
          if (WinDlgBox(HWND_DESKTOP,
                        hwnd,
                 (PFNWP)fnwpSetColorDlg,
                (USHORT)NULL,
                        CLR_DLG,
                MPFROMP(&stColor)))
            {
            stCFG.lReadColForegrndColor = stColor.lForeground;
            stCFG.lReadColBackgrndColor = stColor.lBackground;
            stRead.lBackgrndColor = stColor.lBackground;
            stRead.lForegrndColor = stColor.lForeground;
            WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE);
            }
          break;
        case IDMPU_LOCK_WIDTH:
          if (!stCFG.bStickyMenus)
            usLastPopupItem = IDMPU_LOCK_WIDTH;
          else
            usLastPopupItem = IDMPU_SYNC;
          if (stCFG.fLockWidth == LOCK_READ)
            stCFG.fLockWidth = LOCK_NONE;
          else
            {
            stCFG.lLockWidth = ((stRead.lWidth / stCell.cx) + 1);
            stCFG.fLockWidth = LOCK_READ;
            }
          break;
        case IDMPU_DISP_FILTERS:
          if (!stCFG.bStickyMenus)
            usLastPopupItem = IDMPU_DISP_FILTERS;
          else
            usLastPopupItem = IDMPU_SYNC;
          if (WinDlgBox(HWND_DESKTOP,
                        hwnd,
                 (PFNWP)fnwpDisplaySetupDlgProc,
                (USHORT)NULL,
                        DISP_FILTER_DLG,
                MPFROMP(&stRead)))
            {
            stCFG.bReadTestNewLine = stRead.bTestNewLine;
            stCFG.bSkipReadBlankLines = stRead.bSkipBlankLines;
            stCFG.byReadNewLineChar = stRead.byNewLineChar;
            stCFG.bFilterRead = stRead.bFilter;
            stCFG.fFilterReadMask = stRead.fFilterMask;
            stCFG.byReadMask = stRead.byDisplayMask;
            if (stRead.bSync)
              {
              if (!stCFG.bSyncToRead)
                {
                stWrite.bSync = FALSE;
                stCFG.bSyncToWrite = FALSE;
                stCFG.bSyncToRead = TRUE;
                if (stCFG.fDisplaying & (DISP_DATA | DISP_FILE))
                  {
                  ClearColScrollBar(&stWrite);
                  SetupColScrolling(&stRead);
                  }
                }
              }
            else
              {
              if (stCFG.bSyncToRead)
                {
                stCFG.bSyncToRead = FALSE;
                if (stCFG.fDisplaying & (DISP_DATA | DISP_FILE))
                  SetupColScrolling(&stWrite);
                }
              }
            WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE);
            }
          break;
        }
      break;
//    case WM_CHORD:
    case WM_BUTTON2DOWN:
      if(bFrameActivated)
        {
        hwndMenu = WinLoadMenu(stRead.hwnd,(HMODULE)NULL,IDMPU_COL_DISP_POPUP);
        if (mp1 != 0)
          {
          WinQueryPointerPos(HWND_DESKTOP,&ptl);
          if (!stCFG.bStickyMenus)
            usMenuStyle |= PU_MOUSEBUTTON2DOWN;
          else
            usMenuStyle &= ~PU_MOUSEBUTTON2DOWN;
          }
        else
          {
          usMenuStyle &= ~PU_MOUSEBUTTON2DOWN;
          WinQueryWindowPos(hwndFrame,&swp);
          ptl.x = (swp.x + (swp.cx - (swp.cx / 4)));
          ptl.y = (swp.y + (swp.cy / 2));
          }
        if (stCFG.wColReadFont == wASCIIfont)
          PopupMenuItemCheck(hwndMenu,IDMPU_ASCII_FONT,TRUE);
        else
          PopupMenuItemCheck(hwndMenu,IDMPU_HEX_FONT,TRUE);
        if (stCFG.fLockWidth == LOCK_READ)
          PopupMenuItemCheck(hwndMenu,IDMPU_LOCK_WIDTH,TRUE);
        if (!bStopDisplayThread)
          WinSendMsg(hwndMenu,MM_SETITEMTEXT,(MPARAM)IDMPU_SYNC,"~Reset Display");
        WinPopupMenu(HWND_DESKTOP,stRead.hwndClient,hwndMenu,ptl.x,ptl.y,usLastPopupItem,usMenuStyle);
        }
      else
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
      break;
    case WM_BUTTON1DOWN:
      if(bFrameActivated)
        {
        WinCopyRect(habAnchorBlock,&rclRect,&stRead.rcl);
        lSaveEdge = rclRect.xLeft;
        if (TrackChildWindow(habAnchorBlock,hwndClient,&rclRect,TF_LEFT))
          {
          if (rclRect.xLeft != lSaveEdge)
            {
            WinSendMsg(stWrite.hwndClient,UM_TRACKSIB,0L,(MPARAM)rclRect.xLeft);
            WinSendMsg(stRead.hwndClient,UM_TRACKSIB,(MPARAM)rclRect.xLeft,0L);
            if (stCFG.fLockWidth == LOCK_WRITE)
              stCFG.lLockWidth = ((stWrite.lWidth / stCell.cx) + 1);
            else
              stCFG.lLockWidth = ((stRead.lWidth / stCell.cx) + 1);
            }
          }
        }
      else
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
      break;
    case WM_DESTROY:
      GpiDestroyPS(hdcPs);
      break;
    case UM_SHOWNEW:
      stRead.lScrollIndex = 0;
      stRead.lScrollRow = 0;
      ClearColScrollBar(&stRead);
    case UM_SHOWAGAIN:
      stRead.bActive = TRUE;
      if ((stCFG.fDisplaying & (DISP_DATA | DISP_FILE)) && !stCFG.bSyncToWrite)
        SetupColScrolling(&stRead);
      WinShowWindow(stRead.hwnd,TRUE);
      WinSendMsg(hwnd,UM_TRACKFRAME,0L,0L);
      WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE);
      WinInvalidateRect(hwndStatus,(PRECTL)NULL,FALSE);
      break;
    case UM_HIDEWIN:
      ClearColScrollBar(&stRead);
      stRead.bActive = FALSE;
      WinShowWindow(hwnd,FALSE);
      WinSetWindowPos(stRead.hwnd,HWND_BOTTOM,0L,0L,0L,0L,(SWP_MOVE | SWP_SIZE | SWP_ZORDER));
      break;
    case WM_PAINT:
#ifdef this_junk
      if (!pstCFG->bDisplayingData && (stCFG.bSyncToRead || stCFG.bSyncToWrite))
        ColumnPaint(&stRead,WinPeekMsg(habAnchorBlock,&stQmsg,stWrite.hwndClient,WM_PAINT,WM_PAINT,PM_REMOVE));
      else
#endif
        ColumnPaint(&stRead);
      break;
    case UM_TRACKSIB:
      ColumnSize(&stRead,(LONG)mp1,(LONG)mp2,TRUE);
      break;
    case UM_TRACKFRAME:
      ColumnSize(&stRead,(LONG)mp1,(LONG)mp2,FALSE);
      break;
    case WM_ERASEBACKGROUND:
      return (MRESULT)(TRUE);
    case WM_CLOSE:
      WinPostMsg(hwnd,WM_QUIT,0L,0L);
    default:
      return WinDefWindowProc(hwnd,msg,mp1,mp2);
    }
  return(FALSE);
  }
コード例 #15
0
//----------------------------------------------------------------------------
// NPP_SetWindow:
//----------------------------------------------------------------------------
NPError NP_LOADDS
NPP_SetWindow(NPP instance, NPWindow* window)
{
    if (instance == 0   )
        return NPERR_INVALID_INSTANCE_ERROR;

    PluginInstance* This = (PluginInstance*) instance->pdata;

    //
    // *Developers*: Before setting fWindow to point to the
    // new window, you may wish to compare the new window
    // info to the previous window (if any) to note window
    // size changes, etc.
    //
    if((window->window != 0   ) && (This->hWnd == 0   ))
    {
        This->fWindow = window;
        This->hWnd    = (HWND)This->fWindow->window;

        // subclass the window
        This->lpfnOldWndProc = WinSubclassWindow(This->hWnd, SubClassFunc);
        AssociateInstance(This->hWnd, This);

        // create a PS
        if (! This->hps)
        {
            HDC hdc = WinQueryWindowDC(This->hWnd);
            if (! hdc)
                hdc = WinOpenWindowDC(This->hWnd);
            SIZEL siz = { 0, 0 };
            This->hps = GpiCreatePS(WinQueryAnchorBlock(This->hWnd), hdc, &siz,
                                    PU_PELS | GPIT_MICRO | GPIA_ASSOC);
        }
    }
    else {
        // if window handle changed
        if(This->hWnd != (HWND)window->window) {
            // remember the new window
            This->fWindow = window;

            // Remove the subclass for the old client window
            WinSubclassWindow(This->hWnd, This->lpfnOldWndProc);

            // remember the new window handle
            This->hWnd = (HWND)This->fWindow->window;

            if(This->hWnd != 0   ) {
                // subclass the new one
                This->lpfnOldWndProc = WinSubclassWindow(This->hWnd,
                                                         SubClassFunc);
                AssociateInstance(This->hWnd, This);
            }

            // stop old timer and start a new timer
            WinStopTimer(WinQueryAnchorBlock(This->hWnd), This->hWnd, kTimerId);
            WinStartTimer(WinQueryAnchorBlock(This->hWnd), This->hWnd,
                          kTimerId, kTimerFrequency);

            // destroy old PS and create new PS
            if (! This->hps)
                GpiDestroyPS(This->hps);
            HDC hdc = WinQueryWindowDC(This->hWnd);
            if (! hdc)
                hdc = WinOpenWindowDC(This->hWnd);
            SIZEL siz = { 0, 0 };
            This->hps = GpiCreatePS(WinQueryAnchorBlock(This->hWnd), hdc, &siz,
                                    PU_TWIPS | GPIT_MICRO | GPIA_ASSOC);
        }
    }

    return NPERR_NO_ERROR;
}
コード例 #16
0
  /* Message processing for our PM Window class */
  MRESULT EXPENTRY  Message_Process( HWND    handle,
                                     ULONG   mess,
                                     MPARAM  parm1,
                                     MPARAM  parm2 )
  {
     static HDC     screen_dc;
     static HPS     screen_ps;
     static BOOL    minimized;

     SIZEL   sizl;
     SWP     swp;

     grPMSurface*  surface;

    /* get the handle to the window's surface -- note that this */
    /* value will be null when the window is created            */
    surface = (grPMSurface*)WinQueryWindowPtr( handle, QWL_USER );
    if (!surface)
    {
      surface = the_surface;
      WinSetWindowPtr( handle, QWL_USER, surface );
    }

    switch( mess )
    {
    case WM_DESTROY:
      /* warn the main thread to quit if it didn't know */
      surface->event.type = gr_event_key;
      surface->event.key  = grKeyEsc;
      DosPostEventSem( surface->event_lock );
      break;

    case WM_CREATE:
      /* set original magnification */
      minimized = FALSE;

      /* create Device Context and Presentation Space for screen. */
      screen_dc = WinOpenWindowDC( handle );
      screen_ps = GpiCreatePS( surface->anchor,
                               screen_dc,
                               &sizl,
                               PU_PELS | GPIT_MICRO |
                               GPIA_ASSOC | GPIF_DEFAULT );
      /* take the input focus */
      WinFocusChange( HWND_DESKTOP, handle, 0L );
      LOG(( "screen_dc and screen_ps have been created\n" ));

      /* To permit F9, F10 and others to pass through to the application */
      if (TRUE != WinSetAccelTable (surface->anchor, 0, surface->frame_window))
      {
        printf( "Error - failed to clear accel table\n");
      }
      break;

    case WM_MINMAXFRAME:
      /* to update minimized if changed */
      swp = *((PSWP) parm1);
      if ( swp.fl & SWP_MINIMIZE )
        minimized = TRUE;
      if ( swp.fl & SWP_RESTORE )
        minimized = FALSE;
      return WinDefWindowProc( handle, mess, parm1, parm2 );
      break;

    case WM_ERASEBACKGROUND:
    case WM_PAINT:
      /* copy the memory image of the screen out to the real screen */
      LOCK( surface->image_lock );
      WinBeginPaint( handle, screen_ps, NULL );

      /* main image and magnified picture */
      GpiBitBlt( screen_ps,
                 surface->image_ps,
                 4L,
                 surface->blit_points,
                 ROP_SRCCOPY, BBO_AND );

      WinEndPaint( screen_ps );
      UNLOCK( surface->image_lock );
      break;

    case WM_HELP:  /* this really is a F1 Keypress !! */
      surface->event.key = grKeyF1;
      goto Do_Key_Event;

    case WM_CHAR:
      if ( CHARMSG( &mess )->fs & KC_KEYUP )
        break;

      /* look for a specific vkey */
      {
        int          count = sizeof( key_translators )/sizeof( key_translators[0] );
        Translator*  trans = key_translators;
        Translator*  limit = trans + count;

        for ( ; trans < limit; trans++ )
          if ( CHARMSG(&mess)->vkey == trans->os2key )
          {
            surface->event.key = trans->grkey;
            goto Do_Key_Event;
          }
      }

      /* otherwise, simply record the character code */
      if ( (CHARMSG( &mess )->fs & KC_CHAR) == 0 )
        break;

      surface->event.key = CHARMSG(&mess)->chr;

    Do_Key_Event:
      surface->event.type = gr_event_key;
      DosPostEventSem( surface->event_lock );
      break;

    default:
      return WinDefWindowProc( handle, mess, parm1, parm2 );
    }

    return (MRESULT) FALSE;
  }
コード例 #17
0
ファイル: serialt.c プロジェクト: OS2World/APP-COMM-ComScope
MRESULT EXPENTRY fnwpClient(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
{
    RECTL   rcl;
    USHORT   Command;
    ULONG *pulPtr;

    switch(msg)
    {
    case WM_CREATE:
        stCell.cy = 12;
        stCell.cx = 8;
        hdcPs = WinOpenWindowDC(hwnd);

        /****************************************************************/
        /* Set the size and position of the frame window by making the  */
        /* client area width and height integral numbers of AVIO cell   */
        /* units.  Calculate the frame window values necessary to       */
        /* achieve this.                                                */
        /****************************************************************/

        rcl.yBottom = 0L;
        rcl.xLeft   = 0L;
        rcl.yTop    = 20 * stCell.cy;
        rcl.xRight  = 40 * stCell.cx;

        WinCalcFrameRect(WinQueryWindow(hwnd,QW_PARENT),&rcl,FALSE);

        WinSetWindowPos(WinQueryWindow(hwnd,QW_PARENT),
                        0,
                        7 * stCell.cx,
                        2 * stCell.cy,
                        (SHORT)(rcl.xRight - rcl.xLeft),
                        (SHORT)(rcl.yTop - rcl.yBottom),
                        SWP_MOVE | SWP_SIZE);

        WinPostMsg(hwnd,UM_INIT,0L,0L);
        break;
    case WM_ACTIVATE:
        if(LOUSHORT(LONGFROMMP(mp1)))
            WinSetFocus(HWND_DESKTOP,hwnd);
        break;
    case UM_INIT:
        if (szPortName[0] != 0)
            WinSetWindowText(hwndFrame,szPortName);
        else
            MenuItemEnable(hwndFrame,IDM_PROCESS,FALSE);
        WinShowWindow(hwndFrame,TRUE);
        WinQueryWindowRect(hwndClient,&rcl);
        ulWindowWidth = rcl.xRight;
        ulWindowHeight = rcl.yTop;
        ClearScreen();
        break;
    case WM_PAINT:
        Paint();
        break;
    case WM_SIZE:
        WndSize(hwnd,mp2);
        ClearScreen();
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
    case WM_COMMAND:
        switch (SHORT1FROMMP(mp1))
        {
        case IDM_SELECT:
            if (WinDlgBox(HWND_DESKTOP,
                          hwnd,
                          (PFNWP)fnwpSelectPortDlg,
                          (USHORT)NULL,
                          PS_DLG,
                          NULL))
                WinSetWindowText(hwndFrame,szPortDesc);
            break;
        case IDM_RECOVER_USER_INI:
            RecoverProfile(HINI_USERPROFILE);
            break;
        case IDM_RECOVER_SYS_INI:
            RecoverProfile(HINI_SYSTEMPROFILE);
            break;
        case IDM_EXIT:
            WinPostMsg(hwnd,WM_QUIT,0L,0L);
            break;
        case IDM_SETUP:
            SetupPort();
            break;
        case IDM_REMOVE:
            RemovePort();
            break;
        case IDM_INSTALL:
            InstallPort();
            break;
        case IDM_INIT:
            InitializePort();
            break;
        case IDM_TERM:
            TerminatePort();
//          TerminatePort(szPortName);
            break;
        case IDM_QUERY:
            ulItemCount = QueryPort(achBuffer,4096);
            break;
        default:
            return WinDefWindowProc(hwnd,msg,mp1,mp2);
        }
        break;
    case WM_CLOSE:
        WinPostMsg(hwnd,WM_QUIT,0L,0L);  /* Cause termination     */
        break;
    default:
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
    }
    return(FALSE);
}
コード例 #18
0
/****************************************************************\
 *
 *--------------------------------------------------------------
 *
 *  Name:ClkCreate()
 *
 *  Purpose:Intialize a newly created client window
 *
 *
 *
 *  Usage:
 *
 *  Method:
 *          -
 *
 *          -
 *          -
 *
 *          -
 *          -
 *
 *  Returns:
 *          1 - if sucessful execution completed
 *          0 - if error
\****************************************************************/
VOID ClkCreate ( HWND hwnd )
{
    LONG cxScreen , cyScreen;  /* screen dimensions */
    LONG xLeft , yBottom ;      /* frame window location */
    ULONG cbBuf;
    LONG cyHeight;
    LONG cxWidth;

    hwndClient = hwnd;

    WinLoadString(hab, NULLHANDLE, IDS_TITLE,  0, (PSZ)szTitle   );
    WinLoadString(hab, NULLHANDLE, IDS_HELPTITLE, 256, (PSZ)szHelpTitle);
    GetCountryDependent();
    /* we are called before the global hwndFrame is valid */
    hwndFrame = WinQueryWindow ( hwnd , QW_PARENT) ;
    hwndTitleBar = WinWindowFromID ( hwndFrame , FID_TITLEBAR ) ;
    hwndSysMenu = WinWindowFromID ( hwndFrame , FID_SYSMENU ) ;
    hwndMinMax = WinWindowFromID ( hwndFrame , FID_MINMAX ) ;

    /* load our menus */
    hwndMenu = WinLoadMenu (hwndFrame, NULLHANDLE, IDR_MAIN);
    /* determine screen dimensions */
    /* open a device context and create a presentation space */

    hdc = WinOpenWindowDC (hwnd);
    hps = GpiCreatePS (hab, hdc, &sizl, PU_ARBITRARY | GPIT_MICRO |
            GPIA_ASSOC);

    /*
     * Create our off-screen 'buffer'.
     */
    hdcBuffer = DevOpenDC ( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdc);
    hpsBuffer = GpiCreatePS (hab, hdcBuffer, &sizl, PU_ARBITRARY |
                               GPIT_MICRO | GPIA_ASSOC);

    GpiCreateLogColorTable (hpsBuffer, 0, LCOLF_RGB, 0, 0, (PLONG)NULL);

    /* get the device resolutions so we can make the face appear circular */
    DevQueryCaps (hdc, (LONG)CAPS_VERTICAL_RESOLUTION,(LONG) 1L, &cyRes);
    DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &cxRes);
    DevQueryCaps (hdc, CAPS_COLOR_PLANES, 1L, &cColorPlanes);
    DevQueryCaps (hdc, CAPS_COLOR_BITCOUNT, 1L, &cColorBitcount);

    cxScreen = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
    cyScreen = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);

    /*
     * Calculate an initial window position and size.
     */
    xLeft = cxScreen / 8;
    yBottom = cyScreen / 2;
    cxWidth = cxScreen / 3;
    cyHeight = cyScreen / 2;
    WinSetWindowPos (hwndFrame, NULLHANDLE, xLeft, yBottom,
                       cxWidth, cyHeight,
                       SWP_SIZE | SWP_MOVE | SWP_ACTIVATE);

    cbBuf = sizeof(cp);
    if (!PrfQueryProfileData(HINI_USER, SZ_APPNAME, SZ_KEYNAME, &cp, &cbBuf))
    {
        cp.usMajorTickPref = CLKTM_ALWAYS;
        cp.usMinorTickPref = CLKTM_NOTICONIC;
        cp.clrBackground = 0x00008080;
        cp.clrFace = 0x00008080;
        cp.clrHourHand = RGB_RED;
        cp.clrMinuteHand = RGB_RED;
        cp.fControlsHidden = FALSE;
        cp.usDispMode = DM_TIME | DM_ANALOG | DM_SECONDHAND;
        cp.alarm.uchHour = 0;
        cp.alarm.uchMinutes = 0;
        cp.alarm.usMode = 0;
        SetRGBColors();
        /* position the window and make it visible */
        WinSetWindowPos( hwndFrame , NULLHANDLE ,
                           xLeft , yBottom ,
                           cxWidth , cyHeight ,
                           SWP_SIZE | SWP_MOVE | SWP_ACTIVATE);
        WinQueryWindowPos(hwndFrame, &cp.swp);
    }
    else
    { /*Protect against garbage swp*/

        cp.swp.hwnd = hwndFrame;
        cp.swp.hwndInsertBehind = HWND_TOP;

        cp.swp.fl = (cp.swp.fl & (SWP_MINIMIZE | SWP_MAXIMIZE)) | SWP_SIZE | SWP_MOVE | SWP_ACTIVATE;
        SetRGBColors();
        WinSetMultWindowPos(hab, &cp.swp, 1);
    }

    if (cp.fControlsHidden)
        ClkHideFrameControls (hwndFrame);

    /*
     * Check relevant items.
     */
    WinSendMsg( hwndMenu,
                MM_SETITEMATTR,
                MPFROM2SHORT( IDM_TIME, TRUE),
                MPFROM2SHORT( MIA_CHECKED,
                              ( (cp.usDispMode & DM_TIME)?  MIA_CHECKED
                                      : ~MIA_CHECKED) ) );
    WinSendMsg( hwndMenu,
                MM_SETITEMATTR,
                MPFROM2SHORT( IDM_DATE, TRUE),
                MPFROM2SHORT( MIA_DISABLED,
                              ( (!(cp.usDispMode & DM_TIME))?  MIA_DISABLED
                                      : ~MIA_DISABLED) ) );
    WinSendMsg( hwndMenu,
                MM_SETITEMATTR,
                MPFROM2SHORT( IDM_DATE, TRUE),
                MPFROM2SHORT( MIA_CHECKED,
                              ( (cp.usDispMode & DM_DATE)?  MIA_CHECKED
                                      : ~MIA_CHECKED) ) );
    WinSendMsg( hwndMenu,
                MM_SETITEMATTR,
                MPFROM2SHORT( IDM_TIME, TRUE),
                MPFROM2SHORT( MIA_DISABLED,
                              ( ((!(cp.usDispMode & DM_DATE) || (cp.usDispMode & DM_ANALOG)))?  MIA_DISABLED
                                      : ~MIA_DISABLED) ) );
    WinSendMsg( hwndMenu,
                MM_SETITEMATTR,
                MPFROM2SHORT( (cp.usDispMode & DM_DIGITAL)
                                                          ?IDM_DIGITAL
                                                          :IDM_ANALOG,
                               TRUE),
                MPFROM2SHORT( MIA_CHECKED,
                              MIA_CHECKED));

    WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDM_SECONDHAND, TRUE),
                MPFROM2SHORT( MIA_CHECKED,
                              ( (cp.usDispMode & DM_SECONDHAND) ? MIA_CHECKED
                                      : ~MIA_CHECKED)));


    /*
     * Disable these items if the digital clock is visible
     * since they won't apply.
     */
    if (cp.usDispMode & DM_DIGITAL)
    {
        WinSendMsg (hwndMenu, MM_SETITEMATTR,
                MPFROM2SHORT(IDM_SECONDHAND, TRUE),
                MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));

        WinSendMsg (hwndMenu, MM_SETITEMATTR,
                MPFROM2SHORT( IDM_TICKS, TRUE), MPFROM2SHORT( MIA_DISABLED,
                MIA_DISABLED));
    }

    /* have we been asked to start as an icon? */
    if (fStartAsIcon)
        WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 0, 0, SWP_MINIMIZE);

    WinShowWindow(hwndFrame, TRUE);

    /* get the time in a format for dislaying */
    DosGetDateTime(&dt);
    dt.hours = (UCHAR )(dt.hours * (UCHAR) 5) % (UCHAR) 60 + dt.minutes / (UCHAR)12;

    /* start a timer */
    WinStartTimer (hab, hwnd, IDR_MAIN, 1000);

    WinLoadString(hab, NULLHANDLE, IDS_TITLE, 80, (PSZ)szTitle);
    GetCountryDependent();

}
コード例 #19
0
ファイル: os2pm.c プロジェクト: OS2World/LIB-libfly
MRESULT EXPENTRY FlyWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    SIZEL        sizl;
    int          rc, key, mou_r, mou_c, mou_ev, new_vio_rows, new_vio_cols;
    int          deltaX, deltaY, pix_rows, pix_cols, new_x0, new_y0;
    static int   mou_c1=-1, mou_r1=-1;
    struct _item *L;
    HWND         hwndMenu;
    SWP          swp;
    QMSG         *qmsg;
    USHORT       vk, fl;
    
    switch (msg)
    {
    case WM_CREATE:
        hdc = WinOpenWindowDC (hwnd);
        sizl.cx = sizl.cy = 0;
        grab_video ();
        hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT |
                           GPIT_MICRO | GPIA_ASSOC);
        rc = VioCreatePS (&hvps, 80, 25, 0, 1, 0);
        VioGetDeviceCellSize (&cyChar, &cxChar, hvps);
        set_cursor (0);
        VioSetCurType (pci, hvps);
        release_video ();
        DosPostEventSem (hev_VideoReady);
        return 0;
        
    case WM_MOUSEMOVE:          mou_ev = MOUEV_MOVE; goto MOUSE;
    
    case WM_BUTTON1CLICK:       mou_ev = MOUEV_B1SC; goto MOUSE;
    case WM_BUTTON1DBLCLK:      mou_ev = MOUEV_B1DC; goto MOUSE;
    case WM_BUTTON1MOTIONSTART: mou_ev = MOUEV_B1MS; goto MOUSE;
    case WM_BUTTON1MOTIONEND:   mou_ev = MOUEV_B1ME; goto MOUSE;
    case WM_BUTTON1DOWN:        mou_ev = MOUEV_B1DN; goto MOUSE;
    case WM_BUTTON1UP:          mou_ev = MOUEV_B1UP; goto MOUSE;
    
    case WM_BUTTON2CLICK:       mou_ev = MOUEV_B2SC; goto MOUSE;
    case WM_BUTTON2DBLCLK:      mou_ev = MOUEV_B2DC; goto MOUSE;
    case WM_BUTTON2MOTIONSTART: mou_ev = MOUEV_B2MS; goto MOUSE;
    case WM_BUTTON2MOTIONEND:   mou_ev = MOUEV_B2ME; goto MOUSE;
    case WM_BUTTON2DOWN:        mou_ev = MOUEV_B2DN; goto MOUSE;
    case WM_BUTTON2UP:          mou_ev = MOUEV_B2UP; goto MOUSE;
    
    case WM_BUTTON3DBLCLK:      mou_ev = MOUEV_B3DC; goto MOUSE;
    case WM_BUTTON3CLICK:       mou_ev = MOUEV_B3SC; goto MOUSE;
    case WM_BUTTON3MOTIONSTART: mou_ev = MOUEV_B3MS; goto MOUSE;
    case WM_BUTTON3MOTIONEND:   mou_ev = MOUEV_B3ME; goto MOUSE;
    case WM_BUTTON3DOWN:        mou_ev = MOUEV_B3DN; goto MOUSE;
    case WM_BUTTON3UP:          mou_ev = MOUEV_B3UP; goto MOUSE;
    
    MOUSE:
        if (fl_opt.mouse_active != TRUE) break;
        mou_r = vio_rows - 1 - (SHORT2FROMMP (mp1)/cyChar);
        mou_c = SHORT1FROMMP (mp1)/cxChar;
        if (mou_r < 0 || mou_c < 0) break;
        // prevent MOUEV_MOVE message with same coordinates
        if (mou_ev == MOUEV_MOVE && mou_r == mou_r1 && mou_c == mou_c1) break;
        mou_r1 = mou_r, mou_c1 = mou_c;
        que_put (FMSG_BASE_MOUSE + FMSG_BASE_MOUSE_EVTYPE*mou_ev +
                 FMSG_BASE_MOUSE_X*mou_c + FMSG_BASE_MOUSE_Y*mou_r);
        break;
        
    case WM_PAINT:
        WinBeginPaint (hwnd, hps, NULL);
        grab_video ();
        VioShowBuf (0, 2 * vio_rows * vio_cols, hvps);
        release_video ();
        WinEndPaint (hps);
        return 0;

    case WM_CHAR:
        if (SHORT1FROMMP (mp1) & KC_KEYUP) return 0;
        if (SHORT2FROMMP (mp2) == VK_SHIFT ||
            SHORT2FROMMP (mp2) == VK_CTRL ||
            SHORT2FROMMP (mp2) == VK_ALT) return 0;
        key = pmkey2asvkey (SHORT2FROMMP(mp2), CHAR4FROMMP(mp1), SHORT1FROMMP(mp2),
                            CHAR3FROMMP(mp1), SHORT1FROMMP(mp1));
        if (key != -1) que_put (key);
        return 0;

    case WM_TRANSLATEACCEL:
        qmsg = (QMSG *)mp1;
        vk = SHORT2FROMMP (qmsg->mp2);
        fl = SHORT1FROMMP (qmsg->mp1) & (KC_ALT | KC_SHIFT | KC_CTRL | KC_KEYUP);
        if (vk == VK_MENU || vk == VK_F1) return FALSE;
        //if ((fl & KC_ALT) && vk >= VK_F1 && vk <= VK_F24) return FALSE;
        break;
        
    case WM_CLOSE:
        que_put (FMSG_BASE_SYSTEM +
                 FMSG_BASE_SYSTEM_TYPE*SYSTEM_QUIT);
        return 0;
        
    case WM_SIZE:
        if (cxChar != 0 && cyChar != 0)
        {
            pix_rows = SHORT2FROMMP (mp2);
            pix_cols = SHORT1FROMMP (mp2);
            new_vio_rows = pix_rows / cyChar;
            new_vio_cols = pix_cols / cxChar;
            if (new_vio_rows != vio_rows || new_vio_cols != vio_cols)
            {
                grab_video ();
                VioAssociate (0, hvps);
                VioDestroyPS (hvps);
                rc = VioCreatePS (&hvps, new_vio_rows, new_vio_cols, 0, 1, 0);
                VioSetDeviceCellSize (cyChar, cxChar, hvps);
                VioGetDeviceCellSize (&cyChar, &cxChar, hvps);
                rc = VioAssociate (hdc, hvps);
                VioSetCurType (pci, hvps);
                release_video ();
                que_put (FMSG_BASE_SYSTEM + FMSG_BASE_SYSTEM_TYPE*SYSTEM_RESIZE +
                         FMSG_BASE_SYSTEM_INT2*new_vio_rows + FMSG_BASE_SYSTEM_INT1*new_vio_cols);
            }
            deltaX = new_vio_cols*cxChar - pix_cols;
            deltaY = new_vio_rows*cyChar - pix_rows;
            //if (deltaX != 0 || deltaY != 0)
            if (abs(deltaX) > MAX_DELTA || abs(deltaY) > MAX_DELTA)
            {
                WinPostMsg (hwndFrame, WM_FLY_RESIZE,
                            MPFROM2SHORT (SHORTBASE+deltaX, SHORTBASE+deltaY), NULL);
            }
        }
        WinDefAVioWindowProc (hwnd, msg, (ULONG)mp1, (ULONG)mp2);
        return 0;

    case WM_COMMAND:
        que_put (FMSG_BASE_MENU + LOUSHORT (mp1));
        break;

    case WM_FLY_LOADMENU:
        L = PVOIDFROMMP (mp1);
        // obtain handle for window menu
        hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU);
        fill_submenu (hwndMenu, L);
        fly_active_menu = L;
        break;

    case WM_FLY_UNLOADMENU:
        L = PVOIDFROMMP (mp1);
        // obtain handle for window menu
        hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU);
        empty_submenu (hwndMenu, L);
        fly_active_menu = NULL;
        break;
        
    case WM_FLY_RESIZE:
        deltaX = SHORT1FROMMP (mp1) - SHORTBASE;
        deltaY = SHORT2FROMMP (mp1) - SHORTBASE;
        rc = WinQueryWindowPos (hwndFrame, &swp);
        rc = WinSetWindowPos (hwndFrame, 0, swp.x, swp.y-deltaY, swp.cx+deltaX, swp.cy+deltaY, SWP_SIZE|SWP_MOVE);
        break;
        
    case WM_FLY_MOVE_CANVAS:
        new_x0 = SHORT1FROMMP (mp1) - SHORTBASE;
        new_y0 = SHORT2FROMMP (mp1) - SHORTBASE;
        rc = WinQueryWindowPos (hwndFrame, &swp);
        WinSetWindowPos (hwndFrame, 0, new_x0, new_y0-swp.cy, 0, 0, SWP_MOVE);
        //DosPostEventSem (hev_VideoReady);
        break;
        
    case WM_FLY_MENU_CHSTATUS:
        hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU);
        WinEnableMenuItem (hwndMenu, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1));
        item_status_change++;
        break;
        
    case WM_FLY_MENU_CHSTATE:
        hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU);
        WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT (SHORT1FROMMP(mp1), TRUE),
                    MPFROM2SHORT (MIA_CHECKED, SHORT2FROMMP(mp1) ? MIA_CHECKED : 0));
        break;
        
    case WM_DESTROY:
        grab_video ();
        VioAssociate (0, hvps);
        VioDestroyPS (hvps);
        GpiDestroyPS (hps);
        release_video ();
        que_put (FMSG_BASE_SYSTEM +
                 FMSG_BASE_SYSTEM_TYPE*SYSTEM_DIE);
        return 0;
    }
    
    return WinDefWindowProc (hwnd, msg, mp1, mp2);
}