home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 August
/
VPR9708A.ISO
/
OLS
/
WIN32
/
Comwp362
/
COMWP362.LZH
/
SAMPLES.LZH
/
SAMPLE2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-25
|
6KB
|
220 lines
/*--------------------*
* デバッグ端末使用例 *
*--------------------*
*/
//#define UNICODE
//#define _UNICODE
#include <windows.h>
#include <tchar.h>
#include <string.h>
#include "comwin.h"
#if !defined(UNICODE)
#define LPTSTR LPSTR
#else
#define cwFputs cwFputsW
#define cwFprintf cwFprintfW
LONG FAR PASCAL cwFprintfW( LPVOID lpFile, LPTSTR lpFormat, ... )
{
HGLOBAL hStr;
LPTSTR lpStr;
va_list argptr;
LONG lRet;
hStr = GlobalAlloc(GMEM_MOVEABLE, 0x400 * sizeof(TCHAR));
lpStr = GlobalLock(hStr);
if (lpStr == NULL) {
return -1;
}
va_start(argptr, lpFormat);
_vsntprintf(lpStr, 0x400 - 1, lpFormat, argptr);
va_end(argptr);
lRet = cwFputs(lpStr, lpFile);
GlobalUnlock(hStr);
GlobalFree(hStr);
return lRet;
}
#endif
LONG FAR PASCAL WndProc(HWND, UINT, WPARAM, LPARAM);
LONG FAR PASCAL WndProcW(HWND, UINT, WPARAM, LPARAM);
int WmPaintProc(HWND, WPARAM, LPARAM);
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdParam,
int nCmdShow)
{
static TCHAR szAppName[] = _TEXT("Sample2");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
if (!hPrevInstance) {
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
}
hwnd = CreateWindow(
szAppName, _TEXT("Sample2 for ComWin"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
SetTimer(hwnd, 1, 5000, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam ;
}
LONG FAR PASCAL WndProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
#if !defined(WIN32)
static TCHAR szFormat[] = _TEXT("%04X:%08lX:%s\n");
#else
static TCHAR szFormat[] = _TEXT("%08lX:%08lX:%s\n");
#endif
switch (uMsg) {
case WM_ACTIVATE:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_ACTIVATE"));
break;
case WM_CHAR:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_CHAR"));
break;
case WM_CLOSE:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_CLOSE"));
break;
case WM_CREATE:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_CREATE"));
break;
case WM_DESTROY:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_DESTROY"));
PostQuitMessage(0);
break;
case WM_KEYDOWN:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_KEYDOWN"));
break;
case WM_KEYUP:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_KEYUP"));
break;
case WM_KILLFOCUS:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_KILLFOCUS"));
break;
case WM_LBUTTONDOWN:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_LBUTTONDOWN"));
break;
case WM_PAINT:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_PAINT"));
WmPaintProc(hwnd, wParam, lParam);
break;
case WM_RBUTTONDOWN:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_RBUTTONDOWN"));
break;
case WM_SETFOCUS:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_SETFOCUS"));
break;
case WM_SIZE:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_SIZE"));
break;
case WM_SYSCOMMAND:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_SYSCOMMAND"));
break;
case WM_TIMER:
cwFprintf(NULL, szFormat, wParam, lParam,
(LPTSTR)_TEXT("WM_TIMER"));
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int WmPaintProc(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
HFONT hFont, hFontOld;
LOGFONT lf;
hdc = BeginPaint(hwnd, &ps);
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
memset(&lf, 0, sizeof(lf));
lstrcpy(lf.lfFaceName, _TEXT("Times New Roman"));
lf.lfHeight = -24;
lf.lfItalic = 1;
lf.lfWeight = FW_BOLD;
lf.lfUnderline = 1;
hFont = CreateFontIndirect(&lf);
hFontOld = SelectObject(hdc, hFont);
GetClientRect(hwnd, &rc);
DrawText(hdc, _TEXT("ComWin ver 3.62"), -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
SelectObject(hdc, hFontOld);
DeleteObject(hFont);
EndPaint(hwnd, &ps);
return 0;
}