home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap18 / cosmo1.0 / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.7 KB  |  138 lines

  1. /*
  2.  * MISC.C
  3.  *
  4.  * Functions without any other reasonable home:
  5.  *  WindowTitleSet, RectConvertToHiMetric, RectConvertToDevice
  6.  *
  7.  * Copyright(c) Microsoft Corp. 1992-1994 All Rights Reserved
  8.  * Win32 version, January 1994
  9.  */
  10.  
  11.  
  12. #include <windows.h>
  13. #include <ole.h>
  14. #include "cosmo.h"
  15.  
  16.  
  17.  
  18.  
  19. /*
  20.  * WindowTitleSet
  21.  *
  22.  * Purpose:
  23.  *  Handles changing the window's caption bar depending on the file
  24.  *  that is loaded.
  25.  *
  26.  * Parameters:
  27.  *  hWnd            HWND of the window to change.
  28.  *  pszFile         LPSTR of the file loaded.
  29.  *
  30.  * Return Value:
  31.  *  none.
  32.  */
  33.  
  34. void WINAPI WindowTitleSet(HWND hWnd, LPSTR pszFile)
  35.     {
  36.     char        szTitle[CCHPATHMAX];
  37.  
  38.     wsprintf(szTitle, "%s - %s", (LPSTR)rgpsz[IDS_CAPTION], pszFile);
  39.     SetWindowText(hWnd, szTitle);
  40.     return;
  41.     }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. /*
  50.  * RectConvertToHiMetric
  51.  *
  52.  * Purpose:
  53.  *  Converts the contents of a rectangle from MM_TEXT into MM_HIMETRIC
  54.  *  specifically for use in converting a RECT of a window into
  55.  *  a RECT for a METAFILEPICT structure.
  56.  *
  57.  * Parameters:
  58.  *  hWnd            HWND of the window providing the display context
  59.  *  pRect           LPRECT containing the rectangle to convert.
  60.  *
  61.  * Return Value:
  62.  *  None.
  63.  */
  64.  
  65. void WINAPI RectConvertToHiMetric(HWND hWnd, LPRECT pRect)
  66.     {
  67.     HDC      hDC;
  68.     POINT    pt;
  69.  
  70.     hDC=GetDC(hWnd);
  71.     SetMapMode(hDC, MM_HIMETRIC);
  72.  
  73.     //Convert upper left corner
  74.     pt.x=pRect->left;
  75.     pt.y=pRect->top;
  76.     DPtoLP(hDC, &pt, 1);
  77.     pRect->left=pt.x;
  78.     pRect->top=-pt.y;
  79.  
  80.     //Convert lower right corner
  81.     pt.x=pRect->right;
  82.     pt.y=pRect->bottom;
  83.     DPtoLP(hDC, &pt, 1);
  84.     pRect->right=pt.x;
  85.     pRect->bottom=-pt.y;
  86.  
  87.     ReleaseDC(hWnd, hDC);
  88.     return;
  89.     }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /*
  98.  * RectConvertToDevice
  99.  *
  100.  * Purpose:
  101.  *  Converts the contents of a rectangle from MM_HIMETRIC into MM_TEXT
  102.  *  specifically for use in converting a RECT of an OLE object into
  103.  *  a RECT for a window.
  104.  *
  105.  * Parameters:
  106.  *  hWnd            HWND of the window providing the display context
  107.  *  pRect           LPRECT containing the rectangle to convert.
  108.  *
  109.  * Return Value:
  110.  *  None.
  111.  */
  112.  
  113. void WINAPI RectConvertToDevice(HWND hWnd, LPRECT pRect)
  114.     {
  115.     HDC      hDC;
  116.     POINT    pt;
  117.  
  118.     hDC=GetDC(hWnd);
  119.     SetMapMode(hDC, MM_HIMETRIC);
  120.  
  121.     //Convert upper left corner
  122.     pt.x=pRect->left;
  123.     pt.y=pRect->bottom;
  124.     LPtoDP(hDC, &pt, 1);
  125.     pRect->left=pt.x;
  126.     pRect->bottom=pt.y;
  127.  
  128.     //Convert lower right corner
  129.     pt.x=pRect->right;
  130.     pt.y=pRect->top;
  131.     LPtoDP(hDC, &pt, 1);
  132.     pRect->right=pt.x;
  133.     pRect->top=pt.y;
  134.  
  135.     ReleaseDC(hWnd, hDC);
  136.     return;
  137.     }
  138.