_____________ DDSURFACEDESC______ ddsd;
_____________ LPWORD_____________ lpSurface;
_____________ HRESULT____________ ddrval;
__
_____________ ddsd.dwSize = sizeof(ddsd);
_____________
_____________ while((ddrval=surf->Lock(NULL, &ddsd, 0, NULL))==DDERR_WASSTILLDRAWING);
_____________ if(ddrval == DD_OK)
_____________ _____________ lpSurface = (LPWORD)ddsd.lpSurface;
_____________ for(i = 0; i<HzNum; i++)
_____________ {_____________
_____________ _____________ QuHao = Str[i*2]-160;
_____________ _____________ WeiHao = Str[i*2+1]-160;
_____________ _____________ offset = ((QuHao - 1) * 94 + (WeiHao-1))*32;
_____________ _____________ fseek(HzkFp, offset, SEEK_SET);
_____________ _____________ fread(dotBuffer, 32, 1, HzkFp);
_____________ _____________ for(j=0;j<16;j++)
_____________ _____________ _____________ for(k=0;k<2;k++)
_____________ _____________ _____________ _____________ for(m=0;m<8;m++)
_____________ _____________ _____________ _____________ _____________ if(dotBuffer[j*2+k] & Mask[m])
_____________ _____________ _____________ _____________ _____________ {
_____________ _____________ _____________ _____________ _____________ _____________ lpSurface[ddsd.lPitch*(y+j+1) + x+k*8+m] = 0x000000;
_____________ _____________ _____________ _____________ _____________ }
_____________ _____________ x+=16;
_____________ }
_____________ surf->Unlock(NULL);
_____________ fclose(HzkFp);
}
其实原理很简单:
1. 打开字库
2. 计算字符串长度(这个函数只支持中文),并且Lock Surface
3. 依次计算出每个汉字所对应的区码和位码(汉字的第1个字节是区码,第2个字节就是位码),然后通过公式计算出这个汉字在字库中的偏移量:offset = ((QuHao - 1) * 94 + (WeiHao-1))*32;
4. 读出一个32个字节的点阵
5. 绘制到Surface上