示例#1
0
static void internal_GetStaticTextSize(HWND hwnd, ULONG ulID, int *piCX, int *piCY) {
	HPS hps;
	char achTemp[512];
	POINTL aptl[TXTBOX_COUNT];

	// This calculates how much space is needed for a given static text control
	// to hold its text.
	WinQueryDlgItemText(hwnd, ulID, sizeof(achTemp), achTemp);

	hps = WinGetPS(WinWindowFromID(hwnd, ulID));
	GpiQueryTextBox(hps, strlen(achTemp), achTemp, TXTBOX_COUNT, aptl);

	*piCX = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_BOTTOMLEFT].x;
	*piCY = aptl[TXTBOX_TOPRIGHT].y - aptl[TXTBOX_BOTTOMLEFT].y;

	WinReleasePS(hps);
}
// -------------------------------------------------------------------------
HWND CreateToolbar(HWND hwndParent, HMODULE hmod, ULONG menuid)
{
  UCMINFO UCMInfo;
  ULONG   ulMCx, ulMCy, flgs = 0;
  HWND    hwndClient, hwndMenu, hTmp;

  WinRegisterClass( (HAB)0, "TOOLBAR", ClientWndProc, CS_SIZEREDRAW, 0);

  hwndClient = WinCreateWindow( hwndParent, "TOOLBAR", "", flgs, 8, 8, 0, 0,
                                hwndParent, HWND_TOP, menuid, NULL, NULL );

  memset(&UCMInfo, 0, sizeof(UCMINFO));
  UCMInfo.cb = sizeof(UCMINFO);

  UCMInfo.NbOfCols = 1;
  UCMInfo.NbOfRows = 7;
  UCMInfo.Style    = UCS_FRAMED    |          // Draw a 3D frame around the items
                     UCS_FORCESIZE |       // Force the size of the items
                     UCS_CHNGBMPBG |       // Use one of the bitmap colors as a background color
                     UCS_NO_DM     |       // No drag&drop manip
                     UCS_NO_CM;            // No context menu

  HPS hps = WinGetPS( hwndClient );
  // --  Set the color of the bitmaps which has to be replaced by the items background color
   UCMInfo.BgBmp     = GpiQueryRGBColor( hps, 0, CLR_PALEGRAY );
   UCMInfo.BgColor   = GpiQueryRGBColor( hps, 0, CLR_DARKGRAY );
  // -- Set the color of the items background
  UCMInfo.ItemBgColor = 0x00b0b0b0;
  WinReleasePS( hps );

  UCMInfo.cx = 24;   // Width of the items   ( used because UCS_FORCESIZE is set )
  UCMInfo.cy = 24;   // Height of the items
  UCMInfo.hModule = hmod;

  hwndMenu = UCMenuCreateFromResource( (HAB)0, hwndClient, hwndClient,
                                       CMS_MATRIX, 0, 0, 0, 0, HWND_TOP,
                                       FID_MENU, hmod, ID_TOOLS, &UCMInfo, &hTmp );

//  hide_scrollbars( hwndMenu );
  WinSendMsg( hwndMenu, UCMENU_QUERYSIZE, MPFROMP( &ulMCx ), MPFROMP( &ulMCy ) );
  WinSetWindowPos( hwndMenu, HWND_TOP, 0, 0, ulMCx, ulMCy, SWP_SIZE );
  WinSetWindowPos( hwndClient, HWND_TOP, 0, 0, ulMCx, ulMCy+8, SWP_SIZE );

  return hwndClient;
}
示例#3
0
static void SetMonitorSize (HWND hwnd,HWND hwndMenu,SWP *swpH,char *s) {

  HPS    hps;
  POINTL aptl[TXTBOX_COUNT];
  SWP    swp;
  ULONG  fl = SWP_SIZE | SWP_SHOW | SWP_MOVE;
  long   cx,cy;

  if(s) {
    WinSetWindowText(hwnd,s);
    if(*s) {
      hps = WinGetPS(hwnd);
      GpiQueryTextBox(hps,
                      strlen(s),
                      s,
                      TXTBOX_COUNT,
                      aptl);
      WinReleasePS(hps);
      cx = aptl[TXTBOX_TOPRIGHT].x + 4;
      cy = aptl[TXTBOX_TOPRIGHT].y + 4;
      WinQueryWindowPos(hwnd,
                        &swp);
      if(swp.cx == cx &&
         swp.cy == cy)
        fl = 0;
      if(swpH->x + cx > xScreen)
        swpH->x = xScreen - cx;
      if(swpH->y + cy > yScreen)
        swpH->y = yScreen - cy;
      if(fSwapFloat &&
         !hwndMenu)
        fl |= SWP_ZORDER;
      if(fl)
        WinSetWindowPos(hwnd,
                        HWND_TOP,
                        swpH->x,
                        swpH->y,
                        cx,
                        cy,
                        fl);
    }
  }
}
//--------------------------------------------------------------------------
//
// DrawShearedBox
//
// --------------------------------------------------------------------------
void DrawShearedBox( HWND hwnd )
{
  HPS hps;
  POINTL pointl;
  MATRIXLF m;

  // Get a cached PS for the window

  hps = WinGetPS( hwnd );

  // Query the current contents of the model transform

  GpiQueryModelTransformMatrix( hps, 9L, &m );

  m.fxM21 = MAKEFIXED(1,0); // tan(45)
 // m.fxM22 = MAKEFIXED(1,0); // identity

  // Replace the model transform with our modified one

  GpiSetModelTransformMatrix( hps, 9L, &m, TRANSFORM_REPLACE );


  // Set the current position to (0,100)

  pointl.x = 400; pointl.y = 200;

  GpiSetCurrentPosition( hps, &pointl );

  // Draw a 100 by 100 box from the current position in the
  // current color.

  pointl.x = pointl.y = 100;

  GpiSetColor( hps, CLR_BLUE );
  GpiSetPattern( hps, PATSYM_HALFTONE );

  GpiBox( hps, DRO_OUTLINEFILL, &pointl,0,0 );

  // Free the cached PS

  WinReleasePS( hps );
}
示例#5
0
void wxConvertVectorFontSize(
  FIXED                             fxPointSize
, PFATTRS                           pFattrs
)
{
    HPS                             hPS;
    HDC                             hDC;
    LONG                            lXFontResolution;
    LONG                            lYFontResolution;
    SIZEF                           vSizef;

    hPS = WinGetScreenPS(HWND_DESKTOP); // Screen presentation space

    //
    //   Query device context for the screen and then query
    //   the resolution of the device for the device context.
    //

    hDC = GpiQueryDevice(hPS);
    DevQueryCaps( hDC, CAPS_HORIZONTAL_FONT_RES, (LONG)1, &lXFontResolution);
    DevQueryCaps( hDC, CAPS_VERTICAL_FONT_RES, (LONG)1, &lYFontResolution);

    //
    //   Calculate the size of the character box, based on the
    //   point size selected and the resolution of the device.
    //   The size parameters are of type FIXED, NOT int.
    //   NOTE: 1 point == 1/72 of an inch.
    //

    // multiply first to avoid getting vSizef.cx,cy = 0 since fxPointSize
    // is normally < 72 and FontResolution is typically ca. 100
    vSizef.cx = (FIXED)( (fxPointSize * lXFontResolution) / 72 );
    vSizef.cy = (FIXED)( (fxPointSize * lYFontResolution) / 72 );

    if (pFattrs)
    {
        pFattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( vSizef.cy ), 0 );
        pFattrs->lAveCharWidth   = MAKELONG( HIUSHORT( vSizef.cx ), 0 );
    }
    WinReleasePS(hPS);

} // end of wxConvertVectorPointSize
示例#6
0
/* Returns TRUE if WarpSans is supported by operating system. */
BOOL
check_warpsans( void )
{
  static int have_warpsans = -1;

  if( have_warpsans == -1 )
  {
    LONG fontcounter = 0;
    HPS  hps;
    BOOL rc;

    hps = WinGetPS( HWND_DESKTOP );
    rc  = GpiQueryFonts( hps, QF_PUBLIC, "WarpSans", &fontcounter, 0, NULL );
    WinReleasePS( hps );

    have_warpsans = ( rc != 0 && rc != GPI_ALTERROR );
  }

  return have_warpsans;
}
//--------------------------------------------------------------------------
//
// DrawTransformedBox
//
// --------------------------------------------------------------------------
void DrawTransformedBox( HWND hwnd )
{
  HPS hps;
  POINTL pointl;
  MATRIXLF m;

  // Get a cached PS for the window

  hps = WinGetPS( hwnd );

  // Query the current contents of the model transform

  GpiQueryModelTransformMatrix( hps, 9L, &m );

  m.lM31  = 100;                 // Translate the x coordinates
  m.lM32  = 100;                 // Translate the y coordinates
  m.fxM11 = MAKEFIXED(10,0);     // Scale up the x coordinates
  m.fxM22 = MAKEFIXED(10,0);     // Scale up the y coordinates

  // Replace the model transform with our modified one

  GpiSetModelTransformMatrix( hps, 9L, &m, TRANSFORM_REPLACE );


  // Set the current position to (0,0)

  pointl.x = pointl.y = 0;

  GpiSetCurrentPosition( hps, &pointl );

  // Draw a 10 by 10 box from the current position in the
  // current color.

  pointl.x = pointl.y = 10;

  GpiBox( hps, DRO_OUTLINE, &pointl,0,0 );

  // Free the cached PS

  WinReleasePS( hps );
}
示例#8
0
BOOL clbCreateProc(HWND hwnd, PCLBOXCDATA pclcd, PCREATESTRUCT pc, ULONG style) {
   PCLBOX pclb;
   HPS hps;
   // allocate structure for caching some control data
   if (!(pclb = (PCLBOX)malloc(sizeof(CLBOX)))) return FALSE;
   memset((PVOID)pclb, 0, sizeof(CLBOX));
   // copy some data
   pclb->hab = WinQueryAnchorBlock(hwnd);
   pclb->hwnd = hwnd;
   pclb->fl = pc->flStyle;
   pclb->szl.cx = pc->cx;
   pclb->szl.cy = pc->cy;
   pclb->id = pc->id;
   pclb->hOwner = pc->hwndOwner;
   // Set color control
   if (!(hps = WinGetPS(hwnd))) goto error0;
   clbUpdColors(pclb, hps);
   if ((pclb->cyFont = stSizeFont(hps)) % 2) ++pclb->cyFont;
   WinReleasePS(hps);
   // Interprets controldata
   if (!clbSetCtlData(pclb, pclcd)) goto error0;
   if (clbSetText(pclb, pc->pszText, -1)) *pc->pszText = 0;
   // reset WC_STATIC style
   WinSetWindowBits(hwnd, QWL_STYLE, style, 0xffff);
   WinSetWindowPtr(hwnd, cbWCstc, (PVOID)pclb);
   if (pfnwpWCstc(hwnd, WM_CREATE, (MPARAM)pclcd, (MPARAM)pc)) goto error1;
   // If no CLBXS_CHECK style is set to checkon flags at 1
   if (!(pclb->fl & CLBXS_CHECK)) pclb->is.chkon = 1;
   if (!clbChilds(pclb, pc)) goto error2;
   if (!(pclb->fl & WS_DISABLED)) pclb->is.enbl = 1;
   return TRUE;

   error2:
      WinDestroyWindow(hwnd);
   error1:
      if (pclb->psz) free(pclb->psz);
   error0:
      free(pclb);
      return FALSE;
}
示例#9
0
void GetFontMetrics( HWND hwndWnd, BOOL fCopy )
{
   HPS         hpsClient;
   FONTMETRICS fmFontMetrics;


   hpsClient = WinGetPS( hwndWnd );
   GpiQueryFontMetrics( hpsClient, sizeof( fmFontMetrics ), &fmFontMetrics );
   cxChar = fmFontMetrics.lAveCharWidth;
   cxCaps = fmFontMetrics.lEmInc;
   cyChar = fmFontMetrics.lMaxBaselineExt;
   cyDesc = fmFontMetrics.lMaxDescender;
   WinReleasePS( hpsClient );

   if ( fCopy )
   {
      // Transfer the default font attributes into the FATTRS block of the FontDlg
      fdFontDlg.fAttrs.fsSelection = 0;
      fdFontDlg.fAttrs.lMatch = fmFontMetrics.lMatch;
      strcpy( fdFontDlg.fAttrs.szFacename, fmFontMetrics.szFacename );
   }
}
示例#10
0
static LONG GetFontByDlg(HWND hwndOwner, PPRINTSETUP pPrintSetup, char *pchFont, ULONG idFontDisp)
{
   FONTDLG FontDlg;
   char pchFamily[FACESIZE+5]="";
   long lTemp;
   FONTMETRICS FontMetrics;
   HPS hps;

   hps = WinGetPS(WinWindowFromID(hwndOwner, idFontDisp));

   GpiQueryFontMetrics(hps, sizeof(FontMetrics), &FontMetrics);

   strcpy(pchFamily, FontMetrics.szFamilyname);

   WinReleasePS(hps);

   lTemp = strtol(pchFont, NULL, 10);

   memset(&FontDlg, 0, sizeof(FontDlg));

   FontDlg.cbSize = sizeof(FontDlg);
   FontDlg.hpsPrinter = pPrintSetup->hpsPrinterInfo;
   FontDlg.pszFamilyname = pchFamily;
   FontDlg.usFamilyBufLen = sizeof(pchFamily);
   FontDlg.fxPointSize = MAKEFIXED(lTemp, 0);
   FontDlg.fl = FNTS_CENTER | FNTS_VECTORONLY;
   FontDlg.flFlags = FNTF_NOVIEWSCREENFONTS;
   FontDlg.clrFore = CLR_BLACK;
   FontDlg.clrBack = CLR_WHITE;

   WinFontDlg(HWND_DESKTOP, hwndOwner, &FontDlg);

   if (FontDlg.lReturn == DID_OK)
   {
      sprintf(pchFont, "%d.%s", (int) FIXEDINT(FontDlg.fxPointSize), FontDlg.fAttrs.szFacename);
   }

   return FontDlg.lReturn;
}
示例#11
0
void externalPaint(HWND hwnd)
{
    // hwnd is the value returned by QWidget::winId()

    RECTL rcl;
    WinQueryWindowRect(hwnd, &rcl);
    HPS hps = WinGetPS(hwnd);

    HRGN hrgn = GpiCreateRegion(hps, 1L, &rcl);
    ULONG rc = qt_WinProcessWindowObstacles(hwnd, NULL, hrgn, CRGN_DIFF,
                                            0 /* PWO_Default */);
    if (rc == RGN_RECT || rc == RGN_COMPLEX) {
        HRGN hrgnOld;
        GpiSetClipRegion (hps, hrgn, &hrgnOld);
        hrgn = hrgnOld;

        // Paint to hps using regular PM and GPI calls
    }

    GpiDestroyRegion (hps, hrgn);

    WinReleasePS (hps);
}
示例#12
0
VOID InitApp(HWND hwndFrame, HWND hwndClient, PSZ pszWindowListTitle)

{
HPS	hPS;			   /* Presentation Space Handle		*/
SWCNTRL	swCtl;			   /* Task Switch Control Structure	*/

		       /* Get a	temporary presentation space so	that	*/
		       /* the system's font metrics can be found and    */
		       /* the proper sizing of owner draw list boxes	*/
		       /* can be performed properly			*/

if ( (hPS = WinGetPS(hwndClient)) != (HPS)NULL )
   {
   GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), &fm);

		       /* Release the temporary	presentation space	*/
   WinReleasePS(hPS);
   }

if ( pszWindowListTitle	)
   {
		       /* Fill Switch Entry structure with required	*/
		       /* values before	adding program name to Task	*/
		       /* Manager switch list				*/

   swCtl.hwnd	       = hwndFrame;
   swCtl.hwndIcon      = (HWND)NULL;
   swCtl.hprog	       = (HPROGRAM)NULL;
   swCtl.idProcess     =
   swCtl.idSession     = 0;
   swCtl.uchVisibility = SWL_VISIBLE;
   swCtl.fbJump	       = SWL_JUMPABLE;
   strcpy(swCtl.szSwtitle, pszWindowListTitle);

   hSwitch = WinAddSwitchEntry(&swCtl);
   }
}
示例#13
0
void        InitSort( HWND hwnd)

{
    HPS         hps;

    // load the sort menu's custom checkmarks
    hps = WinGetPS( hwnd);
    if (hps)
    {
        hUpBmp = GpiLoadBitmap( hps, 0, IDB_UPBMP, 0, 0);
        hDownBmp = GpiLoadBitmap( hps, 0, IDB_DOWNBMP, 0, 0);
        WinReleasePS( hps);
    }
    // if that failed, use the standard checkmark
    if (hUpBmp == 0)
        hUpBmp = WinGetSysBitmap( HWND_DESKTOP, SBMP_MENUCHECK);
    if (hDownBmp == 0)
        hDownBmp = WinGetSysBitmap( HWND_DESKTOP, SBMP_MENUCHECK);

    RestoreSort();
    InitSortMenu( hwnd);

    return;
}
示例#14
0
/**************************************************************************
 *
 *  Name       : MyWindowProc
 *
 *  Description: The window procedure associated with the client area in
 *               the standard frame window. It processes all messages
 *               either sent or posted to the client area, depending on
 *               the message command and parameters.
 *
 *  Concepts   :
 *
 *  API's      :   WinLoadString
 *                 WinInvalidateRegion
 *                 WinPostMsg
 *                 WinDefWindowProc
 *                 WinBeginPaint
 *                 GpiSetColor
 *                 GpiSetBackColor
 *                 GpiSetBackMix
 *                 GpiCharStringAt
 *                 WinEndPaint
 *
 *  Parameters :  hwnd = window handle
 *                msg = message code
 *                mp1 = first message parameter
 *                mp2 = second message parameter
 *
 *  Return     :  depends on message sent
 *
 *************************************************************************/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
  switch( msg )
  {
      case WM_TIMER: {
          WinInvalidateRegion( hwnd, 0L, FALSE );
          break;
        }
    case WM_CREATE:
      /*
       * Window initialization is performed here in WM_CREATE processing
       * WinLoadString loads strings from the resource file.
       */
      WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello );
      WinLoadString( hab, (HMODULE)0L, IDS_1,     STRINGLENGTH, sz1     );
      WinLoadString( hab, (HMODULE)0L, IDS_2,     STRINGLENGTH, sz2     );
      WinLoadString( hab, (HMODULE)0L, IDS_3,     STRINGLENGTH, sz3     );
      strcpy( szString, szHello );      /* Copy text Hello into szString*/
      break;

    case WM_COMMAND:
      /*
       * When the user chooses option 1, 2, or 3 from the Options pull-
       * down, the text string is set to 1, 2, or 3, and
       * WinInvalidateRegion sends a WM_PAINT message.
       * When Exit is chosen, the application posts itself a WM_CLOSE
       * message.
       */
      {
      USHORT command;                   /* WM_COMMAND command value     */
      command = SHORT1FROMMP(mp1);      /* Extract the command value    */
      switch (command)
      {
        case ID_EXITPROG:
          WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
          break;
        default:
          return WinDefWindowProc( hwnd, msg, mp1, mp2 );
      }

      break;
      }
    case WM_ERASEBACKGROUND:
      /*
       * Return TRUE to request PM to paint the window background
       * in SYSCLR_WINDOW.
       */
      return (MRESULT)( TRUE );
    case WM_PAINT:
      /*
       * Window contents are drawn here in WM_PAINT processing.
       */
      {
      HPS    hps;                       /* Presentation Space handle    */
      RECTL  rc;                        /* Rectangle coordinates        */
      POINTL pt;                        /* String screen coordinates    */
      POINTL pPos;
      LONG lColor,r,g,b;
      FATTRS fat;
      HPS shps = WinGetScreenPS(HWND_DESKTOP);
fat.usRecordLength = sizeof(FATTRS); /* sets size of structure   */
fat.fsSelection = 0;         /* uses default selection           */
fat.lMatch = 0L;             /* does not force match             */
fat.idRegistry = 0;          /* uses default registry            */
fat.usCodePage = 0;        /* code-page 850                    */
fat.lMaxBaselineExt = 14L;   /* requested font height is 12 pels */
fat.lAveCharWidth = 14L;     /* requested font width is 12 pels  */
fat.fsType = 0;              /* uses default type                */
fat.fsFontUse = FATTR_FONTUSE_NOMIX;/* doesn't mix with graphics */
strcpy(fat.szFacename ,"Courier");
      WinQueryPointerPos(HWND_DESKTOP, &pPos);
      hps = WinBeginPaint( hwnd, 0L, &rc );
      GpiCreateLogColorTable(shps, 0, LCOLF_RGB, 0, 0, NULL);
      GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
      pt.x = 10; pt.y = 27;             /* Set the text coordinates,    */
      lColor=GpiQueryPel(shps, &pPos);
      GpiSetBackColor( hps, 16777215);  /* its background and    */
      WinFillRect( hps, &rc, lColor);
      GpiSetBackMix( hps, BM_OVERPAINT );      /* how it mixes,         */
      b = lColor & 0x000000FF;
      lColor = lColor >> 8;
      g = lColor & 0x000000FF;
      lColor = lColor >> 8;
      r = lColor & 0x000000FF;
      WinReleasePS(shps);
      sprintf(szString,"Color: #%.2X%.2X%.2X",r,g,b);
      GpiCreateLogFont(hps, NULL, 1L, &fat);
      GpiSetCharSet(hps, 1L);
      GpiSetCharMode(hps, CM_MODE1);
      GpiCharStringAt( hps,&pt ,(LONG)strlen( szString ), szString );
      WinEndPaint( hps );                      /* Drawing is complete   */
      break;
      }
    case WM_CLOSE:
      WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/
      break;
    default:
      /*
       * Everything else comes here.  This call MUST exist
       * in your window procedure.
       */

      return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  }
  return (MRESULT)FALSE;
} /* End of MyWindowProc */
示例#15
0
void Draw_Thread(ULONG ulThreadArg)
{
if(!(habDT=WinInitialize(0UL)))         /* Initialize client window */
    GEN_ERR(habDT,hwndFrame,hwndClient);
                                        /* Create a message queue */
if(!(hmqDT=WinCreateMsgQueue(habDT,0UL)))
    GEN_ERR(habDT,hwndFrame,hwndClient);
if(!(hpsDT=WinGetPS(hwndClient)))       /* Get a presentation space for client area */
    GEN_ERR(habDT,hwndFrame,hwndClient);
                                        /* Initialize message queue */
WinPostQueueMsg(hmqDT,DT_PAINT,0UL,0UL);
while(qmsqDT.msg!=DT_EXIT)
    {
    if(WinPeekMsg(habDT,                /* Get the message into message queue */
    &qmsqDT,                            /* Message structure */
    NULLHANDLE,                         /* Window filter (none) */
    0UL,                                /* First message ID */
    0UL,                                /* Last message ID */
    PM_REMOVE)==FALSE)                  /* Options (remove message) */
        qmsqDT.msg=DT_IDLE;             /* If no message available, assume idle */
    switch(qmsqDT.msg)
    {
    case DT_PAINT:                      /* Repaint client window */
        {
        RECTL   rclDT;
        int     x,y;
                                        /* Repaint client window aread */
        WinQueryWindowRect(hwndClient,&rclDT);
        WinFillRect(hpsDT,&rclDT,CLR_WHITE);
        for(x=1;x<RB_X;x++)             /* Draw the entries on playing ground */
            for(y=1;y<RB_Y;y++)
                if(RB_Array[x][y]!=RB_EMPTY)
                    Draw_Bitmap(RB_Array[x][y],ROP_SRCCOPY,(x-1)*RB_SIZE,(y-1)*RB_SIZE);
        break;
        }
    case DT_LBUTTON:
        {
        int     x,y;
                                        /* Left button was pressed, get the location,
                                           add \ to RB_Array, and draw \ bitmap, if
                                           field is emty */
        x=(LONGFROMMP(qmsqDT.mp1)/RB_SIZE)+1;
        y=(LONGFROMMP(qmsqDT.mp2)/RB_SIZE)+1;
        if(RB_Array[x][y]==RB_EMPTY)
            {
            RB_Array[x][y]=RB_LX;
            Draw_Bitmap(RB_LX,ROP_SRCCOPY,(x-1)*RB_SIZE,(y-1)*RB_SIZE);
            }
        break;
        }
    case DT_RBUTTON:
        {
        int     x,y;
                                        /* Right button was pressed, get the location,
                                           add / to RB_Array, and draw / bitmap, if
                                           field is emty */
        x=(LONGFROMMP(qmsqDT.mp1)/RB_SIZE)+1;
        y=(LONGFROMMP(qmsqDT.mp2)/RB_SIZE)+1;
        if(RB_Array[x][y]==RB_EMPTY)
            {
            RB_Array[x][y]=RB_RX;
            Draw_Bitmap(RB_RX,ROP_SRCCOPY,(x-1)*RB_SIZE,(y-1)*RB_SIZE);
            }
        break;
        }
     case DT_IDLE:
        {
        if(runRB==TRUE)
            {
            ULONG       x,y,Symbol;
                                        /* Under DOS we would query the time in milliseconds
                                           from the system timer, to adjust graphics. This
                                           is accurate, but in a multitasking in a multitasking
                                           system, we must assume being pre-empted. Therefore
                                           we can't have an exact time bases. Hope that
                                           the system timer counts more often than all 31
                                           milliseconds in future releases/machines */
                                        /* Draw bitmap */
            switch(RB_Dir)              /* Test that RollBall doesn't leave borders. A
                                           border reverses the direction and produces a
                                           beep */
            {
            case UP:
                RB_PosY++;
                if((RB_PosY+RB_SIZE)>=((RB_Y-2)*RB_SIZE))
                    {
                    RB_PosY=(RB_Y-3)*RB_SIZE;
                    RB_Dir=DOWN;
                    DosBeep(800,50);
                    }
                break;
            case DOWN:
                RB_PosY--;
                if(RB_PosY<0)
                    {
                    RB_PosY=0;
                    RB_Dir=UP;
                    DosBeep(800,50);
                    }
                break;
            case LEFT:
                RB_PosX--;
                if(RB_PosX<0)
                    {
                    RB_PosX=0;
                    RB_Dir=RIGHT;
                    DosBeep(800,50);
                    }
                break;
            case RIGHT:
                RB_PosX++;
                if((RB_PosX+RB_SIZE)>=((RB_X-2)*RB_SIZE))
                    {
                    RB_PosX=(RB_X-3)*RB_SIZE;
                    RB_Dir=LEFT;
                    DosBeep(800,50);
                    }
                break;
            }
                                        /* Draw RollBall at new position */
            Draw_Bitmap(RB_RB,ROP_SRCCOPY,RB_PosX,RB_PosY);
                                        /* Now, test if the middle of RollBall is over any
                                           symbol. If a symbol is found, add points, deflect
                                           or end game */
                                        /* RB_Array is 1 based, because 0 indices are the
                                           playing ground borders */
            x=((RB_PosX)/RB_SIZE)+1;
            y=((RB_PosY)/RB_SIZE)+1;
                                        /* A Symbol if RB_SIZE*RB_SIZE in size, that means
                                           RollBall is exactly over a symbol, if the lower
                                           left edges of both symbols match. Then, and only
                                           then, we count points, deflect or loose */
            if((RB_PosX==(x-1)*RB_SIZE) && (RB_PosY==(y-1)*RB_SIZE))
                Symbol=RB_Array[x][y];
            else Symbol=RB_EMPTY;
            switch(Symbol)
            {
            case RB_LX:                 /* We got a \ deflector */
                {
                switch(RB_Dir)          /* \ deflects direction of RollBall */
                {
                case RIGHT:
                    RB_Dir=DOWN; break;
                case UP:
                    RB_Dir=LEFT; break;
                case LEFT:
                    RB_Dir=UP; break;
                case DOWN:
                    RB_Dir=RIGHT; break;
                }                       /* Remove deflector */
                RB_Array[x][y]=RB_EMPTY;
                break;
                }
            case RB_RX:                 /* We got a / deflector */
                {
                switch(RB_Dir)          /* / deflects direction of RollBall */
                {
                case RIGHT:
                    RB_Dir=UP; break;
                case UP:
                    RB_Dir=RIGHT; break;
                case LEFT:
                    RB_Dir=DOWN; break;
                case DOWN:
                    RB_Dir=LEFT; break;
                }                       /* Remove deflector */
                RB_Array[x][y]=RB_EMPTY;
                DosBeep(600,20);
                break;
                }
            case RB_BP:                 /* We got a point */
            case RB_GP:
            case RB_MP:
            case RB_VP:
                {                       /* Add the points for each symbol */
                RB_Point[0]+=RB_Point[Symbol];
                                        /* Remove the point */
                RB_Array[x][y]=RB_EMPTY;
                if (ulDelay)
                    ulDelay--;
                DosBeep(700,20);
                break;
                }
            case RB_HOLE:               /* We got a hole, sorry but RollBall will be killed.
                                           We disable RollBall from rolling, and send a 
                                           ID_STOPTHREAD message to our window, which
                                           informs the user about the points with a message
                                           box */
                {
                int     freq;
                for(freq=5000;freq>100;freq-=100) DosBeep(freq,5);
                runRB=FALSE;            /* Prevent RollBall from further rolling */
                WinPostMsg(hwndClient,WM_COMMAND,(MPARAM)ID_STOPTHREAD,(MPARAM)0);
                break;
                }
            }
                                        /* Randomly add and remove symbols on playing ground */
            if((rand()%500)<2)
                {
                Put_Random_Field();
                Clear_Random_Field();
                }
            }
        }
    }
DosOpen("TIMER0$",
        &hfile,
        &ulAction,
        0,
        0,
        OPEN_ACTION_OPEN_IF_EXISTS,
        OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
        NULL);   
ulDelay2=ulDelay/2;
DosDevIOCtl(hfile,
            HRT_IOCTL_CATEGORY,
            HRT_BLOCKUNTIL,
            &ulDelay2,
            ulSize2,
            &ulSize2,
            NULL,
            0,
            NULL);
DosClose(hfile);
}
WinReleasePS(hpsDT);                    /* Clean up */
WinDestroyMsgQueue(hmqDT);
WinTerminate(habDT);
DosExit(EXIT_THREAD,0UL);
}
示例#16
0
MRESULT EXPENTRY DirDialogProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
{
   switch ( msg ) {
      case WM_INITDLG:
         {
         SWP swpFileST;
         SWP swpDirST;
         SWP swpDirLB;
         SWP swpDriveST;
         SWP swpDriveCB;
         SWP swpDriveCBEF;
         SWP swpOK;
         SWP swpCancel;
         HWND hwndFileST;
         HWND hwndDirST;
         HWND hwndDirLB;
         HWND hwndDriveST;
         HWND hwndDriveCB;
         HWND hwndOK;
         HWND hwndCancel;
         HENUM henum;
         HWND hwndNext;
         ULONG ulCurY, ulCurX;
         LONG lScreenX, lScreenY, lDlgFrameX, lDlgFrameY, lTitleBarY;

         lScreenX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
         lScreenY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
         lDlgFrameX = WinQuerySysValue(HWND_DESKTOP, SV_CXDLGFRAME);
         lDlgFrameY = WinQuerySysValue(HWND_DESKTOP, SV_CYDLGFRAME);
         lTitleBarY = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);

         hwndFileST = WinWindowFromID(hwndDlg, DID_FILENAME_TXT);
         hwndDirST = WinWindowFromID(hwndDlg, DID_DIRECTORY_TXT);
         hwndDirLB = WinWindowFromID(hwndDlg, DID_DIRECTORY_LB);
         hwndDriveST = WinWindowFromID(hwndDlg, DID_DRIVE_TXT);
         hwndDriveCB = WinWindowFromID(hwndDlg, DID_DRIVE_CB);
         hwndOK = WinWindowFromID(hwndDlg, DID_OK);
         hwndCancel = WinWindowFromID(hwndDlg, DID_CANCEL);
         
#define SPACING 10
         // Reposition drives combobox
         ulCurY = SPACING;
         ulCurX = SPACING + lDlgFrameX;
         WinQueryWindowPos(hwndOK, &swpOK);
         WinSetWindowPos(hwndOK, 0, ulCurX, ulCurY, 0, 0, SWP_MOVE);
         ulCurY += swpOK.cy + SPACING;
         WinQueryWindowPos(hwndCancel, &swpCancel);
         WinSetWindowPos(hwndCancel, 0, ulCurX+swpOK.cx+10, SPACING, 0, 0, SWP_MOVE);
         WinQueryWindowPos(hwndDirLB, &swpDirLB);
         WinSetWindowPos(hwndDirLB, 0, ulCurX, ulCurY, swpDirLB.cx, swpDirLB.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpDirLB.cy + SPACING;
         WinQueryWindowPos(hwndDirST, &swpDirST);
         WinSetWindowPos(hwndDirST, 0, ulCurX, ulCurY, swpDirST.cx, swpDirST.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpDirST.cy + SPACING;
         WinQueryWindowPos(hwndDriveCB, &swpDriveCB);
         WinQueryWindowPos(WinWindowFromID(hwndDriveCB, CBID_EDIT), &swpDriveCBEF);
         WinSetWindowPos(hwndDriveCB, 0, ulCurX, ulCurY-(swpDriveCB.cy-swpDriveCBEF.cy)+5,
                                         swpDirLB.cx,
                                         swpDriveCB.cy,
                                         SWP_SIZE | SWP_MOVE);
         ulCurY += swpDriveCBEF.cy + SPACING;
         WinQueryWindowPos(hwndDriveST, &swpDriveST);
         WinSetWindowPos(hwndDriveST, 0, ulCurX, ulCurY, swpDriveST.cx, swpDriveST.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpDriveST.cy + SPACING;
         WinQueryWindowPos(hwndFileST, &swpFileST);
         WinSetWindowPos(hwndFileST, 0, ulCurX, ulCurY, swpFileST.cx, swpFileST.cy, SWP_MOVE | SWP_SIZE);
         ulCurY += swpFileST.cy + SPACING;

         // Hide unused stuff
         henum = WinBeginEnumWindows(hwndDlg);
         while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)
         {
           USHORT usID = WinQueryWindowUShort(hwndNext, QWS_ID);
           if (usID != DID_FILENAME_TXT &&
               usID != DID_DIRECTORY_TXT &&
               usID != DID_DIRECTORY_LB &&
               usID != DID_DRIVE_TXT &&
               usID != DID_DRIVE_CB &&
               usID != DID_OK &&
               usID != DID_CANCEL &&
               usID != FID_TITLEBAR &&
               usID != FID_SYSMENU &&
               usID != FID_MINMAX) 
           {
             WinShowWindow(hwndNext, FALSE);
           }
         }

         WinSetWindowPos(hwndDlg,
                         HWND_TOP,
                         (lScreenX/2)-((swpDirLB.cx+2*SPACING+2*lDlgFrameX)/2),
                         (lScreenY/2)-((ulCurY+2*lDlgFrameY+lTitleBarY)/2),
                         swpDirLB.cx+2*SPACING+2*lDlgFrameX,
                         ulCurY+2*lDlgFrameY+lTitleBarY,
                         SWP_MOVE | SWP_SIZE);
         }
         break;
      case WM_CONTROL:
         {
         PFILEDLG pfiledlg;
         pfiledlg = (PFILEDLG)WinQueryWindowPtr(hwndDlg, QWL_USER);

         HPS           hps;
         SWP           swp;
         HWND          hwndST;
         RECTL         rectlString = {0,0,1000,1000};
         char          *ptr = NULL;
         int           iHalfLen;
         int           iLength;
         CHAR          szString[CCHMAXPATH];

         hwndST = WinWindowFromID(hwndDlg, DID_FILENAME_TXT);
       
         strcpy(szString, pfiledlg->szFullFile);
         iLength = strlen(pfiledlg->szFullFile);
         /* If we are not just a drive */
         if (iLength > 3) {
           if (szString[iLength-1] == '\\') {
             szString[iLength-1] = '\0';
             iLength--;
           }
         }
       
         hps = WinGetPS(hwndST);
         WinQueryWindowPos(hwndST, &swp);
       
         WinDrawText(hps, iLength, szString,
                          &rectlString, 0, 0, 
                          DT_BOTTOM | DT_QUERYEXTENT | DT_TEXTATTRS);
         while(rectlString.xRight > swp.cx)
         {
           iHalfLen = iLength / 2;
           if(iHalfLen == 2)
             break;
       
           ptr = szString + iHalfLen;
           memmove(ptr - 1, ptr, strlen(ptr) + 1);
           szString[iHalfLen - 2] = '.';
           szString[iHalfLen - 1] = '.';
           szString[iHalfLen]     = '.';
           iLength = strlen(szString);
           rectlString.xLeft = rectlString.yBottom = 0;
           rectlString.xRight = rectlString.yTop = 1000;
           WinDrawText(hps, iLength, szString,
                       &rectlString, 0, 0, 
                       DT_BOTTOM | DT_QUERYEXTENT | DT_TEXTATTRS);
         }
       
         WinReleasePS(hps);
         WinSetWindowText(hwndST, szString);
         }
         break;
   }      
   return WinDefFileDlgProc(hwndDlg, msg, mp1, mp2);
}
示例#17
0
void    _CreateFont( LPWDATA w ) {
//===============================

    LONG                cFonts = { 0 };
    LONG                num_fonts;
    FONTMETRICS *       fonts;
    int                 i;
    unsigned            font_size;
    unsigned            font_selected;
    HPS                 ps;
#ifdef _MBCS
    int                 fontChosenFlag = 0;
#endif

    /*** Prepare to search for a suitable console font ***/
    ps = WinGetPS( w->hwnd );
    num_fonts = GpiQueryFonts( ps, QF_PUBLIC, NULL, &cFonts,
                               sizeof( FONTMETRICS ), NULL );
    fonts = _MemAlloc( num_fonts * sizeof( FONTMETRICS ) );
    GpiQueryFonts( ps, QF_PUBLIC, NULL, &num_fonts, sizeof( FONTMETRICS ),
                   fonts );
    font_size = UINT_MAX;
    font_selected = 0;

    #ifdef _MBCS
        if( __IsDBCS ) {
            /*** Try to find a DBCS font ***/
            for( i = 0; i < num_fonts; ++i ) {
                if( ! (fonts[i].fsType & (FM_TYPE_DBCS|FM_TYPE_FIXED)) )  continue;
                if( fonts[i].lEmHeight > 10 )  continue;
                font_size = fonts[i].lEmHeight;
                font_selected = i;
                fontChosenFlag = 1;
                break;
            }
            /*** Try to find a regular font if can't find DBCS ***/
            if( fontChosenFlag == 0 ) {
                for( i = 0; i < num_fonts; ++i ) {
                    if( ! (fonts[i].fsType & FM_TYPE_DBCS) )  continue;
                    if( fonts[i].lEmHeight > 10 )  continue;
                    font_size = fonts[i].lEmHeight;
                    font_selected = i;
                    fontChosenFlag = 1;
                    break;
                }
            }
        }

        /*** If !__IsDBCS or if DBCS font not found, find a fixed font ***/
        if( fontChosenFlag == 0 ) {
            for( i = 0; i < num_fonts; ++i ) {
                if( ! (fonts[i].fsType & FM_TYPE_FIXED) )  continue;
                if( fonts[i].lEmHeight > 10 )  continue;
                font_size = fonts[i].lEmHeight;
                font_selected = i;
                break;
            }
        }
    #else
        /*** Try to find a suitable font ***/
        for( i = 0; i < num_fonts; ++i ) {
            if( ! (fonts[i].fsType & FM_TYPE_FIXED) )  continue;
            if( fonts[i].lEmHeight > 10 )  continue;
            font_size = fonts[i].lEmHeight;
            font_selected = i;
            break;
        }
    #endif

    /*** Set up the chosen font ***/
    FontAttrs.usRecordLength = sizeof( FATTRS );
    FontAttrs.fsSelection = 0;
    FontAttrs.lMatch = fonts[font_selected].lMatch;
    strcpy( FontAttrs.szFacename, fonts[font_selected].szFacename );
    FontAttrs.idRegistry = fonts[font_selected].idRegistry;
    FontAttrs.usCodePage = 0;
    FontAttrs.lMaxBaselineExt = 0;
    FontAttrs.lAveCharWidth = 0;
    FontAttrs.fsType = 0;
    FontAttrs.fsFontUse = 0;
    w->xchar = fonts[font_selected].lAveCharWidth;
    w->ychar = fonts[font_selected].lMaxBaselineExt + SPACE_BETWEEN_LINES;
    w->base_offset = fonts[font_selected].lMaxDescender;
    _MemFree( fonts );
    WinReleasePS( ps );
}
示例#18
0
MRESULT EXPENTRY stlrTitleBarProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) {
   PSTLRFRAME p;
   /* -------------------------------------------------------------------
    window creation :
    store the handle of the owner window, the initial titlebar size,
    convert the title substituting \r\n with 1 space, update the titlebar
    font
   ------------------------------------------------------------------- */
   if (msg == WM_CREATE) {
      // if this is a global exception window, if the window ID is not
      // FID_TITLEBAR or if the owner window is not a frame, go to the
      // default system titlebar procedure
      if (!pd.ppib
          || (((PCREATESTRUCT)mp2)->id != FID_TITLEBAR)
          || !_isFrameWindow(((PCREATESTRUCT)mp2)->hwndOwner))
         goto defaultTitlebarProcedure;
      // get the frame data
      p = (PSTLRFRAME)WinQueryWindowPtr(((PCREATESTRUCT)mp2)->hwndOwner,
                                        g.cd.frame.cbData);
//      /*-*/ dbgPrintf5("*** pd.ppib:%08x, id: %04x, isOwnerFrame: %d, p: %08x\n",
//                       pd.ppib, ((PCREATESTRUCT)mp2)->id,
//                       _isFrameWindow(((PCREATESTRUCT)mp2)->hwndOwner), p);
      // if the frame window is a win32frame initialize the frame data now
      if (!p
          || ((p == FL_WIN32FRAME)
              && (NULL
                  == (p = _initWin32Frame(((PCREATESTRUCT)mp2)->hwndOwner)))))
         goto defaultTitlebarProcedure;
      // memorizza handle frame window
      WinSetWindowPtr(hwnd, g.cd.tbar.cbData, p);
      p->hTBar = hwnd;
      if (((PCREATESTRUCT)mp2)->pszText)
         p->cchTxt = psznconvcpy(p->achTxt, ((PCREATESTRUCT)mp2)->pszText, 260);
      p->wrclTitle.x = ((PCREATESTRUCT)mp2)->x;
      p->wrclTitle.y = ((PCREATESTRUCT)mp2)->y;
      p->wrclTitle.cx = ((PCREATESTRUCT)mp2)->cx;
      p->wrclTitle.cy = ((PCREATESTRUCT)mp2)->cy;
      // cambia font secondo preferenze
      if (o.tb.on && !(o.gen.disabled || pd.we.tbar))
         _setPPFont(hwnd, o.tb.achFont);

   /* -------------------------------------------------------------------
    hiliting/unhiliting of the titlebar :
    store the handle of the owner window, the initial titlebar size,
    convert the title substituting \r\n with 1 space, update the titlebar
    font
   ------------------------------------------------------------------- */
   } else if (msg == TBM_SETHILITE) {
      if (_getFrameData(hwnd, p)) {
         p->is.tbhilited = (BOOL)mp1;
         if (!o.gen.disabled && o.tb.on && !pd.we.tbar) {
            if (o.tb.ovrPP
                || (p->is.tbhilited && !p->is.tbactpp)
                || !(p->is.tbhilited || p->is.tbictpp)) {
               if (WinIsWindowShowing(hwnd)) {
                  p->hps = WinGetPS(hwnd);
                  DrawTitlebar(p);
                  WinReleasePS(p->hps);
               } /* endif */
               return (MRESULT)TRUE;
            // Š solo apparentemente ridondante, in realt… Š necessario quando
            // non Š ovrPP ed Š presente solo PP att. o inatt.
            } else if (!(p->is.tbactpp && p->is.tbictpp)) {
               repaintWindow(hwnd);
            } /* endif */
         } /* endif */
      } /* endif */

   /* -------------------------------------------------------------------
    titlebar font/color changed
    - if the font changed repaint the window
    - if any color changed reset the presparm presence flag
   ------------------------------------------------------------------- */
   } else if (msg == WM_PRESPARAMCHANGED) {
      if (!pd.we.tbar && _getFrameData(hwnd, p)) {
         ULONG ul;
         switch ((LONG)mp1) {
            case PP_FONTNAMESIZE:
               p->cyfont = 0;
               if (o.gen.disabled) break;
               if (WinIsWindowShowing(hwnd)) repaintWindow(hwnd);
               return (MRESULT)FALSE;
            case PP_ACTIVETEXTBGNDCOLOR:
            case PP_ACTIVETEXTBGNDCOLORINDEX:
            case PP_ACTIVECOLOR:
            case PP_ACTIVECOLORINDEX:
               p->is.tbactpp = _getPPColor(hwnd, (ULONG)mp1, &ul) != 0;
               break;
            case PP_INACTIVETEXTBGNDCOLOR:
            case PP_INACTIVETEXTBGNDCOLORINDEX:
            case PP_INACTIVECOLOR:
            case PP_INACTIVECOLORINDEX:
               p->is.tbictpp = _getPPColor(hwnd, (ULONG)mp1, &ul) != 0;
               break;
         } /* endswitch */
      } /* endif */

   /* -------------------------------------------------------------------
    the titlebar text changed. If this is a Win-OS/2 window set the
    window words to 0 so that the enhancements are skipped, otherwise
    store the new text.
   ------------------------------------------------------------------- */
   } else if (msg == WM_SETWINDOWPARAMS) {
      if (!pd.we.tbar && _getFrameData(hwnd, p)) {
         // unsubclass winOS2 windows titlebars
         if (p->is.winos2) {
            _resetDefaultProc(hwnd);
//            WinSetWindowULong(hwnd, g.cd.tbar.cbData, 0);
         } else {
            if ((PWNDPARAMS)mp1 &&
                (((PWNDPARAMS)mp1)->fsStatus & WPM_TEXT) &&
                ((PWNDPARAMS)mp1)->pszText) {
               p->cchTxt = psznconvcpy(p->achTxt, ((PWNDPARAMS)mp1)->pszText, 260);
               p->cyfont = 0;
            } /* endif */
         } /* endif */
      } /* endif */

   /* -------------------------------------------------------------------
    titlebar size/position changed : store new size and position
   ------------------------------------------------------------------- */
   } else if (msg == WM_WINDOWPOSCHANGED) {
      if ((((PSWP)mp1)->fl & (SWP_SIZE | SWP_MOVE))
          && _getFrameData(hwnd, p)) {
         p->wrclTitle.x = ((PSWP)mp1)->x;
         p->wrclTitle.y = ((PSWP)mp1)->y;
         p->wrclTitle.cx = ((PSWP)mp1)->cx;
         p->wrclTitle.cy = ((PSWP)mp1)->cy;
      } /* endif */

// **************************************************************************
// these messages are processed only if Styler/2 is not disabled:

   } else if (!o.gen.disabled) {

   /* -------------------------------------------------------------------
    check if this is the roll-the-window mouse event :
   ------------------------------------------------------------------- */
      if ((msg == o.roll.moumsg) && (SHORT2FROMMP(mp2) == o.roll.moukbd)) {
         if (!pd.we.wroll
             && o.roll.mou
             && _getFrameData(hwnd, p)
             && !p->is.win32
             && (o.roll.on || p->is.RLon)) {
            toggleRollCmd(p->hwnd, p);
            return (MRESULT)TRUE;
         } /* endif */

   /* -------------------------------------------------------------------
    check if this is the hide-titlebar mouse event :
   ------------------------------------------------------------------- */
      } else if ((msg == o.tbh.moumsg) && (SHORT2FROMMP(mp2) == o.tbh.moukbd)) {
         if (!pd.we.tbarhide
             && o.tbh.mou
             && _getFrameData(hwnd, p)
             && !p->is.win32
      // opzione titlehide attiva e non dialogo o disattivazione titlehide
             && ((o.tbh.on && !(p->is.dialog && o.tbh.noDlg)) || p->is.titleHide)) {
            toggleTitleBarHidingCmd(p->hwnd, p);
            return (MRESULT)TRUE;
         } /* endif */

   /* -------------------------------------------------------------------
    check if this is the change-Zorder mouse event :
   ------------------------------------------------------------------- */
      } else if ((msg == o.sizpos.ZordMoumsg)
                 && (SHORT2FROMMP(mp2) == o.sizpos.ZordMoukbd)) {
         if (!pd.we.sizemove
             && o.sizpos.Zmove
             && _getFrameData(hwnd, p)) {
            _stlrMsgPost(p->hwnd, STLR_ZORDACTIV, SW2_SFMOVETOBOTTOM);
            return (MRESULT)TRUE;
         } /* endif */

   /* -------------------------------------------------------------------
    check if this is the snap-to-screen-edge mouse event :
   ------------------------------------------------------------------- */
      } else if ((msg == o.sizpos.snapMoumsg)
                 && (SHORT2FROMMP(mp2) == o.sizpos.snapMoukbd)) {
         if (!pd.we.sizemove
             && o.sizpos.snap
             && _getFrameData(hwnd, p)) {
            // get the rectangle of the window and of its parent
            RECTL r, rParent;
            WinQueryWindowRect(p->hwnd, &r);
            WinQueryWindowRect(_winParent(p->hwnd), &rParent);
            // click on the left side of the titlebar
            if (MOUSEX(mp1) < (p->wrclTitle.cx / 3)) {
               r.xLeft = -p->ptBrd.x;
            // click on the right side of the titlebar
            } else if (MOUSEX(mp1) > (p->wrclTitle.cx * 2 / 3)) {
               r.xLeft = rParent.xRight - r.xRight + p->ptBrd.x;
            // click on the (horizontal) middle of the titlebar
            } else {
               r.xLeft = (rParent.xRight - r.xRight) / 2;
            } /* endif */
            // click on the bottom of the titlebar
            if (MOUSEY(mp1) < (g.sys.cyTbar / 3)) {
               r.yBottom = -p->ptBrd.y;
            // click on the top of the titlebar
            } else if (MOUSEY(mp1) > (g.sys.cyTbar * 2 / 3)) {
               r.yBottom = rParent.yTop - r.yTop + p->ptBrd.y;
            // click on the (vertical) middle of the titlebar
            } else {
               r.yBottom = (rParent.yTop - r.yTop) / 2;
            } /* endif */
            WinSetWindowPos(p->hwnd, 0, r.xLeft, r.yBottom, 0, 0,
                            SWP_MOVE | SWP_NOADJUST);
         } /* endif */

   /* -------------------------------------------------------------------
    enhanced window painting
   ------------------------------------------------------------------- */
      } else if (msg == WM_PAINT) {
         if (!pd.we.tbar
             && o.tb.on
             && _getFrameData(hwnd, p)
             && (o.tb.ovrPP || (p->is.tbhilited && !p->is.tbactpp)
                 || !(p->is.tbhilited || p->is.tbictpp))) {
            p->hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
            DrawTitlebar(p);
            WinEndPaint(p->hps);
            return (MRESULT)FALSE;
         } /* endif */

   /* -------------------------------------------------------------------
    override the default window tracking :
   ------------------------------------------------------------------- */
      } else if ((msg == WM_BUTTON1DOWN) || (msg == WM_BUTTON2DOWN)) {
         if (_getFrameData(hwnd, p)) {
            // override window motion by titlebar drag :
            // store the current mouse position (mp1)
            // the window motion will start only when the mouse will move
            g.tbdrag.mpPos = mp1;
            // if the window is not already moving store which mouse button
            // has to be released to stop the titlebar drag
            if (!g.tbdrag.hwnd) g.tbdrag.msg = ++msg;
            // store the handle of the titlebar (mouse motion events are not
            // processed when this is NULLHANDLE)
            g.tbdrag.hwnd = hwnd;
            // cattura i msg successivi del mouse
            WinSetCapture(HWND_DESKTOP, hwnd);
            return (MRESULT)TRUE;
         } /* endif */

   /* -------------------------------------------------------------------
    terminate window motion through titlebar drag events :
   ------------------------------------------------------------------- */
      } else if ((msg == WM_BUTTON1UP) || (msg == WM_BUTTON2UP)) {
         if ((g.tbdrag.hwnd == hwnd)
              && (g.tbdrag.msg == msg)
              && _getFrameData(hwnd, p)) {
            HWND hwndParent;
            WinSetCapture(HWND_DESKTOP, NULLHANDLE);
            g.tbdrag.msg = 0;
            g.tbdrag.hwnd = NULLHANDLE;
            // if the Ctrl key is not pressed and the window is not yet active
            // end the window is a size-move feature exception or the event
            // is not related to the Z-order motion feature or the snap-to-
            // parent-edge feature activate the window bringing it to the top
            if (!(SHORT2FROMMP(mp2) & KC_CTRL)
                && (g.hwnd.active != p->hwnd)
                && (pd.we.sizemove
                    || (!(o.sizpos.Zmove
                          && (msg == (o.sizpos.ZordMoumsg - 0x3a1))
                          && (SHORT2FROMMP(mp2) == o.sizpos.ZordMoukbd))
                        && (!(o.sizpos.snap
                          && (msg == (o.sizpos.snapMoumsg - 0x3a1))
                          && (SHORT2FROMMP(mp2) == o.sizpos.snapMoukbd))))))
               WinSetWindowPos(p->hwnd, HWND_TOP, 0, 0, 0, 0,
                               SWP_ACTIVATE | SWP_ZORDER);
         } /* endif */

   /* -------------------------------------------------------------------
    open the system menu on the titlebar :
   ------------------------------------------------------------------- */
      } else if (msg == WM_CONTEXTMENU) {
         if (!pd.we.tbar
             && o.tb.menu
             && _getFrameData(hwnd, p)) {
            // if this is the titlebar of a WPS folder simulate a context
            // menu event on the client window
            if (p->is.folder) {
               p->hClient = WinWindowFromID(p->hwnd, FID_CLIENT);
               WinPostMsg(p->hClient, WM_CONTEXTMENU,
                          (MPARAM)0x7fff7fff, MPVOID);
            // otherwise get the handle of the system menu and bring it to
            // the top via WinPopupMenu()
            } else if (p->hSMenu) {
               POINTL ptl;
               WinQueryPointerPos(g.hwnd.desktop, &ptl);
               g.cd.menu.pfnwp(p->hSMenu, MM_QUERYITEM,
                               (MPARAM)SC_SYSMENU, MPFROMP(&p->mi));
               g.hwnd.sysMenu = p->mi.hwndSubMenu;
               WinPopupMenu(g.hwnd.desktop, p->hSMenu, g.hwnd.sysMenu,
                            ptl.x, ptl.y, 0, PU_HCONSTRAIN | PU_VCONSTRAIN |
                            PU_NONE | PU_KEYBOARD | PU_MOUSEBUTTON1);
            } /* endif */
         } /* endif */
         return (MRESULT)TRUE;

   /* -------------------------------------------------------------------
    trap WM_MOUSEMOVE to implement various features :
    - do not move maximized windows
   ------------------------------------------------------------------- */
      } else if (msg == WM_MOUSEMOVE) {
         // if mouse button 1 or 2 were pressed and then the mouse position
         // changed
         if ((g.tbdrag.hwnd == hwnd)
             && (g.tbdrag.mpPos != mp1)
             && _getFrameData(hwnd, p)) {
            WinSetCapture(HWND_DESKTOP, NULLHANDLE);
            g.tbdrag.hwnd = NULLHANDLE;
            g.tbdrag.msg = 0;
            // if this is a maximized window and the don't-move-max-window
            // feature is set ignore the event
            if (o.maxwin.nomove
                && p->is.max
                && !(pd.we.maxwin || p->is.shield || p->is.ovrdnomovemax))
               return (MRESULT)TRUE;
            WinSendMsg(p->hwnd, WM_TRACKFRAME, (MPARAM)TF_MOVE, g.tbdrag.mpPos);
            // ???????????????????????????????
            // this is needed because the next WM_BUTTONxUP is captured by
            // the WM_TRACKFRAME processing
//            if (!(SHORT2FROMMP(mp2) & KC_CTRL))
//               WinSetWindowPos(p->hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
            return (MRESULT)TRUE;
         } else if (g.is.onctrl != OCTLTBAR) {
            g.is.onctrl = OCTLTBAR;
            // ??????????????? this should be redundant
//            _resetHideMouTimer();
         } /* endif */
      } /* endif */
   // -------------------------------------------------------------------
   } /* endif */

defaultTitlebarProcedure:
   return g.cd.tbar.pfnwp(hwnd, msg, mp1, mp2);
}
示例#19
0
/*
 * _DisplayLineInWindowWithColor - as it sounds!
 */
void _DisplayLineInWindowWithColor( LPWDATA w, int line, LPSTR text, int c1,
                        int c2, int extra, int startcol )
{
  #ifdef _MBCS
    LPBYTE          tmp;
  #else
    LPSTR           tmp;
  #endif
    char            buff[256];
    int             start,end,a,spend,cnt1,cnt2;
    WORD            i;
    HWND            hwnd;

    hwnd = w->hwnd;

    /*** Find dimensions of line ***/
  #ifdef _MBCS
    tmp = FAR_mbsninc( (LPBYTE)text, startcol );
    a = FAR_mbslen( tmp );
    if( line < 1 || line >= w->height )
        return;
    start = 0;
    spend = end = w->width - extra;
    if( end > a )
        end = a;
    cnt1 = FAR_mbsnbcnt( tmp, end - start );
    cnt2 = spend - end;
    FAR_mbsnbcpy( (LPBYTE)buff, tmp, cnt1 - start );
    FARmemset( buff + cnt1, ' ', cnt2 );
    tmp = FAR_mbsninc( (LPBYTE)buff, cnt1 + cnt2 );
    *tmp = '\0';
  #else
    tmp = text;
    tmp += startcol;
    a = FARstrlen( tmp );
    if( line < 1 || line >= w->height )
        return;
    start = 0;
    spend = end = w->width - extra;
    if( end > a )
        end = a;
    cnt1 = end - start;
    cnt2 = spend - end;
    FARmemcpy( buff, tmp, cnt1 );
    FARmemset( buff + cnt1, ' ', cnt2 );
    buff[cnt1 + cnt2] = 0;
  #endif
    line--;

#if defined( __OS2__ )
    {
        RECTL           rcl;
        HPS             ps;
        POINTL          ptl;
        POINTL          points[TXTBOX_COUNT];

        ptl.x = 0;
        ptl.y = (w->y2 - w->y1) - (line+1)*w->ychar + w->base_offset;
        ps = WinGetPS( hwnd );
        _SelectFont( ps );
        GpiQueryTextBox( ps, startcol, w->tmpbuff->data, TXTBOX_COUNT, points );
        rcl.xLeft = points[TXTBOX_BOTTOMRIGHT].x;
    #ifdef _MBCS
        GpiQueryTextBox( ps, __mbslen( (unsigned char *)buff ), buff, TXTBOX_COUNT, points );
    #else
        GpiQueryTextBox( ps, strlen( buff ), buff, TXTBOX_COUNT, points );
    #endif
        rcl.xRight = points[TXTBOX_BOTTOMRIGHT].x;
        rcl.yTop = (w->y2 - w->y1) - line*w->ychar;
        rcl.yBottom = rcl.yTop - w->ychar;
        WinFillRect( ps, &rcl, c1 );
        GpiSetColor( ps, c2 );
    #ifdef _MBCS
        GpiCharStringAt( ps, &ptl, _mbsnbcnt(buff,w->width), buff );
    #else
        GpiCharStringAt( ps, &ptl, w->width, buff );
    #endif
        WinReleasePS( ps );
    }
#else
    {
        HDC     dc;
//      SIZE    size;
//      RECT    rect;

        dc = GetDC( hwnd );
        _SetMyDC( dc, _ColorMap[c2], _ColorMap[c1] );
//      #ifdef __NT__
//          GetTextExtentPoint32( dc, buff, strlen(buff), &size );
//      #else
//          GetTextExtentPoint( dc, buff, strlen(buff), &size );
//      #endif
//
    #ifdef _MBCS
        TextOut( dc, 0, line * w->ychar, (LPSTR)buff, FAR_mbsnbcnt( (LPBYTE)buff, w->width ) );
    #else
        TextOut( dc, 0, line * w->ychar, buff, w->width );
    #endif

        /*** Clear to end of line to remove any residue ***/
//      GetClientRect( w->hwnd, &rect );
//      rect.top = line * w->ychar;
//      rect.bottom = (line+1) * w->ychar ;
//      rect.left = size.cx;
//      FillRect( dc, &rect, w->brush );
        ReleaseDC( hwnd, dc );
    }
#endif

    /*** Update the w->image array ***/
#ifdef _MBCS
    {
        mb_char         mbc;
        unsigned char   *curMbc;
        int             count;

        i = line * w->width + startcol;
        for( count = 0, curMbc = (unsigned char *)buff; count < w->width - startcol; count++ ) {
            mbc = _mbsnextc( curMbc );          /* get the character */
            curMbc = _mbsinc( curMbc );         /* point to next char */
            w->image[i + count] = mbc;          /* store it in w->image */
        }
    }
#else
    i = line * w->width + startcol;
    FARmemcpy( &w->image[i], buff, w->width - startcol );
#endif
} /* _DisplayLineInWindowWithColor */
MRESULT EXPENTRY newProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{

  switch (msg)
    {      
    case WM_CREATE:
      {
        PCREATESTRUCT pCreate=PVOIDFROMMP(mp2);

        /* Initialize the slider data */
        WinSetWindowUShort(hwnd, SLIDERARMWITH,20);
        WinSetWindowUShort(hwnd, SLIDERARMHEIGHT,10);
        /* Dimensions of slider. The slider active area is smaller than the window to
           allow drawing of active state. */
        WinSetWindowULong(hwnd, SLIDERCX,pCreate->cx-4);
        WinSetWindowULong(hwnd, SLIDERCY,pCreate->cy-4);
        WinSetWindowULong(hwnd, SLIDERX,2);
        WinSetWindowULong(hwnd, SLIDERY,2);
        WinSetWindowULong(hwnd, SLIDERARMPOS, 0);
        WinSetWindowULong(hwnd, SLDRAGGING,FALSE);
        return (MRESULT)0;
      }
    case WM_SIZE:
      WinSetWindowULong(hwnd, SLIDERCX, SHORT1FROMMP(mp2)-4);
      WinSetWindowULong(hwnd, SLIDERCY, SHORT2FROMMP(mp2)-4);
      WinInvalidateRect(hwnd, NULLHANDLE,TRUE);
      return (MRESULT)0;
    case WM_BUTTON1DOWN:
      {
        SHORT x=SHORT1FROMMP( mp1);
        SHORT y=SHORT2FROMMP( mp1);
        LONG  lPos=WinQueryWindowULong(hwnd, SLIDERARMPOS);
        USHORT usWidth=WinQueryWindowUShort(hwnd, SLIDERARMWITH);

        if(x<lPos+usWidth && y<WinQueryWindowUShort(hwnd, SLIDERY)+WinQueryWindowUShort(hwnd, SLIDERCY)
           && y>WinQueryWindowUShort(hwnd, SLIDERY)) {
          WinSetWindowUShort(hwnd, PTRPOSINSLARM, x-lPos);
        }
        WinSetFocus(HWND_DESKTOP, hwnd);
      break;
      }
    case WM_FOCUSCHANGE:
      {
        HPS hps;
        RECTL rcl;
        POINTL ptl;

        if(SHORT1FROMMP(mp2)) {
          hps=WinGetPS(hwnd);
          WinQueryWindowRect(hwnd, &rcl);        
          GpiSetLineType(hps, LINETYPE_DOT);
          ptl.x=rcl.xLeft;
          ptl.y=rcl.yBottom;
          GpiMove(hps,&ptl);
          ptl.x=rcl.xRight-1;
          GpiLine(hps,&ptl);
          ptl.y=rcl.yTop-1;
          GpiLine(hps,&ptl);
          ptl.x=rcl.xLeft;
          GpiLine(hps,&ptl);
          ptl.y=rcl.yBottom;
          GpiLine(hps,&ptl);
          WinReleasePS(hps);
        }
        else {
          WinInvalidateRect(hwnd, NULLHANDLE,TRUE);
        }

        break;
      }
    case WM_CHAR:
      if(WinQueryFocus(HWND_DESKTOP)==hwnd) {
        /* We have the focus */
        if((SHORT1FROMMP(mp1) & (KC_VIRTUALKEY))==(KC_VIRTUALKEY)) {
          LONG  lPos=WinQueryWindowULong(hwnd, SLIDERARMPOS);
          USHORT usWidth=WinQueryWindowUShort(hwnd, SLIDERARMWITH);
          ULONG ulCx=WinQueryWindowULong(hwnd, SLIDERCX);
#if 0
          FILE* file;
          file=fopen("d:\\md.log","a");
          fprintf(file,"0x%x 0x%x \n",SHORT1FROMMP(mp1),SHORT2FROMMP(mp1) );
          fclose(file);
#endif
          /*(KC_KEYUP|KC_PREVDOWN|KC_VIRTUALKEY)*/
          switch(SHORT2FROMMP(mp2))
            {
            case VK_RIGHT:

              if(SHORT1FROMMP(mp1) & (KC_KEYUP|KC_PREVDOWN)) {
                lPos+=2;
                if(lPos>ulCx-usWidth)
                  lPos=ulCx-usWidth;
                else {
                  WinPostMsg( hwnd,
                              SLM_SETSLIDERINFO,
                              MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE),
                              MPFROMLONG( (LONG) lPos ));
                  if(SHORT1FROMMP(mp1) & KC_LONEKEY)
                    /* Post SLN_CHANGE notification */
                    WinPostMsg( WinQueryWindow(hwnd, QW_PARENT),WM_CONTROL,
                                MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), SLN_CHANGE),
                                MPFROMLONG(lPos));
                  else
                    /* Post SLN_SLIDERTRACK notification */
                    WinPostMsg(WinQueryWindow(hwnd, QW_PARENT),WM_CONTROL,
                               MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), SLN_SLIDERTRACK),
                               MPFROMLONG(lPos));
                  
                }
                WinSetWindowULong(hwnd, SLIDERARMPOS, lPos);
              }
              return (MRESULT)TRUE;
            case VK_LEFT:
              if(SHORT1FROMMP(mp1) & (KC_KEYUP|KC_PREVDOWN)) {
                lPos-=2;
                if(lPos<0) {
                  lPos=0;
                }
                else {
                  WinPostMsg( hwnd,
                              SLM_SETSLIDERINFO,
                              MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE),
                              MPFROMLONG( (LONG) lPos ));
                  /* Post SLN_CHANGE notification */
                  WinPostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_CONTROL,
                             MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), SLN_CHANGE),
                   MPFROMLONG(WinQueryWindowULong(hwnd, SLIDERARMPOS)));

                }
                WinSetWindowULong(hwnd, SLIDERARMPOS, lPos);
              }
              return (MRESULT)TRUE;
            default:
              break;
            }
        }
      }
      break;
    case WM_BUTTON1MOTIONSTART:
      {
        SHORT x=SHORT1FROMMP( mp1);
        SHORT y=SHORT2FROMMP( mp1);
        LONG  lPos=WinQueryWindowULong(hwnd, SLIDERARMPOS);
        USHORT usWidth=WinQueryWindowUShort(hwnd, SLIDERARMWITH);

        if(x<lPos+usWidth && y<WinQueryWindowUShort(hwnd, SLIDERY)+WinQueryWindowUShort(hwnd, SLIDERCY)
           && y>WinQueryWindowUShort(hwnd, SLIDERY)) {
          WinSetWindowULong(hwnd, SLDRAGGING, TRUE);
          WinSetCapture(HWND_DESKTOP, hwnd);
        }
        break;
      }
    case WM_BUTTON1MOTIONEND:
      if(WinQueryWindowULong(hwnd, SLDRAGGING)) {
        WinSetWindowULong(hwnd, SLDRAGGING,FALSE);
        WinSetCapture(HWND_DESKTOP, NULLHANDLE);
        /* Post SLN_CHANGE notification */
        WinPostMsg(WinQueryWindow(hwnd, QW_PARENT),WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), SLN_CHANGE),
                   MPFROMLONG(WinQueryWindowULong(hwnd, SLIDERARMPOS)));
      }
      break;
    case SLM_SETSLIDERINFO:
      switch(SHORT1FROMMP(mp1))
        {
          case SMA_SLIDERARMPOSITION:
            /*  SMA_RANGEVALUE only for now !! */
            if(SHORT2FROMMP(mp1)==SMA_RANGEVALUE) {
              WinSetWindowULong(hwnd, SLIDERARMPOS, LONGFROMMP(mp2));
              WinInvalidateRect(hwnd, NULLHANDLE,TRUE);
              return (MRESULT)0;
            }
            break;
        default:
          break;
        }
      break;
    case WM_MOUSEMOVE:
      if(WinQueryWindowULong(hwnd, SLDRAGGING)) {
        HPS hps;
        RECTL rcl, rcl2, rcl3;
        LONG lTemp;
        SHORT x=SHORT1FROMMP(mp1);
        LONG  lPos=WinQueryWindowULong(hwnd, SLIDERARMPOS);
        USHORT usWidth=WinQueryWindowUShort(hwnd, SLIDERARMWITH);
       
        lTemp=lPos;
     
        rcl.xLeft=WinQueryWindowULong(hwnd, SLIDERX);
        rcl.yBottom=WinQueryWindowULong(hwnd, SLIDERY);
        rcl.xRight=rcl.xLeft+WinQueryWindowULong(hwnd, SLIDERCX);
        rcl.yTop=rcl.yBottom+WinQueryWindowULong(hwnd, SLIDERCY);

        rcl2=rcl3=rcl;
        rcl.xLeft=x-WinQueryWindowUShort(hwnd, PTRPOSINSLARM);
        if(rcl.xLeft<rcl2.xLeft)/* Make sure we stop at the left border */
          rcl.xLeft=rcl2.xLeft;

        rcl.xRight=rcl.xLeft+usWidth;
        if(rcl.xRight>rcl2.xRight)
          {/* Make sure we stop at the right border */
            rcl.xRight=rcl2.xRight;
            rcl.xLeft=rcl.xRight-usWidth;
          }
        lPos=rcl.xLeft-WinQueryWindowULong(hwnd, SLIDERX);/* Save position zero based */
        WinSetWindowULong(hwnd, SLIDERARMPOS, lPos);
        if(lPos!=lTemp) {
          BOOL rc;

          hps=WinGetPS(hwnd);
          /* Paint Background not necessary here */

          /* Shaft */
          /* Left part */
          rcl3.xRight=rcl.xLeft;
          rc=FALSE;
          if(USERSLIDER) {
            OWNERITEM oi={0};
            oi.hwnd=hwnd;
            oi.hps=hps;
            oi.fsState=SLS_OWNERDRAW;/* More to come */
            oi.rclItem=rcl3;
            oi.idItem=SDA_SLIDERSHAFT;
            rc=(BOOL)WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_DRAWITEM, MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),
                                MPFROMP(&oi) );
          }
          if(!rc)
            WinFillRect(hps, &rcl3, CLR_GREEN);

          /* Right part */
          rcl3.xRight=rcl2.xRight;
          rcl3.xLeft=rcl.xRight;
          rc=FALSE;
          if(USERSLIDER) {
            OWNERITEM oi={0};
            oi.hwnd=hwnd;
            oi.hps=hps;
            oi.fsState=SLS_OWNERDRAW;/* More to come */
            oi.rclItem=rcl3;
            oi.idItem=SDA_SLIDERSHAFT;
            rc=(BOOL)WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_DRAWITEM, MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),
                                MPFROMP(&oi) );
          }
          if(!rc)
            WinFillRect(hps, &rcl3, CLR_WHITE);

          /* Paint Slider */
          rc=FALSE;
          if(USERSLIDER) {
            OWNERITEM oi={0};
            oi.hwnd=hwnd;
            oi.hps=hps;
            oi.fsState=SLS_OWNERDRAW;/* More to come */
            oi.rclItem=rcl;
            oi.idItem=SDA_SLIDERARM;
            rc=(BOOL)WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_DRAWITEM, MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),
                                MPFROMP(&oi) );
          }
          if(!rc)
            {
              WinFillRect(hps,&rcl, CLR_BLUE);
              WinDrawBorder(hps, &rcl, 2, 2, 0, 0 ,0x0400);
            }

          WinReleasePS(hps);

          /* Post SLN_SLIDERTRACK notification */
          WinPostMsg(WinQueryWindow(hwnd, QW_PARENT),WM_CONTROL, MPFROM2SHORT(WinQueryWindowUShort(hwnd, QWS_ID), SLN_SLIDERTRACK),
                     MPFROMLONG(lPos));
        }
      }
      break;
    case WM_PAINT:
      {
        HPS hps, hps2;
        RECTL rcl, rcl2, rcl3;
        POINTL ptl;
        LONG  lPos=WinQueryWindowULong(hwnd, SLIDERARMPOS);
        USHORT usWidth=WinQueryWindowUShort(hwnd, SLIDERARMWITH);
        BOOL rc;

        WinQueryWindowRect(hwnd, &rcl);

        /* Shaft */
        rcl2.xLeft=WinQueryWindowULong(hwnd, SLIDERX);
        rcl2.yBottom=WinQueryWindowULong(hwnd, SLIDERY);
        rcl2.xRight=rcl2.xLeft+WinQueryWindowULong(hwnd, SLIDERCX)-1;
        rcl2.yTop=rcl2.yBottom+WinQueryWindowULong(hwnd, SLIDERCY)-1;

        /* Background */
        hps2=WinGetPS(hwnd);
        GpiExcludeClipRectangle(hps2,&rcl2);
        WinFillRect(hps2, &rcl, CLR_PALEGRAY);
        WinReleasePS(hps2);
        rcl2.yTop+=1;
        rcl2.xRight+=1;

        hps=WinBeginPaint(hwnd, NULLHANDLE, NULLHANDLE);
        /* Focus */
        if(WinQueryFocus(HWND_DESKTOP)==hwnd) {
          GpiSetLineType(hps, LINETYPE_DOT);
          ptl.x=rcl.xLeft;
          ptl.y=rcl.yBottom;
          GpiMove(hps,&ptl);
          ptl.x=rcl.xRight-1;
          GpiLine(hps,&ptl);
          ptl.y=rcl.yTop-1;
          GpiLine(hps,&ptl);
          ptl.x=rcl.xLeft;
          GpiLine(hps,&ptl);
          ptl.y=rcl.yBottom;
          GpiLine(hps,&ptl);
        }

        rcl3=rcl=rcl2;

        /* Arm pos */        
        rcl2.xLeft+=lPos;
        /* Arm size */        
        rcl2.xRight=rcl2.xLeft+usWidth;
        
        /* Shaft */
        /* Left part */
        rcl3.xRight=rcl2.xLeft;
        rc=FALSE;
        if(USERSLIDER) {
          OWNERITEM oi={0};
          oi.hwnd=hwnd;
          oi.hps=hps;
          oi.fsState=SLS_OWNERDRAW;/* More to come */
          oi.rclItem=rcl3;
          oi.idItem=SDA_SLIDERSHAFT;
          rc=(BOOL)WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_DRAWITEM, MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),
                    MPFROMP(&oi) );
        }
        if(!rc)
          WinFillRect(hps, &rcl3, CLR_GREEN);

        /* Right part */
        rcl3.xRight=rcl.xRight;
        rcl3.xLeft=rcl2.xRight;
        rc=FALSE;
        if(USERSLIDER) {
          OWNERITEM oi={0};
          oi.hwnd=hwnd;
          oi.hps=hps;
          oi.fsState=SLS_OWNERDRAW;/* More to come */
          oi.rclItem=rcl3;
          oi.idItem=SDA_SLIDERSHAFT;
          rc=(BOOL)WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_DRAWITEM, MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),
                              MPFROMP(&oi) );
        }
        if(!rc)
          WinFillRect(hps, &rcl3, CLR_WHITE);

        rc=FALSE;
        if(USERSLIDER) {
          OWNERITEM oi={0};
          oi.hwnd=hwnd;
          oi.hps=hps;
          oi.fsState=SLS_OWNERDRAW;/* More to come */
          oi.rclItem=rcl2;
          oi.idItem=SDA_SLIDERARM;
          rc=(BOOL)WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_DRAWITEM, MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),
                              MPFROMP(&oi) );
        }
        if(!rc)
          {
            WinFillRect(hps,&rcl2, CLR_BLUE);        
            WinDrawBorder(hps, &rcl2, 2, 2, 0, 0 ,0x0400);
          }

        WinEndPaint(hps);
        return (MRESULT)0;
      }
      break;
    default:
      break;
    }

  return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
示例#21
0
MRESULT	EXPENTRY DriverWndProc(HWND hWnd, ULONG	msg, MPARAM mp1, MPARAM	mp2)

{
CHAR	     szFile[CCHMAXPATH];   /* File HOlder			*/
FILEFINDBUF3 findbuf;		   /* File Find	Buffer			*/
FONTMETRICS  fm;		   /* Font Metrics Structure		*/
HDIR	     hDir = (HDIR)HDIR_CREATE; /* Directory Handle		*/
HPS	     hPS;		   /* Presentation Space Handle		*/
HWND	     hwndListBox;	   /* List Box Window Handle		*/
LISTBOXCDATA lbwcd;		   /* List Box Window Control Data	*/
POWNERITEM   poi;		   /* Owner Item			*/
RECTL	     rcl;		   /* Client Window Rectangle		*/
ULONG	     ulFileCnt = 1UL;	   /* File Counter Holder		*/
register INT i,	k, n;		   /* Loop Counter			*/

switch ( msg )
   {
		       /* Perform window initialization			*/
   case	WM_CREATE :
       hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW,	FALSE);
       WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
       memset(&lbwcd, 0, sizeof(LISTBOXCDATA));
       lbwcd.cb	= sizeof(LISTBOXCDATA);
       lbwcd.ulVersion = LBV_110;
       lbwcd.vdata.lbcd1_1.flExtStyles = LSXS_CHECKBOX | LSXS_EDITABLE;

       hwndList1 = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
				   10L,	10L, 100L, 175L, hWnd,
				   HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);

       hwndListx = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE,
				   125L, 10L, 100L, 175L, hWnd,
				   HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL);

       hwndList2 = WinCreateWindow(hWnd, "ListBoxWindow", "", WS_VISIBLE, 10L, 190L, 250L, 200L, hWnd,
				   HWND_TOP, 1025UL, (PVOID)&lbwcd, (PVOID)NULL);

       WinSendMsg(hwndList1, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_SINGLECLICK),
		  MPFROMP("ahooga.wav"));
       WinSendMsg(hwndListx, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_DOUBLECLICK),
		  MPFROMP("flush.wav"));

       hwndListA = WinCreateWindow(hWnd, WC_LISTBOX, "", LS_OWNERDRAW |	LS_HORZSCROLL |	LS_MULTIPLESEL | WS_VISIBLE,
				   275L, 10L, 100L, 175L, hWnd,
				   HWND_TOP, 1026UL, (PVOID)NULL, (PVOID)NULL);

		       /* Sub-class the	default	window procedure with	*/
		       /* new one which	will handle specific messages	*/
		       /* allowing better control over the sizing frame	*/

       hwndListB = WinCreateWindow(hWnd, WC_LISTBOX, "", WS_VISIBLE | LS_EXTENDEDSEL, 275L, 190L, 250L,	200L, hWnd,
				   HWND_TOP, 1027UL, (PVOID)NULL, (PVOID)NULL);

       for ( i = 0; i <	10; i++	)
	   {
	   sprintf(szFile, "Item %04d Item %04d Item %04d", i, i, i);
	       WinSendMsg(hwndListx, LM_INSERTITEM,
			  MPFROMLONG(LIT_END),
			  MPFROMP(szFile));
	   }

       n = (INT)WinSendMsg(hwndList2, LMX_CALCLINECOUNT, MPFROMLONG(175L), 0L);

       k = 0;

       WinSendMsg(hwndList2, LM_SETITEMHEIGHT, MPFROMLONG(36L),	0L);

       if ( !DosFindFirst("*.*", &hDir,	FILE_NORMAL,
			  (PVOID)&findbuf, sizeof(FILEFINDBUF3),
			  &ulFileCnt, FIL_STANDARD) )
	   {
	   do
	       {
	       WinSendMsg(hwndList2, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTDESCENDING),
			  MPFROMP(findbuf.achName));
	       WinSendMsg(hwndList1, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       if ( ++k	> n )
		   WinSendMsg(hwndList2, LM_SETTOPINDEX, MPFROMLONG(k -	n), 0L);
	       WinSendMsg(hwndListB, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTDESCENDING),
			  MPFROMP(findbuf.achName));
	       WinSendMsg(hwndListA, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       }
	       while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
	   DosFindClose(hDir);
	   }
       break;

   case	WM_BUTTON1DOWN :
       WinEnableWindowUpdate(hwndListA,	FALSE);
       WinEnableWindowUpdate(hwndList1,	FALSE);

       WinSendMsg(hwndListA, LM_DELETEALL, 0L, 0L);
       WinSendMsg(hwndList1, LM_DELETEALL, 0L, 0L);
       i = 0;
       if ( !DosFindFirst("*.*", &hDir,	FILE_NORMAL,
			  (PVOID)&findbuf, sizeof(FILEFINDBUF3),
			  &ulFileCnt, FIL_STANDARD) )
	   {
	   do
	       {
	       WinSendMsg(hwndListA, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       WinSendMsg(hwndList1, LM_INSERTITEM,
			  MPFROMLONG(LIT_SORTASCENDING),
			  MPFROMP(findbuf.achName));
	       ++i;
	       }
	       while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
	   DosFindClose(hDir);
	   }
       WinShowWindow(hwndListA,	TRUE);
       WinShowWindow(hwndList1,	TRUE);

       while ( i )
	   {
	   if (	i % 2 )
	       {
	       WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
	       WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE));
	       }
	   --i;
	   }
       break;

   case	WM_CONTROL :
       switch (	SHORT2FROMMP(mp1) )
	   {
		       /* Process double click on a List Box		*/

	   case	LN_SELECT :
	       switch (	SHORT1FROMMP(mp1) )
		   {
		   case	1024UL :
		   /*  WinAlarm(HWND_DESKTOP, WA_NOTE);	  */
		       break;

		   case	1027UL :
		   /*  WinAlarm(HWND_DESKTOP, WA_ERROR);  */
		       break;
		   }
	       break;
	   }
       break;


   case	WM_MEASUREITEM :
       GpiQueryFontMetrics(hPS = WinGetPS(hWnd), sizeof(FONTMETRICS), &fm);
       WinReleasePS(hPS);
       return(MRFROMLONG(fm.lMaxBaselineExt));

		       /* Draw a list box item				*/
   case	WM_DRAWITEM :

       if ( SHORT1FROMMP(mp1) == 1024 )
	   hwndListBox = hwndList1;
       else
	   if (	SHORT1FROMMP(mp1) == 1026 )
	       hwndListBox = hwndListA;

		       /* Point	to Owner Item information		*/

       poi = (POWNERITEM)mp2;
       GpiCreateLogColorTable(poi->hps,	0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);

       i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXTLENGTH,
				      MPFROMLONG(poi->idItem), 0L));

       i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXT,
				      MPFROM2SHORT(poi->idItem,	CCHMAXPATH),
				      MPFROMP(szFile)));

		       /* Check	to see if item to be drawn or		*/
		       /* highlighted					*/

       if ( poi->fsState != poi->fsStateOld )
	   {
	   WinFillRect(poi->hps, &poi->rclItem,	RGBCLR_DIALOGBACKGROUND);

	   if (	poi->fsState )
	       WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
			   RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
			   DT_ERASERECT);

		       /* Set item highlighting	by inverting the items	*/
		       /* rectangle colour				*/

	   WinInvertRect(poi->hps, &poi->rclItem);

	   if (	!poi->fsState )
	       WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
			   RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER |
			   DT_ERASERECT);
	   poi->fsState	= poi->fsStateOld = 0;
	   }
       else
	   {
		       /* Item needs to	be drawn, get item rectangle	*/
		       /* item position					*/

	   WinFillRect(poi->hps, &poi->rclItem,	RGBCLR_DIALOGBACKGROUND);

	   WinDrawText(poi->hps, -1L, szFile, &poi->rclItem,
		       RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER	|
		       DT_ERASERECT);
	   }
       return(MRFROMLONG(TRUE));

   case	WM_BUTTON1DBLCLK :
       i = 0;
       if ( !DosFindFirst("*.*", &hDir,	FILE_NORMAL,
			  (PVOID)&findbuf, sizeof(FILEFINDBUF3),
			  &ulFileCnt, FIL_STANDARD) )
	   {
	   do
	       {
	       ++i;
	       }
	       while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) );
	   DosFindClose(hDir);
	   }

       while ( i )
	   {
	   if (	i % 2 )
	       {
	       WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
	       WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE));
	       }
	   --i;
	   }
       break;

   case	WM_BUTTON2DOWN :

       for ( i = 0; i <	5; i++ )
	   WinSendMsg(hwndListx, LM_DELETEITEM,	MPFROMSHORT(2),	0L);

#if 0
       WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(LIT_NONE), MPFROMLONG(TRUE));

       i = LIT_FIRST;
       while ( (i = (INT)LONGFROMMR(WinSendMsg(hwndList1, LM_QUERYSELECTION, MPFROMLONG(i), 0L))) != LIT_NONE )
	   WinSendMsg(hwndList1, LM_SELECTITEM,	MPFROMLONG(i), MPFROMLONG(FALSE));
#endif
       break;
		       /* Erase	background				*/

   case	WM_ERASEBACKGROUND :
       WinQueryWindowRect(hWnd,	&rcl);
       WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND);
       break;
		       /* Paint	the main client	window			*/
   case	WM_PAINT :
       WinSetPointer(HWND_DESKTOP, hptrWait);

       WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL,	&rcl), &rcl, SYSCLR_DIALOGBACKGROUND);

       WinEndPaint(hPS);
       WinSetPointer(HWND_DESKTOP, hptrArrow);
       break;
		       /* Close	Down					*/
   case	WM_CLOSE :

       WinPostMsg(hWnd,	WM_QUIT, 0L, 0L);
       break;

   case	WM_DESTROY :
       WinDestroyPointer(hptrArrow);
       WinDestroyPointer(hptrWait);
       break;
		       /* Default message processing			*/
   default:
       return(WinDefWindowProc(hWnd, msg, mp1, mp2));
   }
return(0L);
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static INT aiPuzzle[NUMROWS][NUMCOLS],
                iBlankRow, iBlankCol, cxSquare, cySquare ;
     CHAR       szNum[10] ;
     HPS        hps ;
     HWND       hwndFrame ;
     INT        iRow, iCol, iMouseRow, iMouseCol, i ;
     POINTL     ptl ;
     RECTL      rcl, rclInvalid, rclIntersect ;
     SIZEL      sizl ;

     switch (msg)
          {
          case WM_CREATE:
                              // Calculate square size in pixels

               hps = WinGetPS (hwnd) ;
               sizl.cx = sizl.cy = 0 ;
               GpiSetPS (hps, &sizl, PU_LOENGLISH) ;
               ptl.x = SQUARESIZE ;
               ptl.y = SQUARESIZE ;
               GpiConvert (hps, CVTC_PAGE, CVTC_DEVICE, 1L, &ptl) ;
               WinReleasePS (hps) ;

               cxSquare = ptl.x ;
               cySquare = ptl.y ;

                              // Calculate client window size and position

               rcl.xLeft   = (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) -
                                           NUMCOLS * cxSquare) / 2 ;
               rcl.yBottom = (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) -
                                           NUMROWS * cySquare) / 2 ;
               rcl.xRight  = rcl.xLeft   + NUMCOLS * cxSquare ;
               rcl.yTop    = rcl.yBottom + NUMROWS * cySquare ;

                              // Set frame window position and size

               hwndFrame = WinQueryWindow (hwnd, QW_PARENT) ;
               WinCalcFrameRect (hwndFrame, &rcl, FALSE) ;
               WinSetWindowPos  (hwndFrame, NULLHANDLE,
                                 rcl.xLeft, rcl.yBottom,
                                 rcl.xRight - rcl.xLeft,
                                 rcl.yTop - rcl.yBottom,
                                 SWP_MOVE | SWP_SIZE | SWP_ACTIVATE) ;

                              // Initialize the aiPuzzle array

               WinSendMsg (hwnd, WM_COMMAND, MPFROMSHORT (IDM_NORMAL), NULL) ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, &rclInvalid) ;

                              // Draw the squares

               for (iRow = NUMROWS - 1 ; iRow >= 0 ; iRow--)
                    for (iCol = 0 ; iCol < NUMCOLS ; iCol++)
                         {
                         rcl.xLeft   = cxSquare * iCol ;
                         rcl.yBottom = cySquare * iRow ;
                         rcl.xRight  = rcl.xLeft   + cxSquare ;
                         rcl.yTop    = rcl.yBottom + cySquare ;

                         if (!WinIntersectRect (0, &rclIntersect,
                                                &rcl, &rclInvalid))
                              continue ;

                         if (iRow == iBlankRow && iCol == iBlankCol)
                              WinFillRect (hps, &rcl, CLR_BLACK) ;
                         else
                              {
                              WinDrawBorder (hps, &rcl, 5, 5,
                                             CLR_PALEGRAY, CLR_DARKGRAY,
                                             DB_STANDARD | DB_INTERIOR) ;

                              WinDrawBorder (hps, &rcl, 2, 2,
                                             CLR_BLACK, 0L, DB_STANDARD) ;

                              sprintf (szNum, "%d", aiPuzzle[iRow][iCol]) ;

                              WinDrawText (hps, -1, szNum,
                                           &rcl, CLR_WHITE, CLR_DARKGRAY,
                                           DT_CENTER | DT_VCENTER) ;
                              }
                         }
               WinEndPaint (hps) ;
               return 0 ;

          case WM_BUTTON1DOWN:
               iMouseCol = MOUSEMSG(&msg)->x / cxSquare ;
               iMouseRow = MOUSEMSG(&msg)->y / cySquare ;

                              // Check if mouse was in valid area

               if ( iMouseRow < 0          || iMouseCol < 0           ||
                    iMouseRow >= NUMROWS   || iMouseCol >= NUMCOLS    ||
                   (iMouseRow != iBlankRow && iMouseCol != iBlankCol) ||
                   (iMouseRow == iBlankRow && iMouseCol == iBlankCol))
                         break ;

                              // Move a row right or left

               if (iMouseRow == iBlankRow)
                    {
                    if (iMouseCol < iBlankCol)
                         for (iCol = iBlankCol ; iCol > iMouseCol ; iCol--)
                              aiPuzzle[iBlankRow][iCol] =
                                   aiPuzzle[iBlankRow][iCol - 1] ;
                    else
                         for (iCol = iBlankCol ; iCol < iMouseCol ; iCol++)
                              aiPuzzle[iBlankRow][iCol] =
                                   aiPuzzle[iBlankRow][iCol + 1] ;
                    }
                              // Move a column up or down
               else
                    {
                    if (iMouseRow < iBlankRow)
                         for (iRow = iBlankRow ; iRow > iMouseRow ; iRow--)
                              aiPuzzle[iRow][iBlankCol] =
                                   aiPuzzle[iRow - 1][iBlankCol] ;
                    else
                         for (iRow = iBlankRow ; iRow < iMouseRow ; iRow++)
                              aiPuzzle[iRow][iBlankCol] =
                                   aiPuzzle[iRow + 1][iBlankCol] ;
                    }
                              // Calculate invalid rectangle

               rcl.xLeft   = cxSquare *  min (iMouseCol, iBlankCol) ;
               rcl.yBottom = cySquare *  min (iMouseRow, iBlankRow) ;
               rcl.xRight  = cxSquare * (max (iMouseCol, iBlankCol) + 1) ;
               rcl.yTop    = cySquare * (max (iMouseRow, iBlankRow) + 1) ;

                              // Set new array and blank values

               iBlankRow = iMouseRow ;
               iBlankCol = iMouseCol ;
               aiPuzzle[iBlankRow][iBlankCol] = 0 ;

                              // Invalidate rectangle

               WinInvalidateRect (hwnd, &rcl, FALSE) ;
               break ;

          case WM_CHAR:
               if (!(CHARMSG(&msg)->fs & KC_VIRTUALKEY) ||
                     CHARMSG(&msg)->fs & KC_KEYUP)
                         return 0 ;

                              // Mimic a WM_BUTTON1DOWN message

               iMouseCol = iBlankCol ;
               iMouseRow = iBlankRow ;

               switch (CHARMSG(&msg)->vkey)
                    {
                    case VK_LEFT:   iMouseCol++ ;  break ;
                    case VK_RIGHT:  iMouseCol-- ;  break ;
                    case VK_UP:     iMouseRow-- ;  break ;
                    case VK_DOWN:   iMouseRow++ ;  break ;
                    default:        return 0 ;
                    }
               WinSendMsg (hwnd, WM_BUTTON1DOWN,
                           MPFROM2SHORT (iMouseCol * cxSquare,
                                         iMouseRow * cySquare), NULL) ;
               return 0 ;

          case WM_COMMAND:
               switch (COMMANDMSG(&msg)->cmd)
                    {
                              // Initialize aiPuzzle array

                    case IDM_NORMAL:
                    case IDM_INVERT:
                         for (iRow = 0 ; iRow < NUMROWS ; iRow++)
                              for (iCol = 0 ; iCol < NUMCOLS ; iCol++)
                                   aiPuzzle[iRow][iCol] = iCol + 1 +
                                        NUMCOLS * (NUMROWS - iRow - 1) ;

                         if (COMMANDMSG(&msg)->cmd == IDM_INVERT)
                              {
                              aiPuzzle[0][NUMCOLS-2] = NUMCOLS * NUMROWS - 2 ;
                              aiPuzzle[0][NUMCOLS-3] = NUMCOLS * NUMROWS - 1 ;
                              }
                         aiPuzzle[iBlankRow = 0][iBlankCol = NUMCOLS - 1] = 0 ;
                         WinInvalidateRect (hwnd, NULL, FALSE) ;
                         return 0 ;

                              // Randomly scramble the squares

                    case IDM_SCRAMBLE:
                         WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (
                                        HWND_DESKTOP, SPTR_WAIT, FALSE)) ;

                         srand ((int) WinGetCurrentTime (0)) ;

                         for (i = 0 ; i < SCRAMBLEREP ; i++)
                              {
                              WinSendMsg (hwnd, WM_BUTTON1DOWN,
                                   MPFROM2SHORT (rand() % NUMCOLS * cxSquare,
                                        iBlankRow * cySquare), NULL) ;
                              WinUpdateWindow (hwnd) ;

                              WinSendMsg (hwnd, WM_BUTTON1DOWN,
                                   MPFROM2SHORT (iBlankCol * cxSquare,
                                        rand() % NUMROWS * cySquare), NULL) ;
                              WinUpdateWindow (hwnd) ;
                              }
                         WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (
                                        HWND_DESKTOP, SPTR_ARROW, FALSE));
                         return 0 ;
                    }
               break ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
示例#23
0
/*----------------------------------------------------------------------*/
SHORT DMLBLocateListboxItem( HWND hwnd, HWND RelHwnd, SHORT Y, SHORT Option )
/*----------------------------------------------------------------------*/
/* Parameters:                                                          */
/*   hwnd         Listbox of interest                                   */
/*   RelHwnd      Window to which Y is relative to                      */
/*   Y            Y position of the pointer                             */
/*   Option       LLI_UNDER to return index of item under pointer,      */
/*                LLI_INSERTPOINT to index of item nearest insert point */
/*----------------------------------------------------------------------*/
/* Given a Y window coordinate, this function will calculate the item   */
/* number of the listbox item at that position.  The LLI_UNDER option   */
/* will return the item directly under the pointer.  The LLI_INSERTPOINT*/
/* option will return the item number *before* which an insertion should*/
/* be made (drop zones are calculated as the half-way points through    */
/* each item).                                                          */
/*----------------------------------------------------------------------*/
{
   RECTL   Rect;
   POINTL  Points[2];
   HPS     hps;
   LONG    VertSize;
   SHORT   ItemNum;
   char    ClassName[10];

   /* Map coordinate from window it is relative to, to win of interst*/
   Points[0].x = 0;
   Points[0].y = Y;
   WinMapWindowPoints(RelHwnd, hwnd, &(Points[0]), 1L);
   Y = Points[0].y;

   /* If this is actually a MultiColumn ListBox, we must find the    */
   /* real listbox which is the first column and use it for our      */
   /* location calculations.  Since we only care about the Y         */
   /* coordinate we only need to look at the 1st column of the MCLB. */

   WinQueryClassName(hwnd, sizeof(ClassName), ClassName);
   if (!strcmp("MCLBCls", ClassName))
     hwnd = WinWindowFromID(hwnd, 1);   /* Get handle of 1st column's listbox */

   /* If this is an OWNERDRAW listbox, ask owner how big items are.  */

   VertSize = 0;
   if (WinQueryWindowULong(hwnd, QWL_STYLE) & LS_OWNERDRAW)
     VertSize = SHORT1FROMMR(                               // Take returned Height
                WinSendMsg(WinQueryWindow(hwnd, QW_OWNER),  // Query owner of listbox
                   WM_MEASUREITEM,                          // Ask owner the size
                   MPFROMSHORT(WinQueryWindowUShort(hwnd, QWS_ID)),  // Listbox ID
                   MPFROMSHORT(0)));                        // First item

   if (VertSize == 0) {
     /* For a normal listbox, items are the size of the font.  To */
     /* determine the size we get the bounding box of a space.    */
     hps = WinGetPS(hwnd);
     GpiQueryTextBox(hps, 1L, " ", 2, Points);
     VertSize = Points[TXTBOX_TOPLEFT].y - Points[TXTBOX_BOTTOMLEFT].y;
     WinReleasePS(hps);
   }

   WinQueryWindowRect(hwnd, &Rect);
   Rect.yTop = Rect.yTop-2;         /* Listbox frame is 2 pixels */

   /* Calculate item number of item under the pointer */
   ItemNum = (SHORT)WinSendMsg(hwnd, LM_QUERYTOPINDEX, 0L, 0L)
             + ((Rect.yTop-Y)/VertSize);

   /* Return item under pointer, or insertion point */

   switch (Option) {
     case LLI_UNDER:
       return ItemNum;
     case LLI_INSERTPOINT:
       if (((Rect.yTop-Y) % VertSize) <= (VertSize / 2))
         return ItemNum;
       return ItemNum+1;  /* Note: May exceed num of items in list */
   }
}
示例#24
0
/****************************************************************************
 * ClientWndProc                                                            *
 *  - Typical PM client window procedure.  (see below)                      *
 *  - Standard client window I/O                                            *
 ****************************************************************************/
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
	   RECTL  rcl;
	   SWP	  swp;
	   HPS	  hpsPaint;

    static HPS	  hps;                      /* Permanent HPS                */
    static INT    cx, cy;		    /* Client window dimensions     */
    static BOOL   bSlowUpdateNow = FALSE;   /* Update toggle for asteroids  *
                                             *   and enemy which are slow.  */
    static POINTL ptlCenter;		    /* Center of client window      */

    switch (msg) {
      /* Recieved from WinCreateStdWindow */
      case WM_CREATE:
	/* Get permanent PS for entire window */
	hps = WinGetPS(hwnd);

	/* Load private Asteroid fonts from ASTEROID.DLL */
	if (GpiLoadFonts(hab, "ASTEROID") != GPI_OK) {
            WinReleasePS(hps);
	    WinAlarm(HWND_DESKTOP, WA_WARNING);
	    WinMessageBox(HWND_DESKTOP,NULLHANDLE,
		"Please put ASTEROID.DLL in a directory in your LIBPATH.",
		"Error reading ASTEROID.DLL",
		0,MB_ICONHAND|MB_OK|MB_APPLMODAL);
	    WinPostMsg(hwnd,WM_QUIT,(MPARAM) 0L,(MPARAM) 0L);
	    return (MRESULT) TRUE;
	    }

        /* Register/create logical fonts for use */
	InitFonts(hps);

	/* Display About dialoge box */
	WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)AboutDlgProc, NULLHANDLE,
		  IDD_ABOUT, NULL);

	return 0;

      /* Recieved during attract mode when user starts game */
      case WM_STARTGAME:
        /* Determine the number of players */
	cPlayers = (INT)LONGFROMMP(mp1);

        /* Initialize each player */
	for (Player=0;Player<cPlayers;Player++) {
	    Level[Player] = 1;
	    Ships[Player] = prfProfile.iSHIPS;
	    DeletePhotons();
	    InitAsteroids();
	    InitEnemy();
	    }

        /* Start with player 1 */
	Player = 0;
	iGameMode = GAME_MODE_NEXT;
	iGameModeCnt = GAME_PAUSE_TIME-1;

	/* Hide the pointer if mouse controls are enabled */
	ShowMouse(FALSE);
        
        /* Paint everything */
	WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID);

	return 0;

      /* Recieved at startup and at the completion of a game */
      case WM_INITGAME:
        /* Make mouse visible if we hid it before */
        ShowMouse(TRUE);
        
	/* Fix menu to reflect attract mode */
	EnableMenuItem(hwndMenu, IDM_START, TRUE);
	EnableMenuItem(hwndMenu, IDM_STOP, FALSE);

	/* Initialize player and enemy data structures */
	cPlayers = 0;
	Level[0] = 1;
	for (Player=0;Player<2;Player++) {
	    Score[Player] = 0L;
	    Ships[Player] = 0;
	    DeletePhotons();
	    }
	Player = 0;

	/* Initialize asteroids (and enemy) for attract mode */
	InitAsteroids();
	InitEnemy();

        /* Depending on whether ASTEROID was just started or a game just  *
         *   completed display the "High Score" or "Press 1 or 2" screen. */
	if (SHORT1FROMMP(mp1) == 0) {
	    iGameMode = GAME_MODE_INIT1;
	    iGameModeCnt = GAME_INIT_TIME;
	    }
	else {
	    iGameMode = GAME_MODE_INIT2;
	    iGameModeCnt = GAME_INIT_TIME;
	    }

        /* Paint everything */
	WinSendMsg(hwnd, WM_PAINT, MPVOID, MPVOID);
	return 0;

      /* Usually recieved from the system, sometime forced by the program to *
       *   ensure the screen is not corrupt.                                 */
      case WM_PAINT:
	/* Clear entire window to insure no "droppings" */
	WinQueryWindowRect(hwnd,&rcl);
        WinFillRect(hps, &rcl, CLR_BLACK);
	WinInvalidateRect(hwnd, &rcl, FALSE);

	/* Get the update region and paint it black */
	hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rcl);
	WinFillRect(hpsPaint, &rcl, CLR_BLACK);
	WinEndPaint(hpsPaint);

        /* Only in normal play mode should we draw the ship */
	if ((iGameMode == GAME_MODE_PLAY) &&
	    (iShipMode[Player] != EXPLOSION) &&
	    (iShipMode[Player] != HYPERSPACE))
	    DrawShip(hps, cx, cy, DRAW_INIT);
	else if ((iGameMode == GAME_MODE_PLAY) &&
		 (iShipMode[Player] == EXPLOSION))
	    ExplodeShip(hps, cx, cy);

        /* Draw the enemy if it is on the screen */
	if (iEnemyMode[Player] != NONE)
	    if (iEnemyMode[Player] != EXPLOSION)
		DrawEnemy(hps, cx, cy,DRAW_INIT);
	    else
		ExplodeEnemy(hps, cx, cy);

        /* Draw photons and asteroids in all modes but the "Enter your *
         *   initials" mode, otherwise draw that screen.               */
	if (iGameMode != GAME_MODE_HIGH) {
	    DrawPhotons(hps, cx, cy, DRAW_INIT);
	    DrawAsteroids(hps, cx, cy, DRAW_INIT);
	    }
	else
	    DrawHighScore(hps, cx, cy, DRAW_INIT);

        /* Always draw the score */
	DrawScore(hps, cx, cy, DRAW_INIT);

	return 0;

      /* Left mouse button down.  This simulates the move/track function *
       *   in the system menu.                                           */
      case WM_BUTTON1DOWN:
        if (prfProfile.bMOUSECONTROL &&
            iGameMode != GAME_MODE_INIT1 &&
            iGameMode != GAME_MODE_INIT2 &&
            !TogglePause(CHECK)) {
	    UPDATE_FIRE(iShipMode[Player], TRUE);
            return (MRESULT)TRUE;
        }
	return WinSendMsg(hwndFrame, WM_TRACKFRAME,
			 (MPARAM) (SHORT1FROMMP(mp2) | TF_MOVE), MPVOID);

      case WM_BUTTON1UP:
        if (prfProfile.bMOUSECONTROL) {
	    UPDATE_FIRE(iShipMode[Player], FALSE);
            return (MRESULT)TRUE;
        }
        return 0;
        
      /* Left mouse button double clicked.  Toggle frame control display. */
      case WM_BUTTON1DBLCLK:
        if (!prfProfile.bMOUSECONTROL ||
            iGameMode == GAME_MODE_INIT1 ||
            iGameMode == GAME_MODE_INIT2 ||
            TogglePause(CHECK)) {
            if (prfProfile.bCONTROLS = !prfProfile.bCONTROLS)
	    	ShowFrameControls();
            else
	    	HideFrameControls();
        }
	return 0;

      case WM_BUTTON2DOWN:
        if (prfProfile.bMOUSECONTROL) {
	    UPDATE_SHIELD(iShipMode[Player], iShipShieldCnt[Player]);
            return (MRESULT)TRUE;
        }
        return 0;
        
      case WM_BUTTON2CLICK:
        if (prfProfile.bMOUSECONTROL) {
            UPDATE_HYPERSPACE(iShipMode[Player], iShipModeCnt[Player]);
            return (MRESULT)TRUE;
        }
        return 0;
        
      /* Right mouse button double clicked.  Display the about dialog box. */
      case WM_BUTTON2DBLCLK:
        if (!prfProfile.bMOUSECONTROL ||
            iGameMode == GAME_MODE_INIT1 ||
            iGameMode == GAME_MODE_INIT2 ||
            TogglePause(CHECK)) {
            WinDlgBox(HWND_DESKTOP, hwndClient, (PFNWP)AboutDlgProc,
            	      NULLHANDLE, IDD_ABOUT, NULL);
        }
	return 0;

      /* User typed a key.  Most of this is self explanatory. */
      case WM_CHAR:
	ProcessChar((CHAR) (CHARMSG(&msg)->vkey-1),
		    CHARMSG(&msg)->fs & KC_VIRTUALKEY,
		    (CHAR) (CHARMSG(&msg)->chr),
		    (BOOL) !(CHARMSG(&msg)->fs & KC_KEYUP));
	return 0;

      /* User entered a command via the menu bar. */
      case WM_COMMAND:
	DoCommand(hwnd, msg, mp1, mp2);
	return 0;

      /* Suspend/un-suspend game depending on focus */
      case WM_SETFOCUS:
	if ((BOOL) SHORT1FROMMP(mp2))
	    TogglePause(SUSPEND_OFF);
	else if (!prfProfile.bBACKGRND)
	    TogglePause(SUSPEND_ON);
	return 0;

      /* Keep track of the client window size.  Profile information is not *
       *   updated here because there are better places (i.e. at exit)     */
      case WM_SIZE:
	cx = (INT)SHORT1FROMMP(mp2);
	cy = (INT)SHORT2FROMMP(mp2);

      /* Keep track of client window position.  Also updates profile info. */
      case WM_MOVE:
	WinQueryWindowPos(hwndFrame,&swp);
	if (!(swp.fl & SWP_MAXIMIZE) && !(swp.fl & SWP_MINIMIZE)) {
	    prfProfile.x  = swp.x;prfProfile.y   = swp.y;
	    prfProfile.cx = swp.cx;prfProfile.cy = swp.cy;
	    }

	if (swp.fl & SWP_MINIMIZE)
	    if (!prfProfile.bBACKGRND) {
		/* Set icon */
		WinSendMsg(hwndFrame, WM_SETICON,
		    (MPARAM) WinLoadPointer(HWND_DESKTOP, NULLHANDLE,
					    ID_RESOURCE), MPVOID);

		TogglePause(SUSPEND_ON);
		}
	    else
		WinSendMsg(hwndFrame, WM_SETICON, MPVOID, MPVOID);
	else
	    TogglePause(SUSPEND_OFF);

	ptlCenter.x = swp.cx / 2;
        ptlCenter.y = swp.cy / 2;
        WinMapWindowPoints(hwndClient, HWND_DESKTOP, &ptlCenter, 1L);

	return 0;

      /* Recieved approximately 31 times a second.  This is the longest and *
       *   ugliest of the messages, partly because there are so many cases  *
       *   to keep track of, partly because it must be highly optimized.    */
      case WM_TIMER:
        if (prfProfile.bMOUSECONTROL &&
            iGameMode != GAME_MODE_INIT1 &&
            iGameMode != GAME_MODE_INIT2) {                   POINTL ptl;
            static BOOL   bUp, bLeft, bRight;

            WinQueryPointerPos(HWND_DESKTOP, &ptl);
            if (bUp || (ptl.y - ptlCenter.y > 0))
	       	UPDATE_THRUST(iShipMode[Player],
            		      bUp = (ptl.y - ptlCenter.y > 0));
            if (bLeft || (ptlCenter.x - ptl.x > 0))
                UPDATE_LEFT(iShipMode[Player],
                	    bLeft = (ptlCenter.x - ptl.x > 0));
            if (bRight || (ptlCenter.x - ptl.x < 0))
                UPDATE_RIGHT(iShipMode[Player],
                 	     bRight = (ptlCenter.x - ptl.x < 0));
            WinSetPointerPos(HWND_DESKTOP, ptlCenter.x, ptlCenter.y);
        }
        
        /* Determine the current game mode */
	switch (iGameMode) {

          /* Either initialization/attract mode screen. */
	  case GAME_MODE_INIT1: case GAME_MODE_INIT2:
            /* Switch screens when count expires */
	    if (--iGameModeCnt == 0) {
		if (iGameMode == GAME_MODE_INIT1)
		    iGameMode = GAME_MODE_INIT2;
		else
		    iGameMode = GAME_MODE_INIT1;
		iGameModeCnt = GAME_INIT_TIME;

                /* Score must be redrawn because the attract mode screens *
                 *   draw the score differently.                          */
		DrawScore(hps, cx, cy, DRAW_REINIT);
		}

            /* Update photons, asteroids, enemy, and score */
	    UpdatePhotons(hps, cx, cy);
	    if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		UpdateAsteroids(hps, cx, cy);
		UpdateEnemy(hps, cx, cy);
		DrawScore(hps, cx, cy, DRAW_REFRESH);
		}
	    break;

          /* Completion of one player's turn or new game */
	  case GAME_MODE_NEXT:
            /* Initially, erase and redraw everything for new player */
	    if (iGameModeCnt-- == GAME_PAUSE_TIME) {
		if ((cPlayers == MAXPLAYERS) &&
                    (Ships[(Player+1) % MAXPLAYERS])) {
		    DrawAsteroids(hps, cx, cy, DRAW_ERASE);
		    DrawPhotons(hps, cx, cy, DRAW_ERASE);
		    Player = (Player+1) % MAXPLAYERS;
		    }
		DrawScore(hps, cx, cy, DRAW_REINIT);
		DrawAsteroids(hps, cx, cy, DRAW_INIT);
		}
            /* During countdown update score and asteroids */
	    else if (iGameModeCnt > 0) {
		if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		    DrawScore(hps, cx, cy, DRAW_REFRESH);
		    UpdateAsteroids(hps, cx, cy);
		    }
		}
            /* At end of countdown start the player */
	    else {
		InitShip();
		InitEnemy();
		iGameMode = GAME_MODE_PLAY;
		DrawScore(hps, cx, cy, DRAW_REINIT);
		}
	    break;

          /* Normal play mode */
	  case GAME_MODE_PLAY:
            /* Update ship, photons, asteroids, enemy, and score */
	    UpdateShip(hps, cx, cy);
	    UpdatePhotons(hps, cx, cy);
	    if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		UpdateAsteroids(hps, cx, cy);
		UpdateEnemy(hps, cx, cy);
                /* Erase old and draw new scores if there is a change*/
		if (bChangeScore) {
		    bChangeScore = FALSE;
		    DrawScore(hps, cx, cy, DRAW_REINIT);
		    }
                /* Else just refresh the score */
		else
		    DrawScore(hps, cx, cy, DRAW_REFRESH);
		}
	    break;

          /* Game over mode.  This is the longest and ugliest case because  *
           *   conditions are highly dependent on the number of players,    *
           *   multiplayer game status, and the number and order of high    *
           *   scores.                                                      */
	  case GAME_MODE_OVER:
            /* Initially, just update the score and number of ships */
	    if (iGameModeCnt-- == GAME_PAUSE_TIME)
		DrawScore(hps, cx, cy, DRAW_REINIT);

            /* During countdown refresh the score and update the asteroids */
	    else if (iGameModeCnt > 0) {
		if (uiSpeed == SPEED_OS2 || (bSlowUpdateNow = !bSlowUpdateNow)) {
		    DrawScore(hps, cx, cy, DRAW_REFRESH);
		    UpdateAsteroids(hps, cx, cy);
		    }
		}

            /* At the end of the countdown, if there are any other players, *
             *   continue with them.                                        */
	    else {
                /* Countinue on with any remaining players. */
		if ((cPlayers == MAXPLAYERS) &&
                    (Ships[(Player+1) % MAXPLAYERS])) {
                    /* Erase all of the old asteroids. */
		    DrawAsteroids(hps, cx, cy, DRAW_ERASE);

                    /* Setup everything for the next player */
		    Player = (Player+1) % MAXPLAYERS;
		    InitShip();
		    InitEnemy();
		    iGameMode = GAME_MODE_PLAY;
		    DrawAsteroids(hps, cx, cy, DRAW_INIT);
		    DrawScore(hps, cx, cy, DRAW_REINIT);
		    }

                /* Check for new high scores and update table as necessary. */
		else {
                    /* Erase all of the old asteroids. */
		    DrawAsteroids(hps, cx, cy, DRAW_ERASE);


                /* The following if/else block is admittedly a kludge, it is *
                 *   simple and it does work, however.  Ideally it should    *
                 *   sort the high scores and update the high score table in *
                 *   descending order.                                       */

                    /* If player 1 scored higher than player 2 then check *
                     *   player 1 first for a high score.                 */
       		    if (Score[0] > Score[1])
			for (Player=0;Player<cPlayers;Player++)
                            /* If the player's score is > than the lowest, *
                             *   update the high score table.              */
			    if (Score[Player] > prfProfile.lSCORES[9]) {
				UpdateHighScores();
				iGameMode = GAME_MODE_HIGH;
				}
                            /* Otherwise, make sure he is not asked for his *
                             *   initials.                                  */
			    else
				Score[Player] = 0;

                    /* Otherwise, check player 2 first */
		    else
			for (Player=cPlayers;Player>=0;Player--)
                            /* If the player's score is > than the lowest, *
                             *   update the high score table.              */
			    if (Score[Player] > prfProfile.lSCORES[9]) {
				UpdateHighScores();
				iGameMode = GAME_MODE_HIGH;
				}
                            /* Otherwise, make sure he is not asked for his *
                             *   initials.                                  */
			    else
				Score[Player] = 0L;

                    /* If there was no high score, go into attract mode */
		    if (iGameMode != GAME_MODE_HIGH)
			WinSendMsg(hwnd,WM_INITGAME,MPFROMSHORT(1),(MPARAM) 0L);
                    /* Else, check for player 1's initials first then 2's   *
                     * This is not faithful, in the arcade game the player  *
                     *   with the higher score always goes first.           */
		    else {
			if (Score[0] > 0L)
			    Player = 0;
			else
			    Player = 1;
			DrawScore(hps, cx, cy, DRAW_REINIT);
			DrawHighScore(hps, cx, cy, DRAW_INIT);
			}
		    }
		}
	    break;

          /* Mode which prompts players to enter their initials */
	  case GAME_MODE_HIGH:
            /* If the player's position is > 0 then refresh the screen */
	    if (Score[Player] > 0L)
		DrawHighScore(hps, cx, cy, DRAW_REFRESH);
            /* Else, the current player is done go to the next */
	    else if ((cPlayers == MAXPLAYERS) && (Player == 0) &&
		     (Score[1] > 0L)) {
		Player++;
		DrawHighScore(hps, cx, cy, DRAW_REINIT);
		}
            /* If there are no more high scores then go into attract mode */
	    else
		WinSendMsg(hwnd, WM_INITGAME, MPFROMSHORT(1), MPVOID);
	    break;
	  }
	return 0;

      /* Used by help manager */
      case HM_QUERY_KEYS_HELP:
	 return((MRESULT)IDH_CLIENTKEYS);

      /* Recieved always from the system or in the case of an initialization*
       *   error.  Both messages will normally save the profile information.*
       * Ideally the profile section should be moved to a subroutine and the*
       *   the following should be broken into two distinct cases.	    */
      case WM_SAVEAPPLICATION:
      case WM_DESTROY:
	/* If the fonts were not found bApplicationOk will be false, in     *
	 *   that case the window profile information should not be updated.*/
	if (TRUE) {
	    /* Copy window position and size info into profile structure */
	    WinQueryWindowPos(hwndFrame, &swp);
	    if (swp.fl & SWP_MAXIMIZE)
		prfProfile.ulMINMAX = SWP_MAXIMIZE;
	    else if (swp.fl & SWP_MINIMIZE)
		prfProfile.ulMINMAX = SWP_MINIMIZE;
	    else {
		prfProfile.ulMINMAX = 0;
		prfProfile.x  = swp.x;prfProfile.y   = swp.y;
		prfProfile.cx = swp.cx;prfProfile.cy = swp.cy;
		}

	    /* Write profile information */
	    PrfWriteProfileData(HINI_USERPROFILE, szClientClass, "Data",
		&prfProfile, sizeof(PROFILEREC));
	    }

        /* If the application is terminating release the fonts and the hps. */
        if (msg == WM_DESTROY) {
	    /* Make sure mouse is visible if we hid it before */
            ShowMouse(TRUE);
            
	    /* Release font identifiers and DLL resource module */
	    GpiSetCharSet(hps, LCID_DEFAULT);
	    GpiDeleteSetId(hps, LCID_LARGE);
	    GpiDeleteSetId(hps, LCID_SMALL);
	    GpiUnloadFonts(hab, "ASTEROID");

	    /* Release the "permanent" presentation space */
	    WinReleasePS(hps);
            }
	return 0;

      }
    return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
VOID DrawDigitalTime(HWND hwnd)
{
    RECTL rcl;
    RECTL rclChar;
    RECTL rclCharOld;
    RECTL rclTime;
    RECTL rclAmPm;
    RECTL rclDate;
    HPS hpsWnd;
    SIZEF sizef;
    USHORT usi;
    ULONG  ulCharWidth,ulCharModulu;
    char achTime[9];
    char achFinalDate[9];
    time_t     tTime;
    struct tm  *pLocalTime;

    WinQueryWindowRect (hwnd, &rcl);
    hpsWnd = WinGetPS (hwnd);

    memset(achTime,0,sizeof(achTime) );
    memset(achFinalDate,0,sizeof(achFinalDate) );

    GpiCreateLogColorTable (hpsWnd, LCOL_RESET, LCOLF_RGB, 0, 0,
                                 (PLONG) NULL);

    /*
     *if black hands and black background
     *selected force the background to
     *blue
     */

    if( !cp.clrMinuteHand && !cp.clrBackground )
    {
          cp.clrBackground = RGB_BLUE;
    }



    switch (cp.usDispMode & (DM_TIME | DM_DATE))
    {
    case DM_DATE:
        rclDate = rcl;
        break;

    case DM_TIME | DM_DATE:
        if (!fIconic)
        {
            rclTime = rclDate = rcl;
            rclTime.yBottom = rclDate.yTop = rcl.yTop / 2;
            break;
        } /*else fall through*/

    case DM_TIME:
        rclTime = rcl;
        break;
    }

    if (cp.usDispMode & DM_TIME)
    {

        rclAmPm = rclTime;
        time(&tTime);
        pLocalTime = localtime(&tTime);
        if (bTwelveHourFormat)
        {
           strftime(achTime, sizeof(achTime), "%I %M %S", pLocalTime);
        }
        else
        {
           strftime(achTime, sizeof(achTime), "%H %M %S", pLocalTime);
        }

        /*insert country time separator*/
        achTime[2] = achTime[5] = szTimeSep[0];
        achTime[8] = '\000';
        /*Process 12 hours mode*/
        if (bTwelveHourFormat)
        {

            if (fIconic)
            {
                rclTime.yBottom = rclAmPm.yTop = rclTime.yTop / 2;
            }
            else
            {
                rclTime.xRight = rcl.xRight * 8 / 11;
                rclAmPm.xLeft = rclTime.xRight;
            }

            strcpy(achAmPm,szAnteMeridian);

            if (pLocalTime->tm_hour >= 12)
            {
                strcpy(achAmPm,szPostMeridian);
            }

        }

        GpiSetCharMode(hpsWnd, CM_MODE3);

        if (fIconic)
        {
            sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft)
                    / 3), 0);
            sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom)
                    * 1400 / 1000), 0);
        }
        else
        {
            sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft)
                    / 6), 8000);
            sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom)
                    * 1000 / 1500), 0);
        }

        GpiSetCharBox(hpsWnd, &sizef);

        if (bTwelveHourFormat)
        {

            if( strcmp(achAmPm,achOldAmPm) )
            {
                WinFillRect(hpsWnd, &rclAmPm, cp.clrBackground);
                WinDrawText(hpsWnd, sizeof(achAmPm) - 1, (PSZ)achAmPm,
                        (PRECTL)&rclAmPm, cp.clrMinuteHand, cp.clrBackground,
                        DT_CENTER | DT_VCENTER );
            }
        }

        if (!fIconic)
        {

            WinDrawText(hpsWnd, sizeof(achTime) - 1 , (PSZ)achTime,
                    (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground,
                    DT_CENTER | DT_VCENTER | DT_QUERYEXTENT);

            ulCharWidth = (rclTime.xRight - rclTime.xLeft) / (sizeof(achTime) - 1 );
            ulCharModulu = (rclTime.xRight - rclTime.xLeft) % (sizeof(achTime) - 1 );
            rclCharOld.xRight = rclTime.xLeft;

            rclChar.yTop = rclTime.yTop;
            rclChar.yBottom = rclTime.yBottom;

            for (usi = 0; usi < (sizeof(achTime)); usi++)
            {
                rclChar.xLeft = rclCharOld.xRight + (ULONG)1;
                rclChar.xRight = rclChar.xLeft + ulCharWidth +
                        ((ulCharModulu > 0L) ? 1L : 0L);

                if (ulCharModulu)
                    ulCharModulu--;

                if (achTime[usi] == szTimeSep[0])
                {
                    rclChar.xRight -= 3;
                }
                else
                {
                    rclChar.xRight += 1;
                }

                rclCharOld = rclChar;

                if (achTime[usi] != achOldTime[usi])
                {
                    WinFillRect (hpsWnd, &rclChar, cp.clrBackground);
                    if (!((usi == 0) && (achTime[0] == '0') &&
                            (bTwelveHourFormat)))
                        WinDrawText (hpsWnd, 1, (PSZ)&achTime[usi], &rclChar,
                                cp.clrMinuteHand, cp.clrBackground,
                                DT_CENTER | DT_VCENTER);
                }
            }
        }
        else
        {   /*Iconic. just draw if minute changed*/

            if (strncmp(achTime,achOldTime,5))
            {
                WinFillRect(hpsWnd,&rclTime,cp.clrBackground);
                WinDrawText(hpsWnd, sizeof(achTime) - 4 , (PSZ)achTime,
                        (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground,
                        DT_CENTER | DT_VCENTER);
            }
        }
    }

    if ((!(cp.usDispMode & DM_TIME)) || ((cp.usDispMode & DM_DATE) &&
            (!fIconic)))
    {
        GetArrangedDate(achFinalDate);
        if (strncmp(achFinalDate, achOldDate,
                sizeof(achFinalDate) - fIconic ? 4 : 1))
        {

            WinFillRect (hpsWnd, &rclDate, cp.clrBackground);
            GpiSetCharMode (hpsWnd, CM_MODE3);

            sizef.cx = MAKEFIXED(LOUSHORT(
                            (rclDate.xRight - rclDate.xLeft) / 5), 0);
            sizef.cy = MAKEFIXED(LOUSHORT(
                            (rclDate.yTop - rclDate.yBottom) * 1000 / 1500), 0);

            GpiSetCharBox(hpsWnd, &sizef);
            WinDrawText(hpsWnd,
                        (sizeof(achFinalDate) - (fIconic ? 4 : 1) ),
                        (PSZ)achFinalDate,(PRECTL)&rclDate,
                        (LONG)cp.clrMinuteHand,
                        (LONG)cp.clrBackground,
                        (ULONG )(DT_CENTER | DT_VCENTER ) );
        }
    }

    WinReleasePS(hpsWnd);

    strncpy(achOldTime,achTime,sizeof(achOldTime));
    strncpy(achOldAmPm,achAmPm,sizeof(achOldAmPm));
    strncpy(achOldDate,achFinalDate,sizeof(achOldDate));
}
示例#26
0
/*
 * Query the font used for various CSS properties (aID) from the system.
 * For OS/2, only very few fonts are defined in the system, so most of the IDs
 * resolve to the same system font.
 * The font queried will give back a string like
 *    9.WarpSans Bold
 *    12.Times New Roman Bold Italic
 *    10.Times New Roman.Strikeout.Underline
 *    20.Bitstream Vera Sans Mono Obli
 * (always restricted to 32 chars, at least before the second dot)
 * We use the value before the dot as the font size (in pt, and convert it to
 * px using the screen resolution) and then try to use the rest of the string
 * to determine the font style from it.
 */
nsresult nsSystemFontsOS2::GetSystemFont(nsSystemFontID aID, nsString* aFontName,
                                         gfxFontStyle *aFontStyle) const
{
#ifdef DEBUG_thebes
    printf("nsSystemFontsOS2::GetSystemFont: ");
#endif
    char szFontNameSize[MAXNAMEL];

    switch (aID)
    {
    case eSystemFont_Icon:
        QueryFontFromINI("IconText", szFontNameSize, MAXNAMEL);
#ifdef DEBUG_thebes
        printf("IconText ");
#endif
        break;

    case eSystemFont_Menu:
        QueryFontFromINI("Menus", szFontNameSize, MAXNAMEL);
#ifdef DEBUG_thebes
        printf("Menus ");
#endif
        break;

    case eSystemFont_Caption:
    case eSystemFont_MessageBox:
    case eSystemFont_SmallCaption:
    case eSystemFont_StatusBar:
    case eSystemFont_Tooltips:
    case eSystemFont_Widget:

    case eSystemFont_Window:      // css3
    case eSystemFont_Document:
    case eSystemFont_Workspace:
    case eSystemFont_Desktop:
    case eSystemFont_Info:
    case eSystemFont_Dialog:
    case eSystemFont_Button:
    case eSystemFont_PullDownMenu:
    case eSystemFont_List:
    case eSystemFont_Field:
        QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL);
#ifdef DEBUG_thebes
        printf("WindowText ");
#endif
        break;

    default:
        NS_WARNING("None of the listed font types, using WarpSans");
        if (!IsDBCS()) {
            strcpy(szFontNameSize, "9.WarpSans");
        } else {
            strcpy(szFontNameSize, "9.WarpSans Combined");
        }
    } // switch
#ifdef DEBUG_thebes
    printf(" (%s)\n", szFontNameSize);
#endif

    char *szFacename = strchr(szFontNameSize, '.');
    if (!szFacename || (*(szFacename++) == '\0'))
        return NS_ERROR_FAILURE;

    // local DPI for size will be taken into account below
    aFontStyle->size = atof(szFontNameSize);

    // determine DPI resolution of screen device to compare compute
    // font size in pixels
    HPS ps = WinGetScreenPS(HWND_DESKTOP);
    HDC dc = GpiQueryDevice(ps);
    // effective vertical resolution in DPI
    LONG vertScreenRes = 120; // assume 120 dpi as default
    DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &vertScreenRes);
    WinReleasePS(ps);

    // now scale to make pixels from points (1 pt = 1/72in)
    aFontStyle->size *= vertScreenRes / 72.0;

    NS_ConvertUTF8toUTF16 fontFace(szFacename);
    int pos = 0;

    // this is a system font in any case
    aFontStyle->systemFont = true;

    // bold fonts should have " Bold" in their names, at least we hope that they
    // do, otherwise it's bad luck
    NS_NAMED_LITERAL_CSTRING(spcBold, " Bold");
    if ((pos = fontFace.Find(spcBold.get(), false, 0, -1)) > -1) {
        aFontStyle->weight = FONT_WEIGHT_BOLD;
        // strip the attribute, now that we have set it in the gfxFontStyle
        fontFace.Cut(pos, spcBold.Length());
    } else {
        aFontStyle->weight = FONT_WEIGHT_NORMAL;
    }

    // FIXME: Set aFontStyle->stretch correctly!
    aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;

    // similar hopes for italic and oblique fonts...
    NS_NAMED_LITERAL_CSTRING(spcItalic, " Italic");
    NS_NAMED_LITERAL_CSTRING(spcOblique, " Oblique");
    NS_NAMED_LITERAL_CSTRING(spcObli, " Obli");
    if ((pos = fontFace.Find(spcItalic.get(), false, 0, -1)) > -1) {
        aFontStyle->style = FONT_STYLE_ITALIC;
        fontFace.Cut(pos, spcItalic.Length());
    } else if ((pos = fontFace.Find(spcOblique.get(), false, 0, -1)) > -1) {
        // oblique fonts are rare on OS/2 and not specially supported by
        // the GPI system, but at least we are trying...
        aFontStyle->style = FONT_STYLE_OBLIQUE;
        fontFace.Cut(pos, spcOblique.Length());
    } else if ((pos = fontFace.Find(spcObli.get(), false, 0, -1)) > -1) {
        // especially oblique often gets cut by the 32 char limit to "Obli",
        // so search for that, too (anything shorter would be ambiguous)
        aFontStyle->style = FONT_STYLE_OBLIQUE;
        // In this case, assume that this is the last property in the line
        // and cut off everything else, too
        // This is needed in case it was really Obliq or Obliqu...
        fontFace.Cut(pos, fontFace.Length());
    } else {
        aFontStyle->style = FONT_STYLE_NORMAL;
    }

    // just throw away any modifiers that are separated by dots (which are either
    // .Strikeout, .Underline, or .Outline, none of which have a corresponding
    // gfxFont property)
    if ((pos = fontFace.Find(".", false, 0, -1)) > -1) {
        fontFace.Cut(pos, fontFace.Length());
    }

#ifdef DEBUG_thebes
    printf("  after=%s\n", NS_LossyConvertUTF16toASCII(fontFace).get());
    printf("  style: %s %s %s\n",
           (aFontStyle->weight == FONT_WEIGHT_BOLD) ? "BOLD" : "",
           (aFontStyle->style == FONT_STYLE_ITALIC) ? "ITALIC" : "",
           (aFontStyle->style == FONT_STYLE_OBLIQUE) ? "OBLIQUE" : "");
#endif
    NS_NAMED_LITERAL_STRING(quote, "\""); // seems like we need quotes around the font name
    *aFontName = quote + fontFace + quote;

    return NS_OK;
}
示例#27
0
/****************************************************************************
   Titlebar Dialog Procedure
*****************************************************************************/
MRESULT EXPENTRY TitleBarProc (HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    {
        BOOL    Handled = TRUE;
        MRESULT mReturn  = 0;
        RECTL   Rectl;
        POINTL  Pointl;
        
        CHARBUNDLE cb;
        FONTMETRICS Fontsz;
        PSZ     TitleText = szTitle;
        ULONG   temp;
        HPS     hps;

        switch (msg)
            {
                case    WM_SETWINDOWPARAMS:
                    if( ((WNDPARAMS*)mp1)->fsStatus & WPM_TEXT )
                        {
                            TitleText = ((WNDPARAMS*)mp1)->pszText;
                        }
                    Handled = FALSE;
                    break;
                case    TBM_SETHILITE:
                    mReturn = (MRESULT)TRUE;
                    hps = WinGetPS(hWnd);
                    WinQueryWindowRect(hWnd,&Rectl);
                    WinFillRect(hps, &Rectl, CLR_BLACK);
                    GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),(PFONTMETRICS)&Fontsz);
                    Pointl.x = 10;
                    Pointl.y = (Rectl.yTop - Fontsz.lMaxAscender) / 2;
                    cb.lColor = CLR_GREEN;
                    cb.lBackColor = CLR_BLACK;
                    cb.usMixMode = BM_OVERPAINT;
                    cb.usBackMixMode = BM_OVERPAINT;
                    GpiSetAttrs(hps,PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR 
                       | CBB_MIX_MODE | CBB_BACK_MIX_MODE, 0,(PBUNDLE)&cb);
                    GpiCharStringAt(hps, &Pointl, strlen(TitleText), TitleText);
                    WinEndPaint(hps);
                    WinReleasePS(hps);
                    break;
                case    WM_PAINT:
                    hps = WinBeginPaint(hWnd, 0, 0);
                    WinQueryWindowRect(hWnd,&Rectl);
                    WinFillRect(hps, &Rectl, CLR_BLACK);
                    GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),(PFONTMETRICS)&Fontsz);
                    Pointl.x = 10;
                    Pointl.y = (Rectl.yTop - Fontsz.lMaxAscender) / 2;
                    cb.lColor = CLR_GREEN;
                    cb.lBackColor = CLR_BLACK;
                    cb.usMixMode = BM_OVERPAINT;
                    cb.usBackMixMode = BM_OVERPAINT;
                    GpiSetAttrs(hps,PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR 
                       | CBB_MIX_MODE | CBB_BACK_MIX_MODE, 0,(PBUNDLE)&cb);
                    GpiCharStringAt(hps, &Pointl, strlen(TitleText), TitleText);
                    WinEndPaint(hps);
                    break;
                default:
                    Handled = FALSE;
                    break;
            }
        if (!Handled) mReturn =  (*TitleDefProc)(hWnd, msg, mp1, mp2);
        return (mReturn);
    }
示例#28
0
// *******************************************************************************
// FUNCTION:     GetBitmapFromTrack
//
// FUNCTION USE: Creates a bitmap from a rectangle structure
//
// DESCRIPTION:  This function takes the rectangle structure that is created 
//               as a result of the tracking operation and creates a bitmap 
//               of that area.  
//
// PARAMETERS:   RECTL    tracking rectangle
//
// RETURNS:      HBITMAP  bitmap handle
//
// INTERNALS:    NONE
//
// HISTORY:
//
// *******************************************************************************
HBITMAP GetBitmapFromTrack (RECTL rclTrack)
{
 HAB                hab;                           
 HBITMAP            hbmTrack;
 HDC                hdcMemory;
 HPS                hpsMemory;
 HPS                hpsScreen;
 LONG               lFormats[2];
 POINTL             aptl[3];
 SIZEL              sizl;
 BITMAPINFOHEADER2  bmp2;

 // --------------------------------------------------------------------------                    
 // Get an anchor block handle                                                                    
 // --------------------------------------------------------------------------                    
 hab = WinQueryAnchorBlock(HWND_DESKTOP);

 // --------------------------------------------------------------------------                    
 // Get a memory device context                                                                  
 // --------------------------------------------------------------------------                    
 hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE) ;

 // --------------------------------------------------------------------------                    
 // Set presentation space size                                                                
 // --------------------------------------------------------------------------                    
 sizl.cx = sizl.cy = 0 ;

 // --------------------------------------------------------------------------                             
 // Create a micro presentation space and associate it                                                                           
 // --------------------------------------------------------------------------                             
 hpsMemory = GpiCreatePS (hab,
                          hdcMemory,
                          &sizl,
                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);

 // --------------------------------------------------------------------------           
 // Call GpiQueryDeviceBitmapFormats to get the number of bit planes                                   
 // --------------------------------------------------------------------------           
 GpiQueryDeviceBitmapFormats (hpsMemory,
                              2L,
                              lFormats);

 // --------------------------------------------------------------------------        
 // Initialize the bitmap info header structure                 
 // --------------------------------------------------------------------------        
 memset(&bmp2, 0, sizeof(BITMAPINFOHEADER2));

 // --------------------------------------------------------------------------                     
 // Populate the bitmap info header structure                                                    
 // --------------------------------------------------------------------------                     
 bmp2.cbFix     = sizeof bmp2;
 bmp2.cx        = (rclTrack.xRight - rclTrack.xLeft);
 bmp2.cy        = (rclTrack.yTop   - rclTrack.yBottom);
 bmp2.cPlanes   = lFormats[0];
 bmp2.cBitCount = lFormats[1];

 // --------------------------------------------------------------------------         
 // Create a bitmap representing the tracking rectangle                                
 // --------------------------------------------------------------------------         
 hbmTrack = GpiCreateBitmap (hpsMemory, &bmp2, 0L, NULL, NULL);

 if (hbmTrack == GPI_ERROR)
  {
   return GPI_ERROR;
  }

 else
  {
   // --------------------------------------------------------------------------        
   // Set the bitmap into our memory presentation space.                                                                      
   // --------------------------------------------------------------------------        
   GpiSetBitmap (hpsMemory, hbmTrack);
   hpsScreen = WinGetScreenPS (HWND_DESKTOP);
  
   aptl[0].x = 0;
   aptl[0].y = 0;
   aptl[1].x = bmp2.cx;
   aptl[1].y = bmp2.cy;
   aptl[2].x = rclTrack.xLeft;
   aptl[2].y = rclTrack.yBottom;
  
   WinLockVisRegions (HWND_DESKTOP, TRUE);
  
   // --------------------------------------------------------------------------                 
   // Bit blit the contents of the source presentation space into our target                     
   // presentation space.  This is how we copy the bitmap from the source to                     
   // the target.                                                                                
   // --------------------------------------------------------------------------                 
   GpiBitBlt (hpsMemory,      //  Target presentation space handle           
              hpsScreen,      //  Source presentation space handle           
              3L,             //  Number of Points                           
              aptl,           //  Array of Points                            
              ROP_SRCCOPY,    //  Mixing function (source copy)              
              BBO_IGNORE);    //  Options                                    
  
   WinLockVisRegions (HWND_DESKTOP, FALSE);
   WinReleasePS (hpsScreen);
  }

 // --------------------------------------------------------------------------                  
 // Free Graphics Engine Resources 
 // --------------------------------------------------------------------------                  
 GpiDestroyPS (hpsMemory);
 DevCloseDC (hdcMemory);

 // --------------------------------------------------------------------------                  
 // Return bitmap handle           
 // --------------------------------------------------------------------------                  
 return hbmTrack;
}
示例#29
0
文件: ktbhelp.c 项目: komh/ktb
static
MRESULT EXPENTRY helpWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
    static CHAR szText[ 256 ] = "";
    static HPS hps = NULLHANDLE;
    static USHORT width = 0, height = 0;

    switch( msg )
    {
        case WM_CREATE :
        {
            FONTMETRICS fm;

            strcpy( szText, (( PCREATESTRUCT )mp2 )->pszText );

            hps = WinGetPS( hwnd );
            GpiQueryFontMetrics( hps, sizeof( fm ), &fm );
            width = fm.lAveCharWidth;
            height = fm.lMaxAscender + fm.lMaxDescender;

            return MRFROMSHORT( FALSE );
        }

        case WM_DESTROY :
            WinReleasePS( hps );

            return MRFROMSHORT( FALSE );

        case WM_SETWINDOWPARAMS :
        {
            PWNDPARAMS  pwp;

            pwp = ( PWNDPARAMS )mp1;
            if( pwp->fsStatus & WPM_TEXT )
                strcpy( szText, pwp->pszText );

            return MRFROMSHORT( TRUE );
        }

        case WM_PAINT :
        {
            RECTL   rcl;

            WinBeginPaint( hwnd, hps, NULL );

            WinQueryWindowRect( hwnd, &rcl );

            WinDrawBorder( hps, &rcl, 1, 1, CLR_BLACK, CLR_YELLOW, DB_INTERIOR );
            WinDrawText( hps, -1, szText, &rcl, CLR_BLACK, CLR_YELLOW,
                         DT_CENTER | DT_VCENTER );

            WinEndPaint( hps );

            return MRFROMSHORT( 0 );
        }

        case WM_QUERY_CHAR_WIDTH :
            return MRFROMSHORT( width );

        case WM_QUERY_CHAR_HEIGHT :
            return MRFROMSHORT( height );
    }

    return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
示例#30
0
MRESULT EXPENTRY ClientWndProc ( HWND hwndWnd, ULONG ulMsg, MPARAM mpParm1, MPARAM mpParm2 )
{
   switch ( ulMsg )
   {
   // For HELP debugging
   #if 0
      case HM_ERROR:
         {
            CHAR     szTempBuffer[256];

            sprintf( szTempBuffer, "Received HM_ERROR message, mp1=0X%8.8X", (ULONG)mpParm1 );
            WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, szTempBuffer, "HM_ERROR", 0, MB_OK );
         }
         break;

      case HM_EXT_HELP_UNDEFINED:
         WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, "Received HM_EXT_HELP_UNDEFINED message", "HM_EXT_HELP_UNDEFINED", 0, MB_OK );
         break;

      case HM_HELPSUBITEM_NOT_FOUND:
         WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, "Received HM_HELPSUBITEM_NOT_FOUND message", "HM_HELPSUBITEM_NOT_FOUND", 0, MB_OK );
         break;
   #endif

      case HM_QUERY_KEYS_HELP:
         return (MRESULT)IDP_KEYS_INFO;
         break;

      case WM_BUTTON1CLICK:
         MoveCursorToPointer( hwndWnd, (*(POINTS *)&mpParm1).x, (*(POINTS *)&mpParm1).y );
         break;

   #if 0
      case WM_BUTTON2CLICK:
         {
            HPS      hpsClient;
            POINTL   ptl;
            INT      xC, yC;


            xC = ( ( (*(POINTS *)&mpParm1).x - cxChar) / cxChar );
            yC = ( ( cyClient - (*(POINTS *)&mpParm1).y ) / cyChar );

            hpsClient = WinGetPS( hwndWnd );
            GpiSetColor( hpsClient, CLR_PALEGRAY );
            if ( xC < 10 )
               GpiSetMix( hpsClient, FM_XOR );
            else if ( xC < 20 )
               GpiSetMix( hpsClient, FM_INVERT );
            else if ( xC < 30 )
               GpiSetMix( hpsClient, FM_NOTXORSRC );
            else if ( xC < 40 )
               GpiSetMix( hpsClient, FM_NOTMASKSRC );
            else if ( xC < 50 )
               GpiSetMix( hpsClient, FM_SUBTRACT );
///            GpiSetBackColor( hpsClient, CLR_PALEGRAY );
///            GpiSetBackMix( hpsClient, BM_OVERPAINT );
///            ptl.x = ( ( (*(POINTS *)&mpParm1).x - cxChar ) / cxChar ) * cxChar + cxChar;
///            ptl.y = ( ( (*(POINTS *)&mpParm1).y - cyClient ) / cyChar - 1 ) * cyChar + cyClient;
            ptl.x = cxChar + ( xC * cxChar );
            ptl.y = cyClient - ( ( yC + 1) * cyChar );
            GpiMove( hpsClient, &ptl );
            ptl.x += cxChar;
            ptl.y += cyChar;
            if ( yC < 5 )
               GpiBox( hpsClient, DRO_FILL, &ptl, 0, 0 );
            else
               GpiBox( hpsClient, DRO_OUTLINE, &ptl, 0, 0 );
///            GpiSetBackColor( hpsClient, CLR_BACKGROUND );
///            GpiSetMix( hpsClient, FM_DEFAULT );
            WinReleasePS( hpsClient );
         }
         break;
   #endif

      case WM_CHAR:
         if ( !( CHARMSG(&ulMsg)->fs & KC_KEYUP ) )
         {
            if ( CHARMSG(&ulMsg)->fs & KC_CHAR )
            {
               ProcessCharMsg( hwndWnd, ulMsg, mpParm1, mpParm2 );
            }
            else if ( CHARMSG(&ulMsg)->fs & KC_VIRTUALKEY )
            {
               if ( !ProcessCursorMsg( hwndWnd, ulMsg, mpParm1, mpParm2 ) )
               {
                  return WinDefWindowProc( hwndWnd, ulMsg, mpParm1, mpParm2 );
               }
            }
         }
         break;

      case WM_CLOSE:
         if ( QueryAbandonChanges( hwndWnd ) )
            return WinDefWindowProc ( hwndWnd, ulMsg, mpParm1, mpParm2 );
         break;

      case WM_COMMAND:
         return ProcessCommandMsg( hwndWnd, ulMsg, mpParm1, mpParm2 );
         break;

      case WM_CREATE:
         hwndMenu = WinWindowFromID( WinQueryWindow( hwndWnd, QW_PARENT ), FID_MENU );
         hwndHScroll = WinWindowFromID( WinQueryWindow( hwndWnd, QW_PARENT ), FID_HORZSCROLL );
         hwndVScroll = WinWindowFromID( WinQueryWindow( hwndWnd, QW_PARENT ), FID_VERTSCROLL );
         SetWindowTitle( hwndWnd );
         break;

      case WM_DESTROY:
         ClearFile( hwndWnd );
         break;

      case WM_ERASEBACKGROUND:
         return MRFROMSHORT ( TRUE ) ;

      case WM_HELP:
         ProcessHelpMessage( hwndWnd, mpParm1, mpParm2 );
         break;

      case WM_HSCROLL:
         if ( !ProcessHScrollMsg( hwndWnd, ulMsg, mpParm1, mpParm2 ) )
            return WinDefWindowProc( hwndWnd, ulMsg, mpParm1, mpParm2 );
         break;

      case WM_PAINT:
         PaintScreen( hwndWnd );
         break;

      case WM_SAVEAPPLICATION:
         SaveSettings( hwndWnd, habAnchor );
         return WinDefWindowProc( hwndWnd, ulMsg, mpParm1, mpParm2 );
         break;

      case WM_SETFOCUS:
         if ( SHORT1FROMMP( mpParm2 ) )
            CreateCursor( hwndWnd );
         else
            DestroyCursor( hwndWnd );
         break;

      case WM_SIZE:
         UpdateWindowSize( hwndWnd, SHORT1FROMMP( mpParm2), SHORT2FROMMP( mpParm2 ) );
         if ( hwndWnd == WinQueryFocus( HWND_DESKTOP ) )
         {
            DestroyCursor( hwndWnd );
            CreateCursor( hwndWnd );
         }
         break;

      case WM_VSCROLL:
         if ( !ProcessVScrollMsg( hwndWnd, ulMsg, mpParm1, mpParm2 ) )
            return WinDefWindowProc( hwndWnd, ulMsg, mpParm1, mpParm2 );
         break;

      default:
         return WinDefWindowProc( hwndWnd, ulMsg, mpParm1, mpParm2 );
         break;
   }

   return MRFROMSHORT ( FALSE ) ;
}