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

📄 sendmsg.cpp

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

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "msc.h"
#include "sendmsg.h"



////////////////////////////////////////
//              嫟捠娭悢              //
////////////////////////////////////////



#undef SendMessage


static LRESULT SendMessage ( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ) {
   if ( IsNT () ) return SendMessageW ( hWnd, Msg, wParam, lParam ) ;
   else           return SendMessageA ( hWnd, Msg, wParam, lParam ) ;
}



static inline int LRESULT_TO_INT ( LRESULT nValue ) {
   if ( nValue != (int) nValue ) return -1 ;
   return (int) nValue ;
}



////////////////////////////////////////
//         僂傿儞僪僂憖嶌堦斒         //
////////////////////////////////////////



HICON Wm_SetIcon ( HWND hWnd, int nIconSize, HICON hIcon ) {
   return (HICON) SendMessage ( hWnd, WM_SETICON, nIconSize, (LPARAM) hIcon ) ;
}


int Wm_SetFont ( HWND hWnd, HFONT hFont, int IsRedraw ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, WM_SETFONT, (WPARAM) hFont, IsRedraw ) ) ;
}


int Wm_Notify ( HWND hWnd, NMHDR *pNotifyMessageHeader ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, WM_NOTIFY, 0, (LPARAM) pNotifyMessageHeader ) ) ;
}


int Wm_GetTextA ( HWND hWnd, char *szString, int nMaxLen ) {
   if ( szString && nMaxLen ) *szString = 0 ;
   return LRESULT_TO_INT ( SendMessageA ( hWnd, WM_GETTEXT, nMaxLen, (LPARAM) szString ) ) ;
}


int Wm_GetTextW ( HWND hWnd, wchar_t *szString, int nMaxLen ) {
   if ( szString && nMaxLen ) *szString = 0 ;
   return LRESULT_TO_INT ( SendMessageW ( hWnd, WM_GETTEXT, nMaxLen, (LPARAM) szString ) ) ;
}


int Wm_SetTextA ( HWND hWnd, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, WM_SETTEXT, 0, (LPARAM) szString ) ) ;
}


int Wm_SetTextW ( HWND hWnd, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, WM_SETTEXT, 0, (LPARAM) szString ) ) ;
}


int Wm_GetTextLengthA ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, WM_GETTEXTLENGTH, 0, 0 ) ) ;
}


int Wm_GetTextLengthW ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, WM_GETTEXTLENGTH, 0, 0 ) ) ;
}


int Wm_KeyDown ( HWND hWnd, int nVirtualKey ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, WM_KEYDOWN, nVirtualKey, 1 ) ) ;
}


int Wm_Destroy ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, WM_DESTROY, 0, 0 ) ) ;
}


int Wm_CopyData ( HWND hWnd, HWND hWndFrom, const COPYDATASTRUCT *pCopyDataStruct ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, WM_COPYDATA, (WPARAM) hWndFrom, (LPARAM) pCopyDataStruct ) ) ;
}



////////////////////////////////////////
//             僟僀傾儘僌             //
////////////////////////////////////////



int Dlg_SetFocus ( HWND hDlg, int nId ) {
   return LRESULT_TO_INT ( SendMessage ( hDlg, WM_NEXTDLGCTL, (WPARAM) GetDlgItem ( hDlg, nId ), TRUE ) ) ;
}



int Dlg_EnableWindow ( HWND hDlg, int nId, int IsEnable ) {
   HWND hControl = GetDlgItem ( hDlg, nId ) ;
   if ( ! IsEnable && hControl == GetFocus () ) SendMessage ( hDlg, WM_NEXTDLGCTL, 0, FALSE ) ;
   return EnableWindow ( hControl, IsEnable ) ;
}



////////////////////////////////////////
//         儃僞儞僐儞僩儘乕儖         //
////////////////////////////////////////



int Button_SetStyle ( HWND hWnd, int nStyle, int IsRedraw ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, BM_SETSTYLE, nStyle, MAKELPARAM ( IsRedraw, 0 ) ) ) ;
}



////////////////////////////////////////
//          僞僽僐儞僩儘乕儖          //
////////////////////////////////////////



int TabCtrl_InsertItemA ( HWND hWnd, int nItem, const TC_ITEMA *pItem ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, TCM_INSERTITEMA, nItem, (LPARAM) pItem ) ) ;
}


int TabCtrl_InsertItemW ( HWND hWnd, int nItem, const TC_ITEMW *pItem ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, TCM_INSERTITEMW, nItem, (LPARAM) pItem ) ) ;
}


int TabCtrl_AdjustRect ( HWND hWnd, int IsLarger, RECT *pRect ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, TCM_ADJUSTRECT, IsLarger, (LPARAM) pRect ) ) ;
}


int TabCtrl_GetCurSel ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, TCM_GETCURSEL, 0, 0 ) ) ;
}



////////////////////////////////////////
//       僄僨傿僢僩僐儞僩儘乕儖       //
////////////////////////////////////////



int Edit_GetMargins ( HWND hWnd, int *pLeftMargin, int *pRightMargin ) {
   int nResult = LRESULT_TO_INT ( SendMessage ( hWnd, EM_GETMARGINS, 0, 0 ) ) ;
   if ( pLeftMargin ) *pLeftMargin = (short) nResult ;
   if ( pRightMargin ) *pRightMargin = (short) ( nResult >> 16 ) ;
   return nResult ;
}


int Edit_SetMargins ( HWND hWnd, short nLeftMargin, short nRightMargin ) {
   WPARAM flags = 0 ;
   if ( nLeftMargin != -1 ) flags |= EC_LEFTMARGIN ;
   if ( nRightMargin != -1 ) flags |= EC_RIGHTMARGIN ;
   return LRESULT_TO_INT ( SendMessage ( hWnd, EM_SETMARGINS, flags, MAKELPARAM ( nLeftMargin, nRightMargin ) ) ) ;
}


int Edit_SetReadOnly ( HWND hWnd, int IsReadOnly ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, EM_SETREADONLY, IsReadOnly, 0 ) ) ;
}


int Edit_SetSel ( HWND hWnd, int nStart, int nEnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, EM_SETSEL, nStart, nEnd ) ) ;
}


int Edit_LimitText ( HWND hWnd, int nMax ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, EM_LIMITTEXT, nMax, 0 ) ) ;
}



////////////////////////////////////////
//     僐儞儃儃僢僋僗僐儞僩儘乕儖     //
////////////////////////////////////////



int ComboBox_AddStringA ( HWND hWnd, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, CB_ADDSTRING, 0, (LPARAM) szString ) ) ;
}


int ComboBox_AddStringW ( HWND hWnd, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, CB_ADDSTRING, 0, (LPARAM) szString ) ) ;
}


int ComboBox_InsertStringA ( HWND hWnd, int nIndex, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, CB_INSERTSTRING, nIndex, (LPARAM) szString ) ) ;
}


int ComboBox_InsertStringW ( HWND hWnd, int nIndex, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, CB_INSERTSTRING, nIndex, (LPARAM) szString ) ) ;
}


int ComboBox_GetCount ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_GETCOUNT, 0, 0 ) ) ;
}


int ComboBox_ResetContent ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_RESETCONTENT, 0, 0 ) ) ;
}


int ComboBox_GetCurSel ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_GETCURSEL, 0, 0 ) ) ;
}


int ComboBox_SetCurSel ( HWND hWnd, int nIndex ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_SETCURSEL, nIndex, 0 ) ) ;
}


int ComboBox_SelectStringA ( HWND hWnd, int nIndexStart, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, CB_SELECTSTRING, nIndexStart, (LPARAM) szString ) ) ;
}


int ComboBox_SelectStringW ( HWND hWnd, int nIndexStart, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, CB_SELECTSTRING, nIndexStart, (LPARAM) szString ) ) ;
}


int ComboBox_FindStringExactA ( HWND hWnd, int nIndexStart, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM) szString ) ) ;
}


int ComboBox_FindStringExactW ( HWND hWnd, int nIndexStart, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM) szString ) ) ;
}


int ComboBox_GetItemHeight ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_GETITEMHEIGHT, 0, 0 ) ) ;
}


int ComboBox_SetEditSel ( HWND hWnd, short nStart, short nEnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_SETEDITSEL, 0, MAKELPARAM ( nStart, nEnd ) ) ) ;
}


int ComboBox_LimitText ( HWND hWnd, int nMax ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, CB_LIMITTEXT, nMax, 0 ) ) ;
}



////////////////////////////////////////
//     儕僗僩儃僢僋僗僐儞僩儘乕儖     //
////////////////////////////////////////



int ListBox_AddStringA ( HWND hWnd, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, LB_ADDSTRING, 0, (LPARAM) szString ) ) ;
}


int ListBox_AddStringW ( HWND hWnd, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, LB_ADDSTRING, 0, (LPARAM) szString ) ) ;
}


int ListBox_InsertStringA ( HWND hWnd, int nIndex, const char *szString ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, LB_INSERTSTRING, nIndex, (LPARAM) szString ) ) ;
}


int ListBox_InsertStringW ( HWND hWnd, int nIndex, const wchar_t *szString ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, LB_INSERTSTRING, nIndex, (LPARAM) szString ) ) ;
}


int ListBox_GetCount ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, LB_GETCOUNT, 0, 0 ) ) ;
}


int ListBox_ResetContent ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, LB_RESETCONTENT, 0, 0 ) ) ;
}


int ListBox_GetCurSel ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, LB_GETCURSEL, 0, 0 ) ) ;
}


int ListBox_SetCurSel ( HWND hWnd, int nIndex ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, LB_SETCURSEL, nIndex, 0 ) ) ;
}


int ListBox_GetTextA ( HWND hWnd, int nIndex, char *szString ) {
   if ( szString ) *szString = 0 ;
   return LRESULT_TO_INT ( SendMessageA ( hWnd, LB_GETTEXT, nIndex, (LPARAM) szString ) ) ;
}


int ListBox_GetTextW ( HWND hWnd, int nIndex, wchar_t *szString ) {
   if ( szString ) *szString = 0 ;
   return LRESULT_TO_INT ( SendMessageW ( hWnd, LB_GETTEXT, nIndex, (LPARAM) szString ) ) ;
}


int ListBox_GetTextLenA ( HWND hWnd, int nIndex ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, LB_GETTEXTLEN, nIndex, 0 ) ) ;
}


int ListBox_GetTextLenW ( HWND hWnd, int nIndex ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, LB_GETTEXTLEN, nIndex, 0 ) ) ;
}



////////////////////////////////////////
//       僾儘僌儗僗僐儞僩儘乕儖       //
////////////////////////////////////////



int ProgressCtrl_SetRange ( HWND hWnd, short nMin, short nMax ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, PBM_SETRANGE, 0, MAKELPARAM ( nMin, nMax ) ) ) ;
}


int ProgressCtrl_SetStep ( HWND hWnd, int nStep ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, PBM_SETSTEP, nStep, 0 ) ) ;
}


int ProgressCtrl_SetPos ( HWND hWnd, int nPos ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, PBM_SETPOS, nPos, 0 ) ) ;
}


int ProgressCtrl_StepIt ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, PBM_STEPIT, 0, 0 ) ) ;
}



////////////////////////////////////////
//             僣乕儖僶乕             //
////////////////////////////////////////



int ToolBar_ButtonCount ( HWND hWnd ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, TB_BUTTONCOUNT, 0, 0 ) ) ;
}


int ToolBar_GetButton ( HWND hWnd, int nIndex, TBBUTTON *pButton ) {
   return LRESULT_TO_INT ( SendMessage ( hWnd, TB_GETBUTTON, nIndex, (LPARAM) pButton ) ) ;
}


#if _WIN32_IE < 0x0400
#define TB_GETBUTTONINFOW        (WM_USER + 63)
#define TB_GETBUTTONINFOA        (WM_USER + 65)
#endif


int ToolBar_GetButtonInfoA ( HWND hWnd, int nCommandId, TBBUTTONINFOA *pButtonInfo ) {
   return LRESULT_TO_INT ( SendMessageA ( hWnd, TB_GETBUTTONINFOA, nCommandId, (LPARAM) pButtonInfo ) ) ;
}


int ToolBar_GetButtonInfoW ( HWND hWnd, int nCommandId, TBBUTTONINFOW *pButtonInfo ) {
   return LRESULT_TO_INT ( SendMessageW ( hWnd, TB_GETBUTTONINFOW, nCommandId, (LPARAM) pButtonInfo ) ) ;
}



////////////////////////////////////////
//     僐儞儃儃僢僋僗僐儞僩儘乕儖     //
////////////////////////////////////////



static int IsComctlVisualStyle ( void ) ;


#ifndef CB_SETMINVISIBLE
#define CB_SETMINVISIBLE   0x1701
#endif



// 僐儞儃儃僢僋僗傪僪儘僢僾偟偨偲偒偺崅偝傪愝掕偡傞
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int ComboBox_SetMaxHeight ( HWND hComboBox, int nItemMax ) {

   int nRetValue = 1 ;

   int nItem = ComboBox_GetCount ( hComboBox ) ;
   if ( nItem < 0 ) return nRetValue ;
   if ( nItem < nItemMax ) nItemMax = nItem ;
   if ( nItemMax < 1 ) nItemMax = 1 ;

   if ( IsComctlVisualStyle () ) {
      if ( SendMessageW ( hComboBox, CB_SETMINVISIBLE, nItemMax, 0 ) ) nRetValue = 0 ;
   }
   else {

      RECT Rect ;
      if ( ! GetWindowRect ( hComboBox, & Rect ) ) return nRetValue ;

      int nHeight = ComboBox_GetItemHeight ( hComboBox ) ;
      if ( nHeight < 0 ) return nRetValue ;
      nHeight = nHeight * ( nItemMax + 2 ) ;

      if ( SetWindowPos ( hComboBox, 0, 0, 0, Rect.right - Rect.left, nHeight, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER ) ) nRetValue = 0 ;

      ComboBox_SetEditSel ( hComboBox, -1, 0 ) ;
   }

   return nRetValue ;
}



////////////////////////////////////////
//          XP Visual Style           //
////////////////////////////////////////



// shlwapi.h
typedef struct {
   DWORD cbSize ;
   DWORD dwMajorVersion ;        // Major version
   DWORD dwMinorVersion ;        // Minor version
   DWORD dwBuildNumber ;         // Build number
   DWORD dwPlatformID ;          // DLLVER_PLATFORM_*
} DLLVERSIONINFO ;


typedef HRESULT ( CALLBACK *DLLGETVERSION ) ( DLLVERSIONINFO *pdvi ) ;



static int IsComctlVisualStyle ( void ) {

   static int nRetValueSaved = -1 ;
   if ( nRetValueSaved >= 0 ) return nRetValueSaved ;

   int nRetValue = 0 ;

   if ( IsWinXPorLater () ) {

      HINSTANCE hComctl32 = LoadLibraryW ( L"COMCTL32.DLL" ) ;
      DLLGETVERSION DllGetVersion = NULL ;

      if ( ! GETPROCADDRESS ( hComctl32, DLLGETVERSION, DllGetVersion ) ) {

         DLLVERSIONINFO DllVersionInfo = { sizeof(DLLVERSIONINFO) } ;

         if ( DllGetVersion ( &  DllVersionInfo ) == NOERROR ) {
            if ( DllVersionInfo.dwMajorVersion >= 6 ) nRetValue = 1 ;
         }
      }

      FreeLibrary ( hComctl32 ) ;
   }

   nRetValueSaved = nRetValue ;

   return nRetValue ;
}



////////////////////////////////////////
//            彂幃晅偒娭悢            //
////////////////////////////////////////

⌨️ 快捷键说明

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