home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / cbsdk10.zip / C-CALEND.C < prev    next >
C/C++ Source or Header  |  1992-11-06  |  6KB  |  256 lines

  1. // === calend.c ===
  2.  
  3. // Calendar Add-In for the clySmic Icon Bar. (C) 1992 by clySmic Software.
  4. // All Rights Reserved.
  5.  
  6. #include "c:\winsdk\include\windows.h"
  7. #include <stdio.h>
  8. #include <dos.h>
  9.  
  10. #include "add-in.h"
  11.  
  12. HANDLE  hInstance;                   // DLL's instance handle
  13. BOOL ShowDOW = TRUE;
  14. struct dosdate_t Today;
  15.  
  16. #define CBVer "1.70"
  17.  
  18. /*-------------------------------------------------------------------*/
  19.  
  20. // LibMain
  21.  
  22. int FAR PASCAL LibMain(HANDLE hLibInst, WORD wDataSeg,
  23.                        WORD cbHeapSize, LPSTR lpszCmdLine)
  24. {
  25.   hInstance = hLibInst;
  26.   return 1;
  27.  
  28. } /*LibMain*/
  29.  
  30. /*-------------------------------------------------------------------*/
  31.  
  32. // Windows Exit Procedure
  33.  
  34. int FAR PASCAL WEP(int bSystemExit)
  35. {
  36.   return 1;
  37.  
  38. } /*WEP*/
  39.  
  40. /*-------------------------------------------------------------------*/
  41.  
  42. // Utility Function
  43.  
  44. int CenterTx(HDC DC, char *Tx, RECT Rect)
  45.  
  46. {
  47.   int Width,WinX,StrtX;
  48.  
  49.   // Ask Windows for the total pixel length of the string & calc starting X
  50.   Width = LOWORD(GetTextExtent(DC,Tx,strlen(Tx)));
  51.  
  52.   // Get total x width of window - don"t add 1!
  53.   WinX = (Rect.right - Rect.left);
  54.  
  55.   // Calculate centered starting posn
  56.   StrtX = ((WinX - Width) / 2) + Rect.left;
  57.  
  58.   return StrtX;
  59.  
  60. } /*CenterTx*/
  61.  
  62. /*-------------------------------------------------------------------*/
  63.  
  64. // Perform Add-In's initialization
  65.  
  66. InitResult FAR PASCAL InitAddIn(char far *CurVer)
  67.  
  68. {
  69.   // Version check
  70.   if (strcmp(CurVer,CBVer) != 0)
  71.     return InitNotOk;
  72.   else
  73.     return InitOk;
  74.  
  75. } /*InitAddIn*/
  76.  
  77. /*-------------------------------------------------------------------*/
  78.  
  79. // Paint on the button (Clysbar does the background)
  80.  
  81. VOID FAR PASCAL PaintAddIn(HWND Wnd, HDC DC, BOOLEAN Pressed)
  82.  
  83. {
  84.   char *MonthName[12] =
  85.     {"JAN","FEB","MAR","APR","MAY","JUN",
  86.      "JUL","AUG","SEP","OCT","NOV","DEC"};
  87.  
  88.   char *Days[7] =
  89.      {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  90.  
  91.   RECT Rect;
  92.   HFONT NumFont,OldFont,SmlFont;
  93.   char Tx[128];
  94.   char StrYr[5],StrDay[5];       // or 4?
  95.   int StrtX,StrtY;
  96.   HICON TheIcon;
  97.  
  98.   GetClientRect(Wnd,&Rect);
  99.  
  100.   StrtX = ((Rect.right - Rect.left) - GetSystemMetrics(SM_CXICON)) / 2;
  101.   StrtY = ((Rect.bottom - Rect.top) - GetSystemMetrics(SM_CYICON)) / 2;
  102.  
  103.   // Draw turning page if pressed
  104.   if (Pressed)
  105.     {
  106.       TheIcon = LoadIcon(hInstance,"CALEND2");
  107.       DrawIcon(DC,StrtX+1,StrtY+1,TheIcon);
  108.  
  109.       return;
  110.     }
  111.  
  112.   TheIcon = LoadIcon(hInstance,"CALEND");
  113.   DrawIcon(DC,StrtX,StrtY,TheIcon);
  114.  
  115.   _dos_getdate(&Today);
  116.  
  117.   itoa(Today.day,StrDay,10);
  118.   itoa(Today.year,StrYr,10);
  119.  
  120.   // Lop off 1st two year digits
  121.   StrYr[0] = StrYr[2];
  122.   StrYr[1] = StrYr[3];
  123.   StrYr[2] = NULL;
  124.  
  125.   SmlFont =
  126.   CreateFont(9,             // Height
  127.              0,0,0,         // Width, left 2 right, normal orientation
  128.              400,           // Weight
  129.              0,0,0,         // Italic, underlined, or strikeout
  130.              0,             // ANSI char set
  131.              0,             // Reserved precision field
  132.              0,             // Default clipping
  133.              PROOF_QUALITY, // Quality
  134.              FF_ROMAN | VARIABLE_PITCH,
  135.              "Small Fonts");
  136.  
  137.   NumFont =
  138.   CreateFont(17,            // Height
  139.              0,0,0,         // Width, left 2 right, normal orientation
  140.              700,           // Weight
  141.              0,0,0,         // Italic, underlined, or strikeout
  142.              0,             // ANSI char set
  143.              0,             // Reserved precision field
  144.              0,             // Default clipping
  145.              PROOF_QUALITY, // Quality
  146.              FF_ROMAN | VARIABLE_PITCH,
  147.              "Times New Roman");
  148.  
  149.   OldFont = SelectObject(DC,NumFont);
  150.  
  151.   SetBkMode(DC,TRANSPARENT);
  152.   SetTextColor(DC,RGB(0,0,0));
  153.  
  154.   Rect.top++;
  155.  
  156.   DrawText(DC,StrDay,strlen(StrDay),&Rect,
  157.            DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  158.  
  159.   SelectObject(DC,SmlFont);
  160.  
  161.   // Adjust rect to account for off-center pad image
  162.   Rect.right -= 2;
  163.  
  164.   SetTextColor(DC,RGB(255,0,0));
  165.   strcpy(Tx,MonthName[Today.month-1]);
  166.   TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 3,Tx,strlen(Tx));
  167.  
  168.   if (ShowDOW)
  169.     {
  170.       strcpy(Tx,Days[Today.dayofweek]);
  171.       SetTextColor(DC,RGB(0,0,128));
  172.       TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,strlen(Tx));
  173.     }
  174.   else
  175.     {
  176.       strcpy(Tx,StrYr);
  177.       SetTextColor(DC,RGB(128,0,128));
  178.       TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,strlen(Tx));
  179.     }
  180.  
  181.   SelectObject(DC,OldFont);
  182.   DeleteObject(SmlFont);
  183.   DeleteObject(NumFont);
  184.  
  185. } /*PaintAddIn*/
  186.  
  187. /*-------------------------------------------------------------------*/
  188.  
  189. // Tell Clysbar what kind of timer we need
  190.  
  191. int FAR PASCAL TimerNeeded()
  192.  
  193. {
  194.   return ait_Slow;
  195. }
  196.  
  197. /*-------------------------------------------------------------------*/
  198.  
  199. // Proc called when timer expires, perform timed duties
  200.  
  201. VOID FAR PASCAL AddInTimer(HWND Wnd, HDC DC)
  202.  
  203. {
  204.   struct dosdate_t TstDate;
  205.  
  206.   // Check for a date change
  207.   _dos_getdate(&TstDate);
  208.  
  209.   // If different date, repaint window
  210.   if (TstDate.day != Today.day)
  211.     PaintAddIn(Wnd,DC,FALSE);
  212.  
  213. } /*AddInTimer*/
  214.  
  215. /*-------------------------------------------------------------------*/
  216.  
  217. // Proc called when button pressed and released (used for toggling states)
  218.  
  219. VOID FAR PASCAL AddInPressed(HWND Wnd, HDC DC)
  220.  
  221. {
  222.   // Toggle the "show day-of-week" indicator when button pressed
  223.   ShowDOW = !ShowDOW;
  224.  
  225.   PaintAddIn(Wnd,DC,FALSE);
  226. } /*AddInPressed*/
  227.  
  228. /*-------------------------------------------------------------------*/
  229.  
  230. // Exit processing for Add-In
  231.  
  232. VOID FAR PASCAL ExitAddIn()
  233.  
  234. {
  235. } /*ExitAddIn*/
  236.  
  237. /*-------------------------------------------------------------------*/
  238.  
  239. // Clysbar queries Add-In about itself for About box
  240.  
  241. VOID FAR PASCAL AddInAbout(char far *Str1, char far *Str2,
  242.                            HICON far *TheIcon,
  243.                            COLORREF far *TitleCol,
  244.                            COLORREF far *TxCol,
  245.                            COLORREF far *BkCol)
  246.  
  247. {
  248.   strcpy(Str1,"C-Calend V1.00");
  249.   strcpy(Str2,"'C' Code Example Version\n⌐ 1992 by clySmic Software.\nAll Rights Reserved.");
  250.  
  251.   *TheIcon = LoadIcon(hInstance,"ABOUT");
  252.   *TitleCol = RGB(255,255,255);
  253.   *TxCol = RGB(192,192,192);
  254.   *BkCol = RGB(255,0,0);
  255. } /*AddInAbout*/
  256.