📄 win2mac.cpp
字号:
case WM_KEYDOWN:
case WM_KEYUP:
{
MacSimulateKey(msg,wparam);
}
break;
case WM_SIZE:
//case WM_SETFOCUS:
//case WM_SYSCOLORCHANGE:
//case WM_MOVE:
//case WM_MACINTOSH:
{
return DefWindowProc(hwnd, msg, wparam, lparam);
}
break;
case WM_CHAR:
{
return RichEditWndProc(hwnd, msg, wparam, lparam);
}
break;
default:
return RichEditANSIWndProc(hwnd, msg, wparam, lparam);
}
return RichEditANSIWndProc(hwnd, msg, wparam, lparam);
}
//----------------------------------------------------------------------------
//
// Function: MacSelectPalette
//
//----------------------------------------------------------------------------
HPALETTE WINAPI MacSelectPalette(HDC hdc, HPALETTE hpal, BOOL bForceBackground)
{
if (hpal)
return ::SelectPalette(hdc,hpal,bForceBackground);
else
return NULL;
}
//----------------------------------------------------------------------------
//
// Function: MacportSetCursor
//
//----------------------------------------------------------------------------
HCURSOR MacportSetCursor(HCURSOR hCursor)
{
if (hCursor)
return SetCursor(hCursor);
else
{
ObscureCursor();
return NULL;
}
}
//----------------------------------------------------------------------------
//
// Function: MacSetMetaFileBitsEx
//
//----------------------------------------------------------------------------
HMETAFILE WINAPI MacSetMetaFileBitsEx(UINT nSize,CONST BYTE * lpData )
{
Assert (0 && "SetMetaFileBitsEx is not implemented for Macintosh");
return NULL;
}
//-------------------------------------------------------------------------
//
// Function: MacSimulateKey
//
// Synopsis: Simulates menu enabler keys for the mac
//
// Arguments: [msg]
// [wParam]
//
// Returns: UINT
//
// Notes: The key is changed to accommodate the mac.
//
//
//-------------------------------------------------------------------------
UINT MacSimulateKey (UINT& msg, WPARAM& wParam)
{
BYTE rgbKeyState[256];
GetKeyboardState(rgbKeyState);
if (rgbKeyState[VK_CONTROL])
{
rgbKeyState[VK_CONTROL] = 0;
}
SetKeyboardState(rgbKeyState);
return msg;
}
//-------------------------------------------------------------------------
//
// Function: MacSimulateMouseButtons
//
// Synopsis: Simulates the right and middle mouse Windows buttons.
//
// Arguments: [msg]
// [wParam]
//
// Returns: UINT
//
// Notes: The right mouse is simulated by CTRL (or COMMAND) click. The
// middle mouse is simulated by SHIFT click. Because CTRL is already
// in use the CTRL click is simulated using the OPTION key.
//
// The command key is used the same as the control key because
// WLM likes to pick up the CTRL mouse as a user break. This makes
// debugging the right mouse simulation very difficult.
//
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
typedef struct tagUISim
{
UINT msg;
UINT wParam;
BYTE control; // Value for VK_CONTROL key state
BYTE menu; // Value for VK_MENU key state
} UISim;
//-------------------------------------------------------------------------
UINT MacSimulateMouseButtons (UINT& msg, WPARAM& wParam)
{
BYTE rgbKeyState[256];
WORD stateIndex = 0;
UISim UISim[] = // 8 4 2 1
{ // cmd shift ctrl option
WM_LBUTTONDOWN, MK_LBUTTON, 0x00, 0x00, // - - - -
WM_LBUTTONDOWN, MK_LBUTTON|MK_CONTROL, 0x80, 0x00, // - - - x
WM_RBUTTONDOWN, MK_RBUTTON, 0x00, 0x00, // - - x -
WM_RBUTTONDOWN, MK_RBUTTON|MK_CONTROL, 0x80, 0x00, // - - x x
WM_MBUTTONDOWN, MK_MBUTTON, 0x00, 0x00, // - x - -
WM_MBUTTONDOWN, MK_MBUTTON|MK_CONTROL, 0x80, 0x00, // - x - x
WM_RBUTTONDOWN, MK_RBUTTON|MK_MBUTTON, 0x00, 0x00, // - x x -
WM_RBUTTONDOWN, MK_RBUTTON|MK_MBUTTON|MK_CONTROL, 0x80, 0x00, // - x x x
WM_LBUTTONDOWN, MK_LBUTTON, 0x00, 0x10, // x - - -
WM_LBUTTONDOWN, MK_LBUTTON|MK_CONTROL, 0x80, 0x10, // x - - x
WM_RBUTTONDOWN, MK_RBUTTON, 0x00, 0x10, // x - x -
WM_RBUTTONDOWN, MK_RBUTTON|MK_CONTROL, 0x80, 0x10, // x - x x
WM_MBUTTONDOWN, MK_MBUTTON, 0x00, 0x10, // x x - -
WM_MBUTTONDOWN, MK_MBUTTON|MK_CONTROL, 0x80, 0x10, // x x - x
WM_RBUTTONDOWN, MK_RBUTTON|MK_MBUTTON, 0x00, 0x10, // x x x -
WM_RBUTTONDOWN, MK_RBUTTON|MK_MBUTTON|MK_CONTROL, 0x80, 0x10 // x x x x
};
// Determine which keys were pressed, and clean out the state variables
GetKeyboardState(rgbKeyState);
if (rgbKeyState[VK_OPTION])
{
rgbKeyState[VK_OPTION] = 0; // Clear key state
stateIndex |= 0x01; // Set option key bit in index
}
if (rgbKeyState[VK_CONTROL])
{
rgbKeyState[VK_CONTROL] = 0; // Clear key state
stateIndex |= 0x02; // Set control key bit in index
}
if (rgbKeyState[VK_COMMAND]) // Use command key like control key due to WLM debug issues
{
rgbKeyState[VK_COMMAND] = 0; // Clear key state
stateIndex |= 0x08; // Set command key bit in index
}
if (rgbKeyState[VK_SHIFT])
{
rgbKeyState[VK_SHIFT] = 0; // Clear key state
stateIndex |= 0x04; // Set shift key bit in index
}
// Now set the return values
if (stateIndex) // Only do this is the mouse is being simulated
{
msg = (msg - WM_LBUTTONDOWN) + UISim[stateIndex].msg;
wParam = UISim[stateIndex].wParam;
rgbKeyState[VK_CONTROL] = UISim[stateIndex].control;
rgbKeyState[VK_MENU] = UISim[stateIndex].menu;
SetKeyboardState(rgbKeyState);
}
return msg;
}
//----------------------------------------------------------------------------
//
// Function: MacSysAllocStringLen
//
//----------------------------------------------------------------------------
STDAPI_(BSTR) MacSysAllocStringLen(LPCWSTR lpStringW, UINT lenChars)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "SysAllocStringLenMac");
int lenStrBytes;
LPSTR lpStringMB;
if ((lpStringW) && (*lpStringW != NULL))
{
lenStrBytes = MsoWideCharToMultiByte(CP_ACP,0,lpStringW,lenChars,NULL,NULL,NULL,NULL);
lpStringMB = (LPSTR)CoTaskMemAlloc( lenStrBytes + sizeof(INT) );
memcpy(lpStringMB, &lenStrBytes, sizeof(INT)); //copy BSTR lenghth in integer before BSTR
lpStringMB += sizeof(INT);
MsoWideCharToMultiByte(CP_ACP,0,lpStringW,lenChars,lpStringMB,lenStrBytes,NULL,NULL);
}
else
{
// note that in every case so far used on RichEdit the first parm is NULL
// so no way to determine how big to make the buffer
// therefore making it the lenghth of a unicode buffer - max size it could be for mbcs
lenStrBytes = lenChars*sizeof(WCHAR);
lpStringMB = (LPSTR)CoTaskMemAlloc( lenStrBytes + sizeof(INT) );
// not sure if this should be lenChars or lenStrBytes
// note that lenStrBytes is wchar lenghth - the max length it could be for mbcs
// memcpy(lpStringMB, &lenStrBytes, sizeof(INT)); //copy BSTR lenghth in integer before BSTR
memcpy(lpStringMB, &lenChars, sizeof(INT)); //copy BSTR lenghth in integer before BSTR
lpStringMB += sizeof(INT);
}
return (BSTR)lpStringMB;
}
//----------------------------------------------------------------------------
//
// Function: MacWordSwapLong
//
//----------------------------------------------------------------------------
ULONG MacWordSwapLong ( ULONG ul)
{
WORD w1,w2;
w1 = (WORD)ul;
w2 = (WORD)(ul>>16);
return (((ULONG)w1)<<16) | w2;
}
#endif //MACPORT
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -