初识Wine
Wine是什么?它是一个Windows系统在Linux、Unix系统上的实现,它实现了基本上所有的Windows API,并且都有源代码,当你对DispachMessage,PeekMessage的实现想弄个究竟或是自己设计一个类似Windows的消息系统等等等时,那就可以看看研究一下Wine的实现了!看看Wine官网的介绍(http://www.winehq.org/):
Wine is an Open Source implementation of the Windows API on top of X, OpenGL, and Unix.
Think of Wine as a compatibility layer for running Windows programs. Wine does not require Microsoft Windows, as it is a completely free alternative implementation of the Windows API consisting of 100% non-Microsoft code, however Wine can optionally use native Windows DLLs if they are available. Wine provides both a development toolkit for porting Windows source code to Unix as well as a program loader, allowing many unmodified Windows programs to run on x86-based Unixes, including Linux, FreeBSD, Mac OS X, and Solaris.
More information can be read in the articles Why Wine is so important, and Debunking Wine Myths. If you are wondering how well a particular application works in Wine, please examine the Applications Database. For installation instructions and step-by-step help with running Wine, take a look at the User Guide.
Wine is free software. The licensing terms are the GNU Lesser General Public License.
预览一下效果图,Lotus在Linux上运行的效果:
下载Wine的source code,建立了一个Source Inside 的Project,开始查看其代码,帖一个DispatchMessage codesnippet:
BOOL WINAPI TranslateMessage( const MSG *msg )
{
UINT message;
WCHAR wp[2];
BYTE state[256];
if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
TRACE_(key)("Translating key %s (%04lx), scancode %02x/n",
SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
GetKeyboardState( state );
/* FIXME : should handle ToUnicode yielding 2 */
switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
{
case 1:
message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)/n",
msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
break;
case -1:
message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)/n",
msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
break;
}
return TRUE;
}
慢慢看,学习一下,对windows和liux系统的编程都有很好的帮助,Go!