Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
5.3 KiB

  1. /****************************************************************************
  2. Hidden 16-bit window for
  3. Switch Input Library DLL
  4. Copyright (c) 1992-1997 Bloorview MacMillan Centre
  5. This mini-application reports the 16-bit bios table address information
  6. back to the 32-bit world of the Switch Input Library
  7. ****************************************************************************/
  8. //#define DEBUGMSG
  9. /**************************************************************** Headers */
  10. #include <windows.h>
  11. #include <dde.h>
  12. #include <memory.h>
  13. #define APIENTRY FAR PASCAL
  14. long APIENTRY WndProc( HWND hWnd, UINT uMsg, WPARAM uParam, LPARAM lParam );
  15. char szAppName[] = "MSSWCHY";
  16. int nShow; // if Debug this will be SHOW
  17. BYTE bios_data_area[16];
  18. HANDLE hData;
  19. DDEDATA FAR *pdata;
  20. extern WORD _0040h;
  21. #ifdef DEBUGMSG
  22. char szDbgMsg[80];
  23. #endif
  24. /********************************************* Windows Callback Functions */
  25. /********************************************************\
  26. Windows initialization
  27. \********************************************************/
  28. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  29. HANDLE hInstance, hPrevInstance;
  30. LPSTR lpszCmdLine;
  31. int nCmdShow;
  32. {
  33. HWND hWnd;
  34. MSG msg;
  35. WNDCLASS wndclass;
  36. // Look for magic word
  37. if (
  38. ( lpszCmdLine[0] != 'S' )
  39. || ( lpszCmdLine[1] != 'W' )
  40. || ( lpszCmdLine[2] != 'C' )
  41. || ( lpszCmdLine[3] != 'H' )
  42. )
  43. {
  44. MessageBox( GetFocus(), "This is not a user program", "MSSWCHY",
  45. MB_OK | MB_ICONHAND );
  46. return FALSE;
  47. }
  48. if(!hPrevInstance)
  49. {
  50. wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  51. wndclass.lpfnWndProc = WndProc;
  52. wndclass.cbClsExtra = 0;
  53. wndclass.cbWndExtra = 0;
  54. wndclass.hInstance = hInstance;
  55. wndclass.hIcon = NULL;
  56. wndclass.hCursor = NULL;
  57. wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  58. wndclass.lpszMenuName = NULL;
  59. wndclass.lpszClassName = szAppName;
  60. if(!RegisterClass(&wndclass))
  61. return FALSE;
  62. }
  63. hWnd = CreateWindow(szAppName, szAppName,
  64. WS_OVERLAPPEDWINDOW,
  65. 0,0,10,10,
  66. NULL, NULL, hInstance, NULL);
  67. nShow = nCmdShow;
  68. ShowWindow(hWnd, nCmdShow);
  69. UpdateWindow(hWnd);
  70. while(GetMessage(&msg, NULL, 0, 0))
  71. {
  72. TranslateMessage(&msg);
  73. DispatchMessage(&msg);
  74. }
  75. return msg.wParam;
  76. }
  77. /********************************************************\
  78. Main window procedure
  79. \********************************************************/
  80. long APIENTRY WndProc(HWND hWnd, UINT uMsg, WPARAM uParam, LPARAM lParam)
  81. {
  82. #ifdef xDEBUGMSG
  83. sprintf( szDbgMsg, "MP Msg: %X %X %lX\r\n", iMessage, wParam, lParam );
  84. OutputDebugString( szDbgMsg );
  85. #endif
  86. switch(uMsg)
  87. {
  88. case WM_CREATE:
  89. {
  90. HWND hSwchx;
  91. hSwchx = FindWindow( "MSSWCHX", NULL );
  92. _fmemcpy( bios_data_area,
  93. (LPSTR)(MAKELONG(0,&_0040h)),
  94. sizeof( bios_data_area ) );
  95. hData = GlobalAlloc( GMEM_DDESHARE, sizeof( DDEDATA ) + sizeof( bios_data_area ));
  96. if (hData)
  97. {
  98. pdata = (DDEDATA FAR *) GlobalLock( hData );
  99. pdata->fResponse = TRUE;
  100. pdata->fRelease = FALSE;
  101. pdata->fAckReq = FALSE;
  102. pdata->cfFormat = CF_OWNERDISPLAY;
  103. _fmemcpy( pdata->Value, bios_data_area, sizeof( bios_data_area ) );
  104. GlobalUnlock( hData );
  105. PostMessage( hSwchx, WM_DDE_DATA, hWnd, MAKELONG( hData, 0 ));
  106. }
  107. }
  108. break;
  109. case WM_DDE_ACK:
  110. {
  111. if (hData)
  112. GlobalFree( hData );
  113. if (nShow != SW_SHOW)
  114. PostMessage( hWnd, WM_CLOSE, 0, 0L );
  115. }
  116. break;
  117. case WM_PAINT: // should only happen in debug mode
  118. {
  119. PAINTSTRUCT ps;
  120. char szOutBuff[100];
  121. int i;
  122. BeginPaint( hWnd, &ps );
  123. i = 0;
  124. wsprintf( szOutBuff, "Bios Data Area" );
  125. TextOut( ps.hdc,0,10 * i,szOutBuff,lstrlen(szOutBuff));
  126. for ( i=0;i<8;i++ )
  127. {// note reversed pairs
  128. wsprintf( szOutBuff, "Port%d: %02X %02X", i,
  129. bios_data_area[2*i+1], bios_data_area[2*i] );
  130. TextOut( ps.hdc,0,30 + 30 * i,szOutBuff,lstrlen(szOutBuff));
  131. }
  132. EndPaint( hWnd, &ps );
  133. }
  134. break;
  135. case WM_CLOSE:
  136. case WM_QUERYENDSESSION:
  137. if (uMsg == WM_QUERYENDSESSION)
  138. return 1L;
  139. else
  140. DestroyWindow( hWnd );
  141. break;
  142. /* Window has just been closed */
  143. case WM_DESTROY:
  144. PostQuitMessage(0);
  145. case WM_ENDSESSION:
  146. if (!uParam && (uMsg == WM_ENDSESSION)) /* Windows is not terminating */
  147. break;
  148. /* else continue */
  149. break;
  150. default:
  151. return DefWindowProc(hWnd, uMsg, uParam, lParam);
  152. }
  153. return 0L;
  154. }