//-----------------------------------------------------------------------
// to bl, define and rewrite printf
#include
#include
#include
#define printf printf_bl
int __cdecl printf_bl( const char *format, ... )
{
char s[65536]={'\0'};
char *sFile = "c:\\test.txt";
//
va_list ap;
va_start( ap, format );
int n = vprintf( format, ap );
vsprintf( s,format,ap );
va_end( ap );
//
FILE *f = fopen( sFile,"a+" );
if( f==NULL ) return 0;
fwrite( s,sizeof(char),strlen(s),f );
fclose( f );
//
return n;
}
void main()
{
printf( "test%d,this is bl %s\r\n",1,"woza woza wozazaza" );
printf( "test2\r\n" );
printf( "test3:%f\r\n", (float)1.234 );
}
//-----------------------------------------------------------------------
//OpenDialog,select and filter any file,Attention to the \0 of two different UNICODE / ANSI
void Load()
{
TCHAR szFilter[100] = {0};
TCHAR szstrFile[100] = {0};
OPENFILENAME ofn;
TCHAR szFile[MAX_PATH] = TEXT("InJect.dll");
TCHAR szFileTitle[MAX_PATH];
memset( &ofn,0,sizeof(ofn) );
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = g_hWnd;
//ofn.lpstrFilter = "Dll Files(*.dll)\0*.dll\0All Files(*.*)\0*.*\0\0"; //ansi
//ofn.lpstrFilter = TEXT("PDF file(*.pdf)\0*.pdf\0\0"); //unicode
//wcscpy( szFilter, TEXT("PDF file(*.pdf)\0") );
//wcscpy( szstrFile, szFilter );
//wcscat( szstrFile, TEXT("*.pdf\0\0") ); //no
lstrcpy( szFilter, TEXT("PDF file(*.pdf)") );
lstrcpy( szstrFile, szFilter );
lstrcpy( szstrFile+lstrlen(szstrFile)+1, TEXT("*.pdf\0\0") ); //yes
ofn.lpstrFilter = szstrFile;
ofn.nFilterIndex = 0;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle);
ofn.lpstrInitialDir = TEXT("c:\\windows\\system32\\");
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
if(GetOpenFileName(&ofn))
{
//HWND hWndA;
//hWndA = GetDlgItem(g_hWnd,IDC_EDIT_DLL);
//SetWindowText( hWndA,ofn.lpstrFile );
}
}
//-----------------------------------------------------------------------
//转换双精度类型,指定小数点位数,并四舍五入
//d: 传入的双精度类型
//pre: 小数点位数
//b: 是否四舍五入
double d_to_dn(double d,int pre,bool b)
{
double dn = 0.00;
__int64 i,k;
if( pre<=1 ) pre=1;
k = (__int64)pow( 10,pre );
if( b )
i = (__int64)((d*k)+0.5);
else
i = (__int64)(d*k);
dn = (double)i/k;
return dn;
}
////////
a1 = d_to_dn( a1,8,false ); //保留8位小数点,不四舍五入
a1 = d_to_dn( a1,2,true ); //保留2位小数点,四舍五入
//-----------------------------------------------------------------------
HIMC hIMC; //全局或成员变量
void IMMCheck(HWND hWnd,bool bEnable)
{
if( hWnd && IsWindow(hWnd) )
{
hIMC = ImmGetContext( hWnd );
if( bEnable )
{
ImmAssociateContext( hWnd,NULL );
ImmReleaseContext( hWnd,hIMC );
}
else
{
ImmAssociateContext( hWnd,hIMC );
hIMC = NULL;
}
::SetFocus(hWnd);
}
}
////////
HWND hWnd = GetDlgItem(IDC_EDIT1)->GetSafeHwnd();
IMMCheck( hWnd,false ); //禁用输入法
IMMCheck( hWnd,true); //启用输入法
//-----------------------------------------------------------------------
CRect rect;
GetClientRect( &rect );
pDC->SetBkMode( TRANSPARENT );
pDC->SelectObject( m_hFont );
char *str = "字体、影音 测试输出";
CRect rc = rect;
rc.top += 5;
rc.left += 5;
rc.bottom += 5;
rc.right += 5;
COLORREF oldCr = pDC->SetTextColor(::GetSysColor(COLOR_3DLIGHT));
::DrawText(pDC->m_hDC,str,-1,rc,DT_CENTER);
SetTextColor( pDC->m_hDC,oldCr );
::DrawText(pDC->m_hDC,str, -1, rect, DT_CENTER);
//select font
HWND hWnd = this->GetSafeHwnd();
CHOOSEFONT cf;
LOGFONT lf;
memset( &cf,0,sizeof(CHOOSEFONT) );
memset( &lf, 0, sizeof(LOGFONT) );
cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = hWnd;
lf.lfHeight = 14;
lf.lfWeight = 800;
strcpy( lf.lfFaceName,"Arial" );
cf.lpLogFont = &lf;
cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
cf.nFontType = SCREEN_FONTTYPE;
if( ChooseFont(&cf) )
{
if( m_hFont ) DeleteObject(m_hFont);
m_hFont = CreateFontIndirect( &lf );
::InvalidateRect( hWnd,NULL,true );
::UpdateWindow( hWnd );
}
//-----------------------------------------------------------------------
posted on 2008-06-20 09:01 风中的流沙 阅读(815)