home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 February / VPR9602A.ISO / fwindows / comwp260 / samples / sample2.c < prev    next >
C/C++ Source or Header  |  1995-10-09  |  4KB  |  154 lines

  1. /*--------------------*
  2.  * デバッグ端末使用例 *
  3.  *--------------------*
  4.  */
  5. #include <windows.h>
  6. #include <string.h>
  7. #include "comwin.h"
  8.  
  9. LONG FAR PASCAL WndProc (HWND, UINT, WPARAM, LPARAM);
  10. int WmPaintProc(HWND, WPARAM, LPARAM);
  11.  
  12. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  13.                    LPSTR lpszCmdParam, int nCmdShow)
  14. {
  15.     static char szAppName[] = "Sample2";
  16.     HWND        hwnd;
  17.     MSG         msg;
  18.     WNDCLASS    wndclass;
  19.  
  20.     if (!hPrevInstance) {
  21.         wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  22.         wndclass.lpfnWndProc   = WndProc;
  23.         wndclass.cbClsExtra    = 0;
  24.         wndclass.cbWndExtra    = 0;
  25.         wndclass.hInstance     = hInstance;
  26.         wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  27.         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  28.         wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  29.         wndclass.lpszMenuName  = NULL;
  30.         wndclass.lpszClassName = szAppName;
  31.  
  32.         RegisterClass(&wndclass);
  33.     }
  34.  
  35.     hwnd = CreateWindow(
  36.                 szAppName, "Sample2 for ComWin",
  37.                 WS_OVERLAPPEDWINDOW,
  38.                 CW_USEDEFAULT, CW_USEDEFAULT,
  39.                 CW_USEDEFAULT, CW_USEDEFAULT,
  40.                 NULL, NULL, hInstance, NULL);
  41.  
  42.     SetTimer(hwnd, 1, 5000, NULL);
  43.     ShowWindow(hwnd, nCmdShow);
  44.     UpdateWindow(hwnd);
  45.  
  46.     while (GetMessage (&msg, NULL, 0, 0)) {
  47.         TranslateMessage (&msg);
  48.         DispatchMessage (&msg);
  49.     }
  50.     return msg.wParam ;
  51. }
  52.  
  53. LONG FAR PASCAL WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  54. {
  55.  
  56. #if !defined(WIN32)
  57.     static char szFormat[] = "%04X:%08lX:%s\n";
  58. #else
  59.     static char szFormat[] = "%08lX:%08lX:%s\n";
  60. #endif
  61.  
  62.     switch (message) {
  63.         case WM_ACTIVATE:
  64.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_ACTIVATE");
  65.             break;
  66.  
  67.         case WM_CHAR:
  68.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_CHAR");
  69.             break;
  70.  
  71.         case WM_CLOSE:
  72.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_CLOSE");
  73.             break;
  74.  
  75.         case WM_CREATE:
  76.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_CREATE");
  77.             break;
  78.  
  79.         case WM_DESTROY:
  80.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_DESTROY");
  81.             PostQuitMessage(0);
  82.             return 0;
  83.  
  84.         case WM_KEYDOWN:
  85.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_KEYDOWN");
  86.             break;
  87.  
  88.         case WM_KEYUP:
  89.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_KEYUP");
  90.             break;
  91.  
  92.         case WM_KILLFOCUS:
  93.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_KILLFOCUS");
  94.             break;
  95.  
  96.         case WM_PAINT:
  97.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_PAINT");
  98.             WmPaintProc(hwnd, wParam, lParam);
  99.             break;
  100.  
  101.         case WM_SETFOCUS:
  102.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_SETFOCUS");
  103.             break;
  104.  
  105.         case WM_SIZE:
  106.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_SIZE");
  107.             break;
  108.  
  109.         case WM_SYSCOMMAND:
  110.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_SYSCOMMAND");
  111.             break;
  112.  
  113.         case WM_TIMER:
  114.             cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_TIMER");
  115.             break;
  116.  
  117.     }
  118.     return DefWindowProc(hwnd, message, wParam, lParam);
  119. }
  120.  
  121. int WmPaintProc(HWND hwnd, WPARAM wParam, LPARAM lParam)
  122. {
  123.     HDC         hdc;
  124.     PAINTSTRUCT ps;
  125.     RECT        rc;
  126.     HFONT       hFont, hFontOld;
  127.     LOGFONT     lf;
  128.  
  129.     hdc = BeginPaint(hwnd, &ps);
  130.  
  131.     SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
  132.     SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
  133.  
  134.     memset(&lf, 0, sizeof(lf));
  135.     lstrcpy(lf.lfFaceName, "Times New Roman");
  136.     lf.lfHeight = -24;
  137.     lf.lfItalic = 1;
  138.     lf.lfWeight = FW_BOLD;
  139.     lf.lfUnderline = 1;
  140.     hFont    = CreateFontIndirect(&lf);
  141.     hFontOld = SelectObject(hdc, hFont);
  142.  
  143.     GetClientRect(hwnd, &rc);
  144.  
  145.     DrawText(hdc, "ComWin ver 2.60", -1, &rc,
  146.                     DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  147.  
  148.     SelectObject(hdc, hFontOld);
  149.     DeleteObject(hFont);
  150.  
  151.     EndPaint(hwnd, &ps);
  152.     return 0;
  153. }
  154.