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

📄 sendmsg.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 2 页
字号:



#define INIT_BUFSIZE    ( MAX_PATH + 0x10 )


#if ! defined _MSC_VER || _MSC_VER < 1300
static int __cdecl vscprintf ( const char *format, va_list args ) ;
static int __cdecl vscwprintf ( const wchar_t *format, va_list args ) ;
#else
#define vscprintf _vscprintf
#define vscwprintf _vscwprintf
#endif



////////////////////////////////////////
//   儊僢僙乕僕儃僢僋僗乮彂幃晅偒乯   //
////////////////////////////////////////



// 彂幃晅偒 MessageBox乮ANSI斉乯
static int MessageBoxVaFormatA ( HWND hWnd, const char *szCaption, unsigned int uType, const char *format, va_list args ) {

   char buffer [ INIT_BUFSIZE ] ;      // for short strings
   char *string = buffer ;

   char *new_buffer = NULL ;

   va_list args1 ;
   va_list args2 ;
   va_copy ( args1, args ) ;
   va_copy ( args2, args ) ;

   int result ;

   if ( ( result = vsnprintf ( buffer, INIT_BUFSIZE, format, args ) ) < 0 || result > INIT_BUFSIZE - 1 ) {

      buffer [ INIT_BUFSIZE - 1 ] = 0 ;

      int length ;
      if ( ( length = vscprintf ( format, args1 ) ) < 0 ) goto CAUGHT_ERROR ;
      if ( ! ( new_buffer = (char*) malloc ( ( length + 1 ) * sizeof(char) ) ) ) goto CAUGHT_ERROR ;
      if ( ( result = vsnprintf ( new_buffer, length + 1, format, args2 ) ) < 0 || result > length ) goto CAUGHT_ERROR ;

      string = new_buffer ;
   }

   CAUGHT_ERROR :
   va_end ( args1 ) ;
   va_end ( args2 ) ;

   int retvalue = MessageBoxA ( hWnd, string, szCaption, uType ) ;

   free ( new_buffer ) ;

   return retvalue ;
}



// 彂幃晅偒 MessageBox乮ANSI斉乯
int __cdecl MessageBoxFormatA ( HWND hWnd, const char *szCaption, unsigned int uType, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = MessageBoxVaFormatA ( hWnd, szCaption, uType, format, args ) ;
   va_end ( args ) ;
   return retvalue ;
}



// 彂幃晅偒 MessageBox乮UNICODE斉乯
static int MessageBoxVaFormatW ( HWND hWnd, const wchar_t *szCaption, unsigned int uType, const wchar_t *format, va_list args ) {

   wchar_t buffer [ INIT_BUFSIZE ] ;      // for short strings
   wchar_t *string = buffer ;

   wchar_t *new_buffer = NULL ;

   va_list args1 ;
   va_list args2 ;
   va_copy ( args1, args ) ;
   va_copy ( args2, args ) ;

   int result ;

   if ( ( result = vsnwprintf ( buffer, INIT_BUFSIZE, format, args ) ) < 0 || result > INIT_BUFSIZE - 1 ) {

      buffer [ INIT_BUFSIZE - 1 ] = 0 ;

      int length ;
      if ( ( length = vscwprintf ( format, args1 ) ) < 0 ) goto CAUGHT_ERROR ;
      if ( ! ( new_buffer = (wchar_t*) malloc ( ( length + 1 ) * sizeof(wchar_t) ) ) ) goto CAUGHT_ERROR ;
      if ( ( result = vsnwprintf ( new_buffer, length + 1, format, args2 ) ) < 0 || result > length ) goto CAUGHT_ERROR ;

      string = new_buffer ;
   }

   CAUGHT_ERROR :
   va_end ( args1 ) ;
   va_end ( args2 ) ;

   int retvalue = MessageBoxW ( hWnd, string, szCaption, uType ) ;

   free ( new_buffer ) ;

   return retvalue ;
}



// 彂幃晅偒 MessageBox乮UNICODE斉乯
int __cdecl MessageBoxFormatW ( HWND hWnd, const wchar_t *szCaption, unsigned int uType, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = MessageBoxVaFormatW ( hWnd, szCaption, uType, format, args ) ;
   va_end ( args ) ;
   return retvalue ;
}



////////////////////////////////////////
//       SendMessage乮彂幃晅偒乯      //
////////////////////////////////////////



// 彂幃晅偒 SendMessage乮ANSI斉乯
static LRESULT SendMessageVaFormatA ( HWND hWnd, UINT Msg, WPARAM wParam, const char *format, va_list args ) {

   char buffer [ INIT_BUFSIZE ] ;      // for short strings
   char *string = buffer ;

   char *new_buffer = NULL ;

   va_list args1 ;
   va_list args2 ;
   va_copy ( args1, args ) ;
   va_copy ( args2, args ) ;

   int result ;

   if ( ( result = vsnprintf ( buffer, INIT_BUFSIZE, format, args ) ) < 0 || result > INIT_BUFSIZE - 1 ) {

      buffer [ INIT_BUFSIZE - 1 ] = 0 ;

      int length ;
      if ( ( length = vscprintf ( format, args1 ) ) < 0 ) goto CAUGHT_ERROR ;
      if ( ! ( new_buffer = (char*) malloc ( ( length + 1 ) * sizeof(char) ) ) ) goto CAUGHT_ERROR ;
      if ( ( result = vsnprintf ( new_buffer, length + 1, format, args2 ) ) < 0 || result > length ) goto CAUGHT_ERROR ;

      string = new_buffer ;
   }

   CAUGHT_ERROR :
   va_end ( args1 ) ;
   va_end ( args2 ) ;

   LRESULT retvalue = SendMessageA ( hWnd, Msg, wParam, (LPARAM) string ) ;

   free ( new_buffer ) ;

   return retvalue ;
}



// 彂幃晅偒 SendMessage乮UNICODE斉乯
static LRESULT SendMessageVaFormatW ( HWND hWnd, UINT Msg, WPARAM wParam, const wchar_t *format, va_list args ) {

   wchar_t buffer [ INIT_BUFSIZE ] ;      // for short strings
   wchar_t *string = buffer ;

   wchar_t *new_buffer = NULL ;

   va_list args1 ;
   va_list args2 ;
   va_copy ( args1, args ) ;
   va_copy ( args2, args ) ;

   int result ;

   if ( ( result = vsnwprintf ( buffer, INIT_BUFSIZE, format, args ) ) < 0 || result > INIT_BUFSIZE - 1 ) {

      buffer [ INIT_BUFSIZE - 1 ] = 0 ;

      int length ;
      if ( ( length = vscwprintf ( format, args1 ) ) < 0 ) goto CAUGHT_ERROR ;
      if ( ! ( new_buffer = (wchar_t*) malloc ( ( length + 1 ) * sizeof(wchar_t) ) ) ) goto CAUGHT_ERROR ;
      if ( ( result = vsnwprintf ( new_buffer, length + 1, format, args2 ) ) < 0 || result > length ) goto CAUGHT_ERROR ;

      string = new_buffer ;
   }

   CAUGHT_ERROR :
   va_end ( args1 ) ;
   va_end ( args2 ) ;

   LRESULT retvalue = SendMessageW ( hWnd, Msg, wParam, (LPARAM) string ) ;

   free ( new_buffer ) ;

   return retvalue ;
}



////////////////////////////////////////
//   僂傿儞僪僂憖嶌堦斒乮彂幃晅偒乯   //
////////////////////////////////////////



// 彂幃晅偒 Wm_SetText乮ANSI斉乯
int __cdecl Wm_SetTextFormatA ( HWND hWnd, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( hWnd, WM_SETTEXT, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Wm_SetText乮UNICODE斉乯
int __cdecl Wm_SetTextFormatW ( HWND hWnd, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( hWnd, WM_SETTEXT, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}



// 彂幃晅偒 Dlg_Wm_SetText乮ANSI斉乯
int __cdecl Dlg_Wm_SetTextFormatA ( HWND hDlg, int nId, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( GetDlgItem ( hDlg, nId ), WM_SETTEXT, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_Wm_SetText乮UNICODE斉乯
int __cdecl Dlg_Wm_SetTextFormatW ( HWND hDlg, int nId, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( GetDlgItem ( hDlg, nId ), WM_SETTEXT, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}



////////////////////////////////////////
//     僐儞儃儃僢僋僗乮彂幃晅偒乯     //
////////////////////////////////////////



// 彂幃晅偒 ComboBox_AddString乮ANSI斉乯
int __cdecl ComboBox_AddStringFormatA ( HWND hWnd, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( hWnd, CB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 ComboBox_AddString乮UNICODE斉乯
int __cdecl ComboBox_AddStringFormatW ( HWND hWnd, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( hWnd, CB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 ComboBox_InsertString乮ANSI斉乯
int __cdecl ComboBox_InsertStringFormatA ( HWND hWnd, int nIndex, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( hWnd, CB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 ComboBox_InsertString乮UNICODE斉乯
int __cdecl ComboBox_InsertStringFormatW ( HWND hWnd, int nIndex, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( hWnd, CB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}



// 彂幃晅偒 Dlg_ComboBox_AddString乮ANSI斉乯
int __cdecl Dlg_ComboBox_AddStringFormatA ( HWND hDlg, int nId, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( GetDlgItem ( hDlg, nId ), CB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_ComboBox_AddString乮UNICODE斉乯
int __cdecl Dlg_ComboBox_AddStringFormatW ( HWND hDlg, int nId, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( GetDlgItem ( hDlg, nId ), CB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_ComboBox_InsertString乮ANSI斉乯
int __cdecl Dlg_ComboBox_InsertStringFormatA ( HWND hDlg, int nId, int nIndex, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( GetDlgItem ( hDlg, nId ), CB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_ComboBox_InsertString乮UNICODE斉乯
int __cdecl Dlg_ComboBox_InsertStringFormatW ( HWND hDlg, int nId, int nIndex, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( GetDlgItem ( hDlg, nId ), CB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}



////////////////////////////////////////
//     儕僗僩儃僢僋僗乮彂幃晅偒乯     //
////////////////////////////////////////



// 彂幃晅偒 ListBox_AddString乮ANSI斉乯
int __cdecl ListBox_AddStringFormatA ( HWND hWnd, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( hWnd, LB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 ListBox_AddString乮UNICODE斉乯
int __cdecl ListBox_AddStringFormatW ( HWND hWnd, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( hWnd, LB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 ListBox_InsertString乮ANSI斉乯
int __cdecl ListBox_InsertStringFormatA ( HWND hWnd, int nIndex, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( hWnd, LB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 ListBox_InsertString乮UNICODE斉乯
int __cdecl ListBox_InsertStringFormatW ( HWND hWnd, int nIndex, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( hWnd, LB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}



// 彂幃晅偒 Dlg_ListBox_AddString乮ANSI斉乯
int __cdecl Dlg_ListBox_AddStringFormatA ( HWND hDlg, int nId, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( GetDlgItem ( hDlg, nId ), LB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_ListBox_AddString乮UNICODE斉乯
int __cdecl Dlg_ListBox_AddStringFormatW ( HWND hDlg, int nId, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( GetDlgItem ( hDlg, nId ), LB_ADDSTRING, 0, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_ListBox_InsertString乮ANSI斉乯
int __cdecl Dlg_ListBox_InsertStringFormatA ( HWND hDlg, int nId, int nIndex, const char *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatA ( GetDlgItem ( hDlg, nId ), LB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}


// 彂幃晅偒 Dlg_ListBox_InsertString乮UNICODE斉乯
int __cdecl Dlg_ListBox_InsertStringFormatW ( HWND hDlg, int nId, int nIndex, const wchar_t *format,... ) {
   va_list args ;
   va_start ( args, format ) ;
   int retvalue = LRESULT_TO_INT ( SendMessageVaFormatW ( GetDlgItem ( hDlg, nId ), LB_INSERTSTRING, nIndex, format, args ) ) ;
   va_end ( args ) ;
   return retvalue ;
}



//////////////////////////////
//         vscprintf        //
//////////////////////////////



#undef vfwprintf  // not oem_vfwprintf



#if ! defined _MSC_VER || _MSC_VER < 1300
// Printf曄姺偺弌椡偵昁梫側僶僢僼傽偺挿偝傪庢摼偡傞
// 暥帤悢傪曉偡乮廔抂偺 NULL 傪娷傑側偄乯
static int __cdecl vscprintf ( const char *format, va_list args ) {
   FILE *stdnul = fopen ( "NUL", "wb" ) ;
   if ( ! stdnul ) return EOF ;
   int retvalue = vfprintf ( stdnul, format, args ) ;
   fclose ( stdnul ) ;
   return retvalue ;
}
#endif



#if ! defined _MSC_VER || _MSC_VER < 1300
// Printf曄姺偺弌椡偵昁梫側僶僢僼傽偺挿偝傪庢摼偡傞
// 暥帤悢傪曉偡乮廔抂偺 NULL 傪娷傑側偄乯
static int __cdecl vscwprintf ( const wchar_t *format, va_list args ) {
   FILE *stdnul = fopen ( "NUL", "wb" ) ;
   if ( ! stdnul ) return EOF ;
   int retvalue = vfwprintf ( stdnul, format, args ) ;
   fclose ( stdnul ) ;
   return retvalue ;
}
#endif



////////////////////////////////////////
//             WindowLong             //
////////////////////////////////////////



// 僂傿儞僪僂僾儘僔乕僕儍傪愝掕偡傞乮ANSI斉乯
WNDPROC SetWindowProcA ( HWND hWnd, WNDPROC WndProc ) {
   return (WNDPROC) SetWindowLongPtrA ( hWnd, GWLP_WNDPROC, (LONG_PTR) WndProc ) ;
}


// 僂傿儞僪僂僾儘僔乕僕儍傪愝掕偡傞乮UNICODE斉乯
WNDPROC SetWindowProcW ( HWND hWnd, WNDPROC WndProc ) {
   return (WNDPROC) SetWindowLongPtrW ( hWnd, GWLP_WNDPROC, (LONG_PTR) WndProc ) ;
}


// 僂傿儞僪僂僾儘僔乕僕儍傪庢摼偡傞乮ANSI斉乯
WNDPROC GetWindowProcA ( HWND hWnd ) {
   return (WNDPROC) GetWindowLongPtrA ( hWnd, GWLP_WNDPROC ) ;
}


// 僂傿儞僪僂僾儘僔乕僕儍傪庢摼偡傞乮UNICODE斉乯
WNDPROC GetWindowProcW ( HWND hWnd ) {
   return (WNDPROC) GetWindowLongPtrW ( hWnd, GWLP_WNDPROC ) ;
}



// 僟僀傾儘僌僾儘僔乕僕儍偐傜曉偡抣傪愝掕偡傞
int SetDlgMsgResult ( HWND hWnd, LRESULT lResult ) {
   if ( IsNT () ) SetWindowLongPtrW ( hWnd, DWLP_MSGRESULT, lResult ) ;
   else           SetWindowLongPtrA ( hWnd, DWLP_MSGRESULT, lResult ) ;
   return 0 ;
}



⌨️ 快捷键说明

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