home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- // Copyright (C) 1991 Microsoft Corporation
- //
- // You have a royalty-free right to use, modify, reproduce and distribute
- // the Sample Custom Control Files (and/or any modified version) in any way
- // you find useful, provided that you agree that Microsoft has no warranty,
- // obligation or liability for any Custom Control File.
- //---------------------------------------------------------------------------
- // Pix.c
- //---------------------------------------------------------------------------
- // Contains control procedure for PIX control
- //---------------------------------------------------------------------------
-
- #define NOCOMM
- #include <windows.h>
-
- #include <vbapi.h>
- #include "pix.h"
-
-
- //---------------------------------------------------------------------------
- // Standard Error Values
- //---------------------------------------------------------------------------
- #define ERR_None 0
- #define ERR_BadIndex 381 // Error$(381) = "Invalid property array index"
- #define ERR_BadPixFmt 32000 // User-defined error
-
-
- //---------------------------------------------------------------------------
- // Local Prototypes
- //---------------------------------------------------------------------------
- VOID NEAR PaintPix(PPIX ppix, HWND hwnd, HDC hdc);
-
-
- //---------------------------------------------------------------------------
- // Pix Control Procedure
- //---------------------------------------------------------------------------
- LONG FAR PASCAL _export PixCtlProc
- (
- HCTL hctl,
- HWND hwnd,
- USHORT msg,
- USHORT wp,
- LONG lp
- )
- {
- PPIX ppix = NULL;
-
- switch (msg)
- {
- case WM_PAINT:
- ppix = (PPIX)VBDerefControl(hctl);
- if (wp)
- PaintPix(ppix, hwnd, (HDC)wp);
- else
- {
- PAINTSTRUCT ps;
-
- BeginPaint(hwnd, &ps);
- PaintPix(ppix, hwnd, ps.hdc);
- EndPaint(hwnd, &ps);
- }
- break;
-
- case VBM_GETPROPERTY:
- switch (wp)
- {
- case IPROP_PIX_LIST: // Get element of List prop array
- {
- LONG i;
- LPDATASTRUCT lpDs = (LPDATASTRUCT)lp;
- LPSTR lpstr;
-
- i = lpDs->index[0].data;
- if (i < 0 || i >= ARRMAX)
- return ERR_BadIndex;
-
- ppix = (PPIX)VBDerefControl(hctl);
- if (ppix->List[i] == NULL)
- {
- lpDs->data = (LONG)VBCreateHsz((_segment)hctl,"");
- // *** ppix may now be invalid due to call to VB API ***
- return ERR_None;
- }
- lpstr = VBDerefHsz(ppix->List[i]);
- lpDs->data = (LONG)VBCreateHsz((_segment)hctl, lpstr);
- // *** ppix may now be invalid due to call to VB API ***
- return ERR_None;
- }
- }
- break;
-
- case VBM_SETPROPERTY:
- switch (wp)
- {
- case IPROP_PIX_LIST: // Set element of List prop array
- {
- LONG i;
- LPDATASTRUCT lpDs =(LPDATASTRUCT)lp;
- HSZ hsz;
-
- i = lpDs->index[0].data;
- if (i < 0 || i >= ARRMAX)
- return ERR_BadIndex;
-
- ppix = (PPIX)VBDerefControl(hctl);
- if (ppix->List[i])
- VBDestroyHsz(ppix->List[i]);
- hsz = VBCreateHsz((_segment)hctl, (LPSTR)(lpDs->data));
- // *** ppix may now be invalid due to call to VB API ***
- ppix = (PPIX)VBDerefControl(hctl);
- ppix->List[i] = hsz;
- return ERR_None;
- }
- }
- break;
-
- case VBM_CHECKPROPERTY:
- switch (wp)
- {
- case IPROP_PIX_PICT:
- {
- PIC pic;
-
- VBGetPic((HPIC)lp, &pic);
- switch (pic.picType)
- {
- case PICTYPE_BITMAP:
- case PICTYPE_NONE:
- InvalidateRect(hwnd, NULL, TRUE);
- return ERR_None;
- }
- return VBSetErrorMessage(ERR_BadPixFmt,
- "Picture format not supported.");
- }
- }
- break;
-
- case WM_DESTROY:
- ppix = (PPIX)VBDerefControl(hctl);
- VBFreePic(ppix->hpicPict);
- break;
- }
-
- return VBDefControlProc(hctl, hwnd, msg, wp, lp);
- }
-
-
-
- //---------------------------------------------------------------------------
- // Paint the bitmap into the Pix control.
- //---------------------------------------------------------------------------
- VOID NEAR PaintPix
- (
- PPIX ppix,
- HWND hwnd,
- HDC hdc
- )
- {
- PIC pic;
- HPIC hpic = ppix->hpicPict;
- BITMAP bmp;
- HDC hdcMem;
- RECT rect;
-
- VBGetPic(hpic, &pic);
- switch (pic.picType)
- {
- case PICTYPE_BITMAP:
- GetObject(pic.picData.bmp.hbitmap, sizeof(BITMAP), (LPSTR)&bmp);
- hdcMem = CreateCompatibleDC(hdc);
- SelectObject(hdcMem, pic.picData.bmp.hbitmap);
- GetClientRect(hwnd, &rect);
- StretchBlt(hdc, 0, 0,
- rect.right, rect.bottom, hdcMem, 0, 0,
- bmp.bmWidth, bmp.bmHeight, SRCCOPY);
- DeleteDC(hdcMem);
- break;
-
- case PICTYPE_NONE:
- {
- HBRUSH hbr;
-
- hbr = (HBRUSH)SendMessage(GetParent(hwnd), WM_CTLCOLOR,
- hdc, MAKELONG(hwnd, 0));
- GetClipBox(hdc, &rect);
- FillRect(hdc, &rect, hbr);
- break;
- }
- }
- }
-