home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / input / ime / multiui / multiui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-11  |  11.3 KB  |  346 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*      MULTIUI.C                                                     */
  4. /*                                                                    */
  5. /*      Copyright (c) 1995-1996  Microsoft Corporation                     */
  6. /*                                                                    */
  7. /**********************************************************************/
  8.  
  9. #include "windows.h"
  10. #include "imm.h"
  11. #include "resource.h"
  12. #include "multiui.h"
  13.  
  14.  
  15. /**********************************************************************/
  16. /*                                                                    */
  17. /*    WinMain(HANDLE, HANDLE, LPSTR, int)                             */
  18. /*                                                                    */
  19. /**********************************************************************/
  20. int APIENTRY WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  21. HINSTANCE hInstance;
  22. HINSTANCE hPrevInstance;
  23. LPSTR lpCmdLine;
  24. int nCmdShow;
  25. {
  26.     MSG msg;
  27.  
  28.     if (!hPrevInstance)  
  29.         if (!InitApplication(hInstance))
  30.             return (FALSE);
  31.  
  32.     if (!InitInstance(hInstance, nCmdShow))
  33.     return (FALSE);
  34.  
  35.     
  36.     while (GetMessage(&msg, NULL, 0, 0))
  37.     {
  38.     TranslateMessage(&msg);
  39.     DispatchMessage(&msg);
  40.     }
  41.     return (msg.wParam);
  42. }
  43.  
  44. /**********************************************************************/
  45. /*                                                                    */
  46. /*    InitApplication(HANDLE)                                         */
  47. /*                                                                    */
  48. /**********************************************************************/
  49. BOOL InitApplication(hInstance)
  50. HANDLE hInstance;
  51. {
  52.     WNDCLASS  wc;
  53.  
  54.     wc.style         = (UINT)NULL;
  55.     wc.lpfnWndProc   = MainWndProc;
  56.     wc.cbClsExtra    = 0;
  57.     wc.cbWndExtra    = 0;
  58.     wc.hInstance     = hInstance;
  59.     wc.hIcon         = LoadIcon(hInstance,"MyIcon");
  60.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  61.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  62.     wc.lpszMenuName  = "MultiUiMenu";
  63.     wc.lpszClassName = "MultiUiWClass";
  64.  
  65.     if (! RegisterClass (&wc))
  66.     return FALSE;
  67.  
  68.  
  69.     wc.style         = CS_DBLCLKS;
  70.     wc.lpfnWndProc   = NoUINoIMCWndProc;
  71.     wc.cbClsExtra    = 0;
  72.     wc.cbWndExtra    = WNDEXTRA_NOUINOIMC;
  73.     wc.hInstance     = hInstance;
  74.     wc.hIcon         = 0;
  75.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  76.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  77.     wc.lpszMenuName  = NULL;
  78.     wc.lpszClassName = "NoUINoIMCWClass";
  79.  
  80.     if (! RegisterClass (&wc))
  81.     return FALSE;
  82.  
  83.     wc.style         = CS_DBLCLKS;
  84.     wc.lpfnWndProc   = NoUIOwnIMCWndProc;
  85.     wc.cbClsExtra    = 0;
  86.     wc.cbWndExtra    = WNDEXTRA_NOUIOWNIMC;
  87.     wc.hInstance     = hInstance;
  88.     wc.hIcon         = 0;
  89.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  90.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  91.     wc.lpszMenuName  = NULL;
  92.     wc.lpszClassName = "NoUIOwnIMCWClass";
  93.  
  94.     if (! RegisterClass (&wc))
  95.     return FALSE;
  96.  
  97.     wc.style         = CS_DBLCLKS;
  98.     wc.lpfnWndProc   = OwnUIOwnIMCWndProc;
  99.     wc.cbClsExtra    = 0;
  100.     wc.cbWndExtra    = WNDEXTRA_OWNUIOWNIMC;
  101.     wc.hInstance     = hInstance;
  102.     wc.hIcon         = 0;
  103.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  104.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  105.     wc.lpszMenuName  = NULL;
  106.     wc.lpszClassName = "OwnUIOwnIMCWClass";
  107.  
  108.     if (! RegisterClass (&wc))
  109.     return FALSE;
  110.  
  111.     return TRUE;
  112. }
  113.  
  114. /**********************************************************************/
  115. /*                                                                    */
  116. /*    InitInstance(HANDLE, int)                                       */
  117. /*                                                                    */
  118. /**********************************************************************/
  119. BOOL InitInstance(hInstance, nCmdShow)
  120.     HANDLE          hInstance;
  121.     int             nCmdShow;
  122. {
  123.     RECT rc;
  124.     int iDesc = 0;
  125.     HDC hIC;
  126.     TEXTMETRIC tm;
  127.     HFONT hFont = GetDefaultGUIFont();
  128.  
  129.     char szTitle[20] =  "MultiUi TestTool";
  130.  
  131.     hInst = hInstance;
  132.  
  133.     if (!(hWndMain = CreateWindow(
  134.         "MultiUiWClass", (LPSTR)szTitle,
  135.         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  136.         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  137.         NULL, NULL, hInstance, NULL)))
  138.     return FALSE;
  139.  
  140.  
  141.     GetClientRect(hWndMain,&rc);
  142.  
  143.     rc.right  /= 2;
  144.     rc.bottom /= 3;
  145.  
  146.     hIC = CreateIC("DISPLAY", NULL, NULL, NULL);
  147.  
  148.     SelectObject(hIC, hFont);
  149.  
  150.     GetTextMetrics(hIC,&tm);
  151.  
  152.     if (rc.bottom >= tm.tmHeight)
  153.         iDesc = tm.tmHeight + tm.tmExternalLeading;
  154.  
  155.     DeleteDC(hIC);
  156.  
  157.     if (!(hWndDef1 = CreateWindowEx(WS_EX_CLIENTEDGE, "NoUINoIMCWClass", "",
  158.             WS_CHILD|WS_VISIBLE,
  159.         rc.left, rc.top + iDesc, rc.right, rc.bottom - iDesc,
  160.         hWndMain, NULL, hInstance, NULL)))
  161.     return FALSE;
  162.  
  163.     if (!(hWndDef2 = CreateWindowEx(WS_EX_CLIENTEDGE, "NoUINoIMCWClass", "",
  164.             WS_CHILD|WS_VISIBLE,
  165.         rc.right, rc.top + iDesc, rc.right, rc.bottom - iDesc,
  166.         hWndMain, NULL, hInstance, NULL)))
  167.     return FALSE;
  168.  
  169.     if (!(hWndIMC1 = CreateWindowEx(WS_EX_CLIENTEDGE, "NoUIOwnIMCWClass", "",
  170.             WS_CHILD|WS_VISIBLE,
  171.         rc.left, rc.bottom + iDesc, rc.right, rc.bottom - iDesc,
  172.         hWndMain, NULL, hInstance, NULL)))
  173.     return FALSE;
  174.  
  175.     if (!(hWndIMC2 = CreateWindowEx(WS_EX_CLIENTEDGE, "NoUIOwnIMCWClass", "",
  176.             WS_CHILD|WS_VISIBLE,
  177.         rc.right, rc.bottom + iDesc, rc.right, rc.bottom - iDesc,
  178.         hWndMain, NULL, hInstance, NULL)))
  179.     return FALSE;
  180.  
  181.     if (!(hWndIMCUI1 = CreateWindowEx(WS_EX_CLIENTEDGE, "OwnUIOwnIMCWClass", "",
  182.             WS_CHILD|WS_VISIBLE,
  183.         rc.left, rc.bottom * 2 + iDesc, rc.right, rc.bottom - iDesc,
  184.         hWndMain, NULL, hInstance, NULL)))
  185.     return FALSE;
  186.  
  187.     if (!(hWndIMCUI2 = CreateWindowEx(WS_EX_CLIENTEDGE, "OwnUIOwnIMCWClass", "",
  188.             WS_CHILD|WS_VISIBLE,
  189.         rc.right, rc.bottom * 2 + iDesc, rc.right, rc.bottom - iDesc,
  190.         hWndMain, NULL, hInstance, NULL)))
  191.     return FALSE;
  192.  
  193.  
  194.     /* display each windows */
  195.     ShowWindow (hWndMain, nCmdShow);
  196.     UpdateWindow (hWndMain);
  197.  
  198.     return TRUE;
  199.  
  200. }
  201.  
  202. /**********************************************************************/
  203. /*                                                                    */
  204. /*    MainWndProc(HWND, UINT, WPARAM, LPARAM)                         */
  205. /*                                                                    */
  206. /**********************************************************************/
  207. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  208. HWND hWnd;
  209. UINT message;
  210. WPARAM wParam;
  211. LPARAM lParam;
  212. {
  213.     PAINTSTRUCT ps;
  214.     HDC  hDC;
  215.     FARPROC lpProc;
  216.     RECT rc;
  217.     int iDesc = 0;
  218.     HDC hIC;
  219.     TEXTMETRIC tm;
  220.     HFONT hFont;
  221.     HFONT hOldFont;
  222.     HIMC hIMC;
  223.     HWND hIMEWnd;
  224.     char szDesc[128];
  225.  
  226.     switch (message) {
  227.     case WM_CREATE:
  228.         break;
  229.  
  230.     case WM_SIZE:
  231.             switch (wParam)
  232.             {
  233.                 case SIZENORMAL:
  234.                 case SIZEFULLSCREEN:
  235.                     GetClientRect(hWndMain,&rc);
  236.                     rc.right  /= 2;
  237.                     rc.bottom /= 3;
  238.  
  239.                     hFont = GetDefaultGUIFont();
  240.                     hIC = CreateIC("DISPLAY", NULL, NULL, NULL);
  241.  
  242.                     SelectObject(hIC, hFont);
  243.  
  244.                     GetTextMetrics(hIC,&tm);
  245.  
  246.                     iDesc = 0;
  247.                     if (rc.bottom >= tm.tmHeight)
  248.                         iDesc = tm.tmHeight + tm.tmExternalLeading;
  249.  
  250.                     DeleteDC(hIC);
  251.  
  252.                     MoveWindow(hWndDef1,
  253.                                rc.left,rc.top + iDesc,
  254.                                rc.right,rc.bottom - iDesc,TRUE);
  255.                     MoveWindow(hWndDef2,
  256.                                rc.right,rc.top + iDesc,
  257.                                rc.right,rc.bottom - iDesc,TRUE);
  258.                     MoveWindow(hWndIMC1,
  259.                                rc.left,rc.bottom + iDesc,
  260.                                rc.right,rc.bottom - iDesc,TRUE);
  261.                     MoveWindow(hWndIMC2,
  262.                                rc.right,rc.bottom + iDesc,
  263.                                rc.right,rc.bottom - iDesc,TRUE);
  264.                     MoveWindow(hWndIMCUI1,
  265.                                rc.left,rc.bottom * 2 + iDesc,
  266.                                rc.right,rc.bottom - iDesc,TRUE);
  267.                     MoveWindow(hWndIMCUI2,
  268.                                rc.right,rc.bottom * 2 + iDesc,
  269.                                rc.right,rc.bottom - iDesc,TRUE);
  270.  
  271.                     InvalidateRect(hWnd,NULL,TRUE);
  272.                     break;
  273.  
  274.                 case SIZEICONIC:
  275.                 return (DefWindowProc(hWnd, message, wParam, lParam));
  276.                     break;
  277.            
  278.             }
  279.         break;
  280.  
  281.     case WM_PAINT:
  282.         hDC = BeginPaint (hWnd, &ps);
  283.             hFont = GetDefaultGUIFont();
  284.             hOldFont = SelectObject(hDC, hFont);
  285.  
  286.             GetClientRect(hWndMain,&rc);
  287.             rc.right  /= 2;
  288.             rc.bottom /= 3;
  289.  
  290.             wsprintf(szDesc,"%08lX Default IMC and Default IME window"
  291.                      ,(DWORD)hWndDef1);
  292.             TextOut(hDC, rc.left,rc.top,szDesc,lstrlen(szDesc));
  293.  
  294.             wsprintf(szDesc,"%08lX Default IMC and Default IME window"
  295.                      ,(DWORD)hWndDef2);
  296.             TextOut(hDC, rc.right,rc.top,szDesc,lstrlen(szDesc));
  297.  
  298.             hIMC = (HIMC)GetWindowLong(hWndIMC1,MYGWL_IMC);
  299.             wsprintf(szDesc,"%08lX IMC[%08lX] and Default IME window"
  300.                      ,(DWORD)hWndIMC1, (DWORD)hIMC);
  301.             TextOut(hDC, rc.left,rc.bottom,szDesc,lstrlen(szDesc));
  302.  
  303.             hIMC = (HIMC)GetWindowLong(hWndIMC2,MYGWL_IMC);
  304.             wsprintf(szDesc,"%08lX IMC[%08lX] and Default IME window"
  305.                      ,(DWORD)hWndIMC2, (DWORD)hIMC);
  306.             TextOut(hDC, rc.right,rc.bottom,szDesc,lstrlen(szDesc));
  307.  
  308.             hIMC = (HIMC)GetWindowLong(hWndIMCUI1,MYGWL_IMC);
  309.             hIMEWnd = (HWND)GetWindowLong(hWndIMCUI1,MYGWL_IMEWND);
  310.             wsprintf(szDesc,"%08lX IMC[%08lX] and IME window[%08lX]"
  311.                      ,(DWORD)hWndIMCUI1, (DWORD)hIMC ,(DWORD)hIMEWnd);
  312.             TextOut(hDC, rc.left,rc.bottom * 2,szDesc,lstrlen(szDesc));
  313.  
  314.             hIMC = (HIMC)GetWindowLong(hWndIMCUI2,MYGWL_IMC);
  315.             hIMEWnd = (HWND)GetWindowLong(hWndIMCUI2,MYGWL_IMEWND);
  316.             wsprintf(szDesc,"%08lX IMC[%08lX] and IME window[%08lX]"
  317.                      ,(DWORD)hWndIMCUI2, (DWORD)hIMC ,(DWORD)hIMEWnd);
  318.             TextOut(hDC, rc.right,rc.bottom * 2,szDesc,lstrlen(szDesc));
  319.  
  320.             SelectObject(hDC, hOldFont);
  321.         EndPaint (hWnd, &ps);
  322.         break;
  323.  
  324.     case WM_COMMAND:
  325.         switch(WMCOMMANDWPARAM(wParam))
  326.         {
  327.         case IDM_ABOUT:
  328.             lpProc = MakeProcInstance(AboutDlg, hInst);
  329.             DialogBox(hInst, "ABOUTBOX", hWnd, (DLGPROC)lpProc);
  330.             FreeProcInstance(lpProc);
  331.             break;
  332.  
  333.         }
  334.         break;
  335.  
  336.     case WM_DESTROY:
  337.         PostQuitMessage(0);
  338.         break;
  339.  
  340.     default:
  341.         return (DefWindowProc(hWnd, message, wParam, lParam));
  342.     }
  343.     return 0L;
  344. }
  345.  
  346.