⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guicontrol.c

📁 M3355的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    HBITMAP hbmp;
    HBRUSH hbr, oldHbr;
    BOOL bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder;
    HPEN leftPen,rightPen,oldPen, bkPen;
    HDC hMemDC;
    HBITMAP hOldBmp;
    RECT rect, rectDoggies;

#ifdef USING_MEMDC
    if(clBk==CL_BKNOCARE || clBk==CL_TRANSPARENT)
#else        
    if(1)
#endif        
    {
        GUI_CreateBitmapControl2(hdc, lpRect, clBk, clTopEdge, clBotEdge, iBitmapID, iLSpace, iTSpace);
        return;
    }
    else
    {
        if(!hdc)
            return;
        
        // I modified rect meaning as 0x0000: the highest 4 bits stand for no border or else. the lowest 12 bits stand for real position.
        // Temporarily, It should be no problem, for dc at most (608, 416), but 2^12=4096, that is enough.
        bDrawLeftBorder=((lpRect->left & RECTBORDER_NOLEFT) == RECTBORDER_NOLEFT)? FALSE:TRUE;
        bDrawTopBorder=((lpRect->top & RECTBORDER_NOTOP) == RECTBORDER_NOTOP)?FALSE:TRUE;
        bDrawRightBorder=((lpRect->right & RECTBORDER_NORIGHT) == RECTBORDER_NORIGHT)?FALSE:TRUE;
        bDrawBotBorder=((lpRect->bottom & RECTBORDER_NOBOT)== RECTBORDER_NOBOT)?FALSE:TRUE;
        
        lpRect->left=lpRect->left & 0x0fff;
        lpRect->top = lpRect->top & 0x0fff;
        lpRect->right=lpRect->right & 0x0fff;
        lpRect->bottom=lpRect->bottom & 0x0fff;
        
        // 1
        hMemDC=InitMemoryDC(hdc, lpRect->right-lpRect->left+1, lpRect->bottom-lpRect->top+1, &hOldBmp);
        
        rect.left=0;
        rect.right=lpRect->right-lpRect->left;
        rect.top=0;
        rect.bottom=lpRect->bottom-lpRect->top;
        
		DrawEdgedRectangle(hMemDC, &rect, clBk, clTopEdge, clBotEdge,bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder);

#if 0
        // I modified iLSpace meaning as 1. space from 'rect.left' to 'image.right' 2. need doggie or not: <0 need doggie, >=0 no doggies
         if(iLSpace<0)
        {
            rectDoggies.left=0;
            rectDoggies.right=DOGGIE_RADIUS;
            rectDoggies.top=0;
            rectDoggies.bottom=DOGGIE_RADIUS;
            
            hbr=(HBRUSH)CreateSolidBrush(CL_TRANSPARENT);
            FillRect(hMemDC, &rectDoggies, hbr);
            DeleteObject((HGDIOBJ)hbr);
            
            hbr=(HBRUSH)CreateSolidBrush(clBk);
            oldHbr=(HBRUSH)SelectObject(hMemDC, (HGDIOBJ)hbr);
            Circle(hMemDC, rectDoggies.left+DOGGIE_RADIUS, rectDoggies.top+DOGGIE_RADIUS, (USHORT)DOGGIE_RADIUS);
            SelectObject(hMemDC, (HGDIOBJ)oldHbr);
            DeleteObject((HGDIOBJ)hbr);
        }
#endif

        // I modified iLSpace meaning as 1. space from 'rect.left' to 'text.right' 2. need doggie or not: <0 need doggie, >=0 no doggies
        iLSpace=iLSpace>0?iLSpace:-iLSpace;
        
        hbmp=LoadBitmap(NULL,GET_IMNAME(iBitmapID));
        TransparentImage(hMemDC,rect.left+iLSpace, rect.top+iTSpace,0,0,hbmp,0,0,GetBMPWidth(hbmp),GetBMPHeight(hbmp), CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmp);
        
        // 2
        BitBlt(hdc, lpRect->left, lpRect->top, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top, hMemDC, 1,0,SRCCOPY);
        // 3
        DelMemoryDC(hMemDC, hOldBmp);
    }
}


/********************************************************************/
// Bitmap control

void GUI_CreateBitmapControl2(HDC hdc, RECT *lpRect, COLORREF clBk, COLORREF clTopEdge, COLORREF clBotEdge, UINT iBitmapID, int iLSpace, int iTSpace)
{
    HBITMAP hbmp;
    BOOL bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder;
    HBRUSH hbr;
    HPEN leftPen,rightPen,oldPen;

    if(!hdc)
        return;

    if(clBk==CL_BKNOCARE)
        ;
    else
    {
        // I modified rect meaning as 0x0000: the highest 4 bits stand for no border or else. the lowest 12 bits stand for real position.
        // Temporarily, It should be no problem, for dc at most (608, 416), but 2^12=4096, that is enough.
        bDrawLeftBorder=((lpRect->left & RECTBORDER_NOLEFT) == RECTBORDER_NOLEFT)? FALSE:TRUE;
        bDrawTopBorder=((lpRect->top & RECTBORDER_NOTOP) == RECTBORDER_NOTOP)?FALSE:TRUE;
        bDrawRightBorder=((lpRect->right & RECTBORDER_NORIGHT) == RECTBORDER_NORIGHT)?FALSE:TRUE;
        bDrawBotBorder=((lpRect->bottom & RECTBORDER_NOBOT)== RECTBORDER_NOBOT)?FALSE:TRUE;
        
        lpRect->left=lpRect->left & 0x0fff;
        lpRect->top = lpRect->top & 0x0fff;
        lpRect->right=lpRect->right & 0x0fff;
        lpRect->bottom=lpRect->bottom & 0x0fff;
        
		DrawEdgedRectangle(hdc, lpRect, clBk, clTopEdge, clBotEdge,bDrawLeftBorder, bDrawTopBorder, bDrawRightBorder, bDrawBotBorder);

    }

    hbmp=LoadBitmap(NULL,GET_IMNAME(iBitmapID));
    TransparentImage(hdc,lpRect->left+iLSpace, lpRect->top+iTSpace,0,0,hbmp,0,0,GetBMPWidth(hbmp),GetBMPHeight(hbmp), CL_TRANSPARENT);
    DeleteObject((HGDIOBJ)hbmp);
}


/********************************************************************/
// composed Bitmap


void GUI_CreateLeftMidRightBitmap(HDC hdc, RECT *lpRect, UINT iLeftTopBmpID, UINT iMiddleBmpID, UINT iRightBotBmpID, BOOL isLeftMidRight)
{
    HDC hMemDC;
    HBITMAP hCompBmp, hOldBmp, hbmpLT, hbmpMd, hbmpRB;
    int i;
    int iHeightLT, iWidthLT, iHeightMd, iWidthMd, iHeightRB, iWidthRB;

    
    if(!hdc)
        return;

#ifdef USING_MEMDC
    if(0)
#else        
    if(1)
#endif        
    {
        GUI_CreateLeftMidRightBitmap2(hdc, lpRect, iLeftTopBmpID, iMiddleBmpID, iRightBotBmpID, isLeftMidRight);
        return;
    }
    
    hMemDC=InitMemoryDC(hdc, lpRect->right-lpRect->left+1, lpRect->bottom-lpRect->top+1, &hOldBmp);
    BitBlt(hMemDC, 1, 0, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top, hdc, lpRect->left,lpRect->top,SRCCOPY);

#if 0
    if(isLeftMidRight==TRUE)
    {
#endif    
        hbmpLT=LoadBitmap(NULL,GET_IMNAME(iLeftTopBmpID));
        iWidthLT=GetBMPWidth(hbmpLT);
        iHeightLT=GetBMPHeight(hbmpLT);
        TransparentImage(hMemDC,0,0,0,0,hbmpLT,0,0,iWidthLT,iHeightLT, CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpLT);
        
        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        iWidthRB=GetBMPWidth(hbmpRB);
        iHeightRB=GetBMPHeight(hbmpRB);
        DeleteObject((HGDIOBJ)hbmpRB);
        
        hbmpMd=LoadBitmap(NULL,GET_IMNAME(iMiddleBmpID));
        iWidthMd=GetBMPWidth(hbmpMd);
        iHeightMd=GetBMPHeight(hbmpMd);
        for(i=0+iWidthLT; i<lpRect->right-lpRect->left+1-iWidthRB; i+=iWidthMd)
        {
            TransparentImage(hMemDC,i,0,0,0,hbmpMd,0,0,iWidthRB,iHeightRB, CL_TRANSPARENT);
        }
        DeleteObject((HGDIOBJ)hbmpMd);

        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        TransparentImage(hMemDC,lpRect->right-lpRect->left+1-iWidthRB,0,0,0,hbmpRB,0,0,iWidthRB,iHeightRB, CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpRB);
#if 0
	}
    else
    {
        hbmpLT=LoadBitmap(NULL,GET_IMNAME(iLeftTopBmpID));
        iWidthLT=GetBMPWidth(hbmpLT);
        iHeightLT=GetBMPHeight(hbmpLT);
        TransparentImage(hMemDC,0,0,0,0,hbmpLT,0,0,iWidthLT,iHeightLT,CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpLT);
        
        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        iWidthRB=GetBMPWidth(hbmpRB);
        iHeightRB=GetBMPHeight(hbmpRB);
        DeleteObject((HGDIOBJ)hbmpRB);
        
        hbmpMd=LoadBitmap(NULL,GET_IMNAME(iMiddleBmpID));
        iWidthMd=GetBMPWidth(hbmpMd);
        iHeightMd=GetBMPHeight(hbmpMd);
        for(i=0+iHeightLT; i<lpRect->bottom-lpRect->top+1-iHeightRB; i+=iHeightMd)
        {
            TransparentImage(hMemDC,0, i,0,0,hbmpMd,0,0,iWidthMd,iHeightMd,CL_TRANSPARENT);
        }
        DeleteObject((HGDIOBJ)hbmpMd);
        
        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        TransparentImage(hMemDC,0, lpRect->bottom-lpRect->top+1-iHeightRB,0,0,hbmpRB,0,0,iWidthRB,iHeightRB,CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpRB);
    }
#endif

    // 2
    BitBlt(hdc, lpRect->left, lpRect->top, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top, hMemDC, 1,0,SRCCOPY);
    // 3
    DelMemoryDC(hMemDC, hOldBmp);
}

void GUI_CreateLeftMidRightBitmap2(HDC hdc, RECT *lpRect, UINT iLeftTopBmpID, UINT iMiddleBmpID, UINT iRightBotBmpID, BOOL isLeftMidRight)
{
#define hMemDC hdc

    HBITMAP hCompBmp, hOldBmp, hbmpLT, hbmpMd, hbmpRB;
    int i;
    int iHeightLT, iWidthLT, iHeightMd, iWidthMd, iHeightRB, iWidthRB;

    
    if(!hdc)
        return;

#if 0
    if(isLeftMidRight==TRUE)
    {
#endif
        hbmpLT=LoadBitmap(NULL,GET_IMNAME(iLeftTopBmpID));
        iWidthLT=GetBMPWidth(hbmpLT);
        iHeightLT=GetBMPHeight(hbmpLT);
        TransparentImage(hMemDC,lpRect->left, lpRect->top,0,0,hbmpLT,0,0,iWidthLT,iHeightLT,CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpLT);
        
        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        iWidthRB=GetBMPWidth(hbmpRB);
        iHeightRB=GetBMPHeight(hbmpRB);
        DeleteObject((HGDIOBJ)hbmpRB);
        
        hbmpMd=LoadBitmap(NULL,GET_IMNAME(iMiddleBmpID));
        iWidthMd=GetBMPWidth(hbmpMd);
        iHeightMd=GetBMPHeight(hbmpMd);
        for(i=lpRect->left+iWidthLT; i<lpRect->right-iWidthRB; i+=iWidthMd)
        {
            TransparentImage(hMemDC,i, lpRect->top,0,0,hbmpMd,0,0,iWidthRB,iHeightRB,CL_TRANSPARENT);
        }
        DeleteObject((HGDIOBJ)hbmpMd);

        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        TransparentImage(hMemDC,lpRect->right-iWidthRB, lpRect->top,0,0,hbmpRB,0,0,iWidthRB,iHeightRB,CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpRB);
#if 0
    }
    else
    {
        hbmpLT=LoadBitmap(NULL,GET_IMNAME(iLeftTopBmpID));
        iWidthLT=GetBMPWidth(hbmpLT);
        iHeightLT=GetBMPHeight(hbmpLT);
        TransparentImage(hMemDC,lpRect->left, lpRect->top,0,0,hbmpLT,0,0,iWidthLT,iHeightLT,CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpLT);
        
        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        iWidthRB=GetBMPWidth(hbmpRB);
        iHeightRB=GetBMPHeight(hbmpRB);
        DeleteObject((HGDIOBJ)hbmpRB);
        
        hbmpMd=LoadBitmap(NULL,GET_IMNAME(iMiddleBmpID));
        iWidthMd=GetBMPWidth(hbmpMd);
        iHeightMd=GetBMPHeight(hbmpMd);
        for(i=lpRect->top+iHeightLT; i<lpRect->bottom-iHeightRB; i+=iHeightMd)
        {
            TransparentImage(hMemDC,lpRect->left, i,0,0,hbmpMd,0,0,iWidthMd,iHeightMd,CL_TRANSPARENT);
        }
        DeleteObject((HGDIOBJ)hbmpMd);
        
        hbmpRB=LoadBitmap(NULL,GET_IMNAME(iRightBotBmpID));
        TransparentImage(hMemDC,lpRect->left, lpRect->bottom-iHeightRB,0,0,hbmpRB,0,0,iWidthRB,iHeightRB,CL_TRANSPARENT);
        DeleteObject((HGDIOBJ)hbmpRB);
    }
#endif

#undef hMemDC
}

#if 0
void GUI_CreateLine(HDC hdc, COLORREF clLine, int iFromX, INT iFromY, int iToX, int iToY)
{
    HPEN oldPen, linePen;
    
    if(!hdc)
        return;

    linePen = CreatePen(PS_SOLID, 2, clLine);
    oldPen=(HPEN)SelectObject(hdc,(HGDIOBJ)linePen);
    
    MoveToEx(hdc, iFromX, iFromY, NULL);
    LineTo(hdc, iToX, iToY);

    SelectObject(hdc, (HGDIOBJ)oldPen);
    DeleteObject((HGDIOBJ)linePen);
}

void GUI_CreateCycle(HDC hdc, COLORREF clBk, COLORREF clEdge, int iCenterX, INT iCenterY, INT iRadius)
{
    HBRUSH hbr, oldHbr;

    if(!hdc)
        return;

    hbr=(HBRUSH)CreateSolidBrush(clBk);
    oldHbr=(HBRUSH)SelectObject(hdc, (HGDIOBJ)hbr);
    Circle(hdc, iCenterX, iCenterY, iRadius);
    SelectObject(hdc, (HGDIOBJ)oldHbr);
    DeleteObject((HGDIOBJ)hbr);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -