📄 ctrlmisc.c
字号:
}
else
break;
left_bytes -= len_cur_char;
mchar += len_cur_char;
}
}
else
{
if(pfont)
fontsize = GetFontCCharWidth(pfont);
for (i = 0; i < len; i++)
{
if ((BYTE)mchar[i] > 0xA0)
{
i++;
if (i < len)
{
if ((BYTE)mchar[i] > 0xA0)
{
nTextWidth += fontsize;
}
else
i--;
}
else
{
nTextWidth += GetFontSingleCharWidth(pfont,(char*)&mchar[i],1);
}
}
else
{
nTextWidth += GetFontSingleCharWidth(pfont,(char*)&mchar[i],1);
}
}
}
HJ_DEBUG("\nbefore return nTextWidth=%d\n",nTextWidth);
return nTextWidth;
}
//edit by tjb 2004-4-20
//because ppfile参数在函数结束时还是为空
//char * PrefixFileName(const char * path,char * prefix,char ** ppfile,int maxlen)
char * PrefixFileName(const char * path,char * prefix,char *ppfile,int maxlen)
{
char *str1;
if (!ppfile)
return NULL;
str1 = rindex(path,'/');
if(str1)
{
int rpath;
rpath = (int)(str1-path)+1;
if(rpath <= 0 || rpath > maxlen)
return NULL;
strncpy(ppfile,path,rpath);
ppfile[rpath] = 0;
strncat(ppfile,prefix,maxlen);
strncat(ppfile,str1+1,maxlen);
}
else
{
strncpy(ppfile,prefix,maxlen);
strncat(ppfile,path,maxlen);
}
return ppfile;
}
BOOL RefreshChildInParent(HWND hwnd)
{
BOOL ret = FALSE;
RECT rcClient;
DWORD dwStyle1,dwStyle2;
HWND pParent = GetParent(hwnd);
GetWindowRect(hwnd,&rcClient);
dwStyle1 = GetWindowStyle(hwnd);
if(pParent)
{
dwStyle2 = GetWindowStyle(pParent);
if( (dwStyle1 & WS_VISIBLE) &&
(dwStyle2 & WS_VISIBLE))
{
ret = InvalidateRect (pParent, (PRECT)&rcClient, TRUE);
}
}
return ret;
/*GetClientRect(hwnd,&rcClient);
return RefreshSequenceParent(hwnd,&rcClient);
*/
}
BOOL RefreshSequenceParent(HWND hwnd,RECT * rect)
{
BOOL ret = FALSE;
RECT rcClient;
DWORD dwStyle1,dwStyle2;
HWND pParent = GetParent(hwnd);
GetWindowRect(hwnd,&rcClient);
dwStyle1 = GetWindowStyle(hwnd);
if(pParent)
{
dwStyle2 = GetWindowStyle(pParent);
if( (dwStyle1 & WS_VISIBLE) &&
(dwStyle2 & WS_VISIBLE))
{
RECT parentClient;
parentClient.left = rcClient.left + rect->left;
parentClient.top = rcClient.top + rect->top;
parentClient.right = rcClient.left + rect->right;
parentClient.bottom = rcClient.top + rect->bottom;
RefreshSequenceParent(pParent,&parentClient);
ret = InvalidateRect (pParent, (PRECT)&rcClient, TRUE);
}
}
return ret;
}
void FillRectWithAlpha(HDC hdc,RECT * rect,char * bmpfile)
{
BITMAP bmp;
memset(&bmp,0,sizeof(BITMAP));
if(!LoadBitmap( HDC_SCREEN, &bmp, bmpfile))
{
bmp.bmType = BMP_TYPE_NORMAL;
FillBoxWithBitmap(hdc, 0, 0, rect->right,rect->bottom,&bmp);
UnloadBitmap(&bmp);
}
}
//edit by tjb 2003-3-29
//修改原因:当位图的大小与控件的大小不一致时,图片不能全部显示或不能填充整个控件
//改为根据控件大小来拉伸或缩小图片,使图片填充整个控件
BOOL FillWithBmpfile(HWND hwnd,HDC hdc,char * bmpfile,BOOL alpha)
{
BITMAP bmp;
RECT rect;
memset(&bmp,0,sizeof(BITMAP));
if(bmpfile)
{
if(!LoadBitmap( HDC_SCREEN, &bmp, bmpfile))
{
if(alpha)
{
unsigned char r,g,b,a;
Pixel2RGBA(HDC_SCREEN,GetWindowBkColor (hwnd),&r,&g,&b,&a);
bmp.bmType |= BMP_TYPE_ALPHACHANNEL;
bmp.bmAlpha = a;
}
GetWindowRect(hwnd, &rect);
FillBoxWithBitmap(hdc, 0, 0, RECTW(rect), RECTH(rect), &bmp);
UnloadBitmap(&bmp);
return TRUE;
}
}
return FALSE;
}
BOOL FillWithBitmapAlpha(HWND hwnd,HDC hdc,BITMAP * pbmp,BOOL alpha)
{
if (pbmp)
{
RECT rect;
int bmType = pbmp->bmType;
if(alpha)
{
unsigned char r,g,b,a;
Pixel2RGBA(HDC_SCREEN,GetWindowBkColor (hwnd),&r,&g,&b,&a);
pbmp->bmType |= BMP_TYPE_ALPHACHANNEL;
pbmp->bmAlpha = a;
}
GetWindowRect(hwnd, &rect);
// FillBoxWithBitmap(hdc, 0, 0, RECTW(rect), RECTH(rect), pbmp);
FillBoxWithBitmap(hdc, 0, 0, 0, 0, pbmp);
pbmp->bmType = bmType;
return TRUE;
}
return FALSE;
}
int GUIAPI LoadBitmapWithAlphaFile (HDC hdc, PBITMAP bmp, const char* file_name,const char * alphafile)
{
MYBITMAP myBitmap;
RGB pal [256];
int ret;
myBitmap.frames = 1;
if ((ret = LoadMyBitmapFromFile (&myBitmap, pal, file_name)) < 0)
return ret;
ret = ExpandMyBitmap (hdc, bmp, &myBitmap, pal, 0);
free (myBitmap.bits);
memset(&myBitmap,0,sizeof(MYBITMAP));
myBitmap.frames = 1;
if ((ret = LoadMyBitmapFromFile (&myBitmap, pal, alphafile)) < 0)
{
free(bmp->bmBits);
bmp->bmBits = NULL;
return ret;
}
ret = AlphaBltMyBitmap(bmp,&myBitmap,pal,0);
if(myBitmap.bits)
free (myBitmap.bits);
return ret;
}
//add by hejia 2004-9-17
//add by hejia 2004-9-17
BOOL FillWithAlphaBmpfile(HWND hwnd,HDC hdc,char * bmpfile, BOOL alpha)
{
BITMAP bmp;
RECT rect;
HDC tmpdc;
char albmpfile[MAX_PATH+1];
memset(&bmp,0,sizeof(BITMAP));
tmpdc = CreateCompatibleDC(hdc);
SetMemDCAlpha(tmpdc, 0, 0);
//SetRasterOperation(hdc,ROP_SET);
SetBkMode(tmpdc, BM_TRANSPARENT);
GetWindowRect(hwnd, &rect);
FillWithBmpfile(hwnd, tmpdc, (char *)bmpfile, alpha);
PrefixFileName(bmpfile, "al", albmpfile, MAX_PATH);
if(albmpfile)
{
if ( access (albmpfile, F_OK) == 0)
{
if(!LoadBitmap( HDC_SCREEN, &bmp, albmpfile))
{
unsigned char r,g,b,a;
//fprintf(stderr,"\n/********enter FillWithAlphaBmpfile.\n");
Pixel2RGBA(HDC_SCREEN,GetWindowBkColor (hwnd),&r,&g,&b,&a);
bmp.bmType &= ~BMP_TYPE_ALPHACHANNEL;
bmp.bmType |= BMP_TYPE_ALPHARED;
bmp.bmAlpha = a;
FillBoxWithBitmap(tmpdc, 0, 0, RECTW(rect), RECTH(rect), &bmp);
UnloadBitmap(&bmp);
}
}
}
BitBlt(tmpdc,0,0,RECTW(rect),RECTH(rect),hdc,0,0,0);
DeleteCompatibleDC(tmpdc);
return TRUE;
err:
return FALSE;
}
BOOL FillWithBmpAlphaValue2(HWND hwnd,HDC hdc,BITMAP * pbmp,BOOL alpha)
{
if (pbmp)
{
RECT rect;
int bmType = pbmp->bmType;
if(alpha)
{
unsigned char r,g,b,a;
Pixel2RGBA(HDC_SCREEN,GetWindowBkColor (hwnd),&r,&g,&b,&a);
pbmp->bmType |= BMP_TYPE_ALPHAVALUE;
pbmp->bmAlpha = a;
}
HJ_DEBUG("\nFillWithBmpAlphaValue2 hello.\n");
GetWindowRect(hwnd, &rect);
FillBoxWithBitmap(hdc, 0, 0, RECTW(rect), RECTH(rect), pbmp);
//FillBoxWithBitmap(hdc, 0, 0, 0, 0, pbmp);
pbmp->bmType = bmType;
return TRUE;
}
return FALSE;
}
//add by hejia 2004-9-17
BOOL FillWithBmpAlphaValue(HWND hwnd,HDC hdc,char * bmpfile,BOOL alpha)
{
BITMAP bmp;
RECT rect;
memset(&bmp,0,sizeof(BITMAP));
if(bmpfile)
{
if(!LoadBitmap( HDC_SCREEN, &bmp, bmpfile))
{
if(alpha)
{
unsigned char r,g,b,a;
Pixel2RGBA(HDC_SCREEN,GetWindowBkColor (hwnd),&r,&g,&b,&a);
bmp.bmType |= BMP_TYPE_ALPHAVALUE;
bmp.bmAlpha = a;
}
GetWindowRect(hwnd, &rect);
FillBoxWithBitmap(hdc, 0, 0, RECTW(rect), RECTH(rect), &bmp);
UnloadBitmap(&bmp);
return TRUE;
}
}
return FALSE;
}
/****************************************************************************
*功能:使用图片填充控键
*参数: hwnd - 控键句柄
* hdc -
* bmpfile - 图片文件名(包括路径),若是使用该种方式,pbmp设为NULL
* pbmp - 使用bitmap指针来填充,bmpfile 设为NULL
* bmptype - 填充方式,包括BMP_TYPE_ALPHAVALUE、BMP_TYPE_ALPHARED、
* BMP_TYPE_ALPHACHANNEL、BMP_TYPE_NORMAL
* alpha - 是否使用alpha值
******************************************************************************/
BOOL FillWithPicture(HWND hwnd,HDC hdc, char * bmpfile, PBITMAP pbmp, int bmptype, BOOL alpha)
{
if (!bmpfile && !pbmp)
return FALSE;
switch(bmptype)
{
case BMP_TYPE_ALPHACHANNEL:
if (bmpfile)
return FillWithBmpfile(hwnd, hdc, bmpfile, alpha);
else
return FillWithBitmapAlpha(hwnd, hdc, pbmp, alpha);
case BMP_TYPE_ALPHARED:
if (bmpfile)
return FillWithAlphaBmpfile(hwnd, hdc, bmpfile, alpha);
case BMP_TYPE_ALPHAVALUE:
if (bmpfile)
return FillWithBmpAlphaValue(hwnd, hdc, bmpfile, alpha);
else
return FillWithBmpAlphaValue2(hwnd, hdc, pbmp, alpha);
case BMP_TYPE_NORMAL:
if (pbmp)
{
pbmp->bmType = BMP_TYPE_NORMAL;
return FillBoxWithBitmap(hdc, 0, 0, 0, 0, pbmp);
}
default:
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -