Chinaunix首页 | 论坛 | 博客
  • 博客访问: 845896
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:10:29

//-----------------------------------------------------------------------
// 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)   

 re: some codes 2008-06-20 19:13


。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。超级路过。。。

 re: some codes 2008-06-23 12:11

NONCLIENTMETRICS ncm;
LOGFONT lf;
char ss[50] = {'\0'};

memset( &ncm,0,sizeof(NONCLIENTMETRICS) );
ncm.cbSize = sizeof( NONCLIENTMETRICS );
SystemParametersInfo( SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),&ncm,0 );

lf= ncm.lfCaptionFont;
AfxMessageBox( lf.lfFaceName );
sprintf( ss,"%d",ncm.iCaptionHeight );
AfxMessageBox( ss );
sprintf( ss,"%d",lf.lfHeight );
AfxMessageBox( ss );


CFont *f = this->GetFont();
//LOGFONT lf;
f->GetLogFont( &lf );
AfxMessageBox( lf.lfFaceName );
sprintf( ss,"%d",lf.lfHeight );
AfxMessageBox( ss );

char ss[50] = {'\0'};
HDC dc;
LOGFONT lg;
dc = ::GetWindowDC( this->GetSafeHwnd() );
HFONT hFont = (HFONT)GetCurrentObject( dc,OBJ_FONT );
GetObject( hFont,sizeof(LOGFONT),&lg );
AfxMessageBox( lg.lfFaceName );
sprintf( ss,"%d",lg.lfHeight );
AfxMessageBox( ss );

/*
CRect rc(0,0,0,0);
ClipCursor(&rc);

//HWND hWnd = GetDlgItem(IDC_EDIT1)->GetSafeHwnd();
//::SetFocus(hWnd);
/*
Sleep(3000);

keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY|0, 0);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0);

 re: some codes 2008-06-24 16:59

void CDlgDlg::OnButton1() 
{
char szFile[] = "d:\\test.txt";  
HWND hWnd = ::FindWindow( "Notepad",NULL );  
if(hWnd == NULL) return;  

DWORD dwBufSize = sizeof(DROPFILES) + sizeof(szFile) + 1;  
BYTE *pBuf = NULL;  
LPSTR pszRemote = NULL;  
HANDLE hProcess = NULL;  

__try 
{  
pBuf = new BYTE[dwBufSize];  
if(pBuf == NULL) __leave;  

memset( pBuf, 0, dwBufSize );  
DROPFILES *pDrop = (DROPFILES *)pBuf;  
pDrop->pFiles = sizeof(DROPFILES);  
strcpy( (char *)(pBuf + sizeof(DROPFILES)), szFile );  

DWORD dwProcessId;  
GetWindowThreadProcessId(hWnd, &dwProcessId);  
hProcess = OpenProcess( PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, dwProcessId );  
if(hProcess == NULL) __leave;  

pszRemote = (LPSTR)VirtualAllocEx( hProcess, NULL, dwBufSize, MEM_COMMIT, PAGE_READWRITE );  
if(pszRemote == NULL) __leave;  

if(WriteProcessMemory(hProcess, pszRemote, pBuf, dwBufSize, 0))  
::SendMessage( hWnd, WM_DROPFILES, (WPARAM)pszRemote, NULL );  
}  
__finally 
{  
if(pBuf != NULL) delete []pBuf;  
if(pszRemote != NULL) VirtualFreeEx( hProcess, pszRemote, dwBufSize, MEM_FREE );  
if(hProcess != NULL) CloseHandle( hProcess );  

}

 re: some codes 2008-07-16 20:08

偶也超级路过


--------------------next---------------------

阅读(403) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~