home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / vbxwzrd / backgrnd.c~ < prev    next >
Encoding:
Text File  |  1995-03-19  |  6.5 KB  |  193 lines

  1. //---------------------------------------------------------------------------
  2. // BackGrnd.c
  3. //---------------------------------------------------------------------------
  4. // Contains control procedure for BackGrnd control
  5. //---------------------------------------------------------------------------
  6.  
  7. #include <windows.h>
  8. #include "vbapi.h"
  9. #include "BackGrnd.h"
  10.  
  11. //---------------------------------------------------------------------------
  12. // Local Prototypes
  13. //---------------------------------------------------------------------------
  14. BOOL _export FAR PASCAL AboutDlgProc(HWND hDlg, USHORT msg, USHORT wp, LONG lp);
  15.  
  16. //---------------------------------------------------------------------------
  17. // Global Variables
  18. //---------------------------------------------------------------------------
  19. HANDLE hmodDLL;
  20.  
  21.  
  22. //---------------------------------------------------------------------------
  23. // BackGrnd Control Procedure
  24. //---------------------------------------------------------------------------
  25. LONG FAR PASCAL _export BackGrndCtlProc
  26. (
  27.     HCTL   hctl,
  28.     HWND   hwnd,
  29.     USHORT msg,
  30.     USHORT wp,
  31.     LONG   lp
  32. )
  33. {
  34.     switch (msg)
  35.         {       
  36.         case WM_PAINT:
  37.             {
  38.             PAINTSTRUCT ps;
  39.             HDC  MemDC; 
  40.             HBRUSH hBrush;
  41.               HBRUSH hBrushOld;            
  42.               RECT   rect;
  43.               PIC    Pic;
  44.               HPIC   hPic;
  45.               BITMAP Bmp;
  46.               int    X;
  47.               int    Y; 
  48.               if (VBGetMode()==MODE_RUN) VBFireEvent(hctl, IEVENT_BackGrnd_BeginPaint, NULL);
  49.             BeginPaint(hwnd, &ps);   
  50.             VBGetControlProperty(hctl, IPROP_BackGrnd_Picture, &hPic);
  51.             if (hPic!=0)
  52.             {
  53.             VBGetPic(hPic, &Pic);
  54.             hBrush = (HBRUSH)GetBrushOrg(ps.hdc);
  55.               if (hBrush) hBrushOld = SelectObject(ps.hdc, hBrush);
  56.               GetClientRect(hwnd, &rect);
  57.               GetObject(Pic.picData.bmp.hbitmap, sizeof(BITMAP), (LPSTR)&Bmp);
  58.               MemDC = CreateCompatibleDC(ps.hdc);
  59.               SelectObject(MemDC, Pic.picData.bmp.hbitmap);                        
  60.               Y = 0;                          
  61.             while (Y < rect.bottom)
  62.             {       
  63.               X = 0;         
  64.                 while (X < rect.right) 
  65.                 {     
  66.                   BitBlt(ps.hdc, X, Y, Bmp.bmWidth, Bmp.bmHeight, MemDC, 0, 0, SRCCOPY);
  67.                 X = X + Bmp.bmWidth;
  68.                 } 
  69.                 Y = Y + Bmp.bmHeight;
  70.             } 
  71.               SelectObject(ps.hdc, hBrushOld);                        
  72.               DeleteDC(MemDC);                                  
  73.               }
  74.             EndPaint(hwnd, &ps);
  75.             if (VBGetMode()==MODE_RUN) VBFireEvent(hctl, IEVENT_BackGrnd_EndPaint, NULL);
  76.             break;
  77.             }
  78.         case VBM_SETPROPERTY:
  79.             if (wp==IPROP_BackGrnd_Picture) InvalidateRect(hwnd, NULL, TRUE);
  80.             break;
  81.         case WM_USER:
  82.             VBDialogBoxParam(hmodDLL, "ABOUT", (FARPROC)AboutDlgProc, 0L);
  83.             break;
  84.         case VBM_INITPROPPOPUP:
  85.             if (wp==3)
  86.                 {
  87.                   PostMessage(hwnd,WM_USER,0,0);
  88.                   return (lp+1)&&(0xFFFF);
  89.                 }
  90.             break;
  91.         }
  92.     return VBDefControlProc(hctl, hwnd, msg, wp, lp);
  93. }
  94. // This routine handles the 'About' Dialog Box messages 
  95. BOOL FAR PASCAL _export AboutDlgProc
  96. (
  97.     HWND   hDlg,
  98.     USHORT msg,
  99.     USHORT wp,
  100.      LONG   lp
  101. )
  102. {
  103.      switch (msg)
  104.           {
  105.           case WM_CREATE:
  106.                 // Avoid warnings on unused (but required) formal parameters
  107.                 lp = lp;
  108.                 return TRUE;
  109.         case WM_INITDIALOG:
  110.             return FALSE;
  111.         case WM_COMMAND:
  112.             if ((wp==IDOK)||(wp==IDCANCEL))
  113.                     EndDialog(hDlg, TRUE);
  114.                     return TRUE;
  115.           }
  116.     return FALSE;
  117. }
  118. //---------------------------------------------------------------------------
  119. // Register custom control. This routine is called by VB when the custom
  120. // control DLL is loaded for use.
  121. //---------------------------------------------------------------------------
  122. BOOL FAR PASCAL _export VBINITCC
  123. (
  124.     USHORT usVersion,
  125.     BOOL   fRuntime
  126. )
  127. {
  128.      // Avoid warnings on unused (but required) formal parameters
  129.      fRuntime  = fRuntime;
  130.      usVersion = usVersion;
  131.      // Register control(s)
  132.      return VBRegisterModel(hmodDLL, &modelBackGrnd);
  133. }
  134.  
  135.  
  136. //---------------------------------------------------------------------------
  137. // Initialize library.  This routine is called when the first client loads
  138. // the DLL.
  139. //---------------------------------------------------------------------------
  140. int FAR PASCAL LibMain
  141. (
  142.     HANDLE hModule,
  143.     WORD   wDataSeg,
  144.     WORD   cbHeapSize,
  145.     LPSTR  lpszCmdLine
  146. )
  147. {
  148.     // Avoid warnings on unused (but required) formal parameters
  149.     wDataSeg    = wDataSeg;
  150.     cbHeapSize  = cbHeapSize;
  151.     lpszCmdLine = lpszCmdLine;
  152.  
  153.     hmodDLL = hModule;
  154.  
  155.     return 1;
  156. }
  157. //---------------------------------------------------------------------------
  158. // WEP
  159. //---------------------------------------------------------------------------
  160. // C7 and QCWIN provide default a WEP:
  161. //---------------------------------------------------------------------------
  162. #if (_MSC_VER < 610)
  163. int FAR PASCAL WEP(int fSystemExit);
  164. //---------------------------------------------------------------------------
  165. // For Windows 3.0 it is recommended that the WEP function reside in a
  166. // FIXED code segment and be exported as RESIDENTNAME.  This is
  167. // accomplished using the alloc_text pragma below and the related EXPORTS
  168. // and SEGMENTS directives in the .DEF file.
  169. //
  170. // Read the comments section documenting the WEP function in the Windows
  171. // 3.1 SDK "Programmers Reference, Volume 2: Functions" before placing
  172. // any additional code in the WEP routine for a Windows 3.0 DLL.
  173. //---------------------------------------------------------------------------
  174. #pragma alloc_text(WEP_TEXT,WEP)
  175. //---------------------------------------------------------------------------
  176. // Performs cleanup tasks when the DLL is unloaded.  WEP() is
  177. // called automatically by Windows when the DLL is unloaded (no
  178. // remaining tasks still have the DLL loaded).    It is strongly
  179. // recommended that a DLL have a WEP() function, even if it does
  180. // nothing but returns success (1), as in this example.
  181. //---------------------------------------------------------------------------
  182. int FAR PASCAL WEP
  183. (
  184.     int fSystemExit
  185. )
  186. {
  187.     // Avoid warnings on unused (but required) formal parameters
  188.     fSystemExit = fSystemExit;
  189.     return 1;
  190. }
  191. #endif // C6
  192. //---------------------------------------------------------------------------
  193.