home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 February
/
VPR9602A.ISO
/
fwindows
/
comwp260
/
samples
/
sample2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-09
|
4KB
|
154 lines
/*--------------------*
* デバッグ端末使用例 *
*--------------------*
*/
#include <windows.h>
#include <string.h>
#include "comwin.h"
LONG FAR PASCAL WndProc (HWND, UINT, WPARAM, LPARAM);
int WmPaintProc(HWND, WPARAM, LPARAM);
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "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, "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 message, WPARAM wParam, LPARAM lParam)
{
#if !defined(WIN32)
static char szFormat[] = "%04X:%08lX:%s\n";
#else
static char szFormat[] = "%08lX:%08lX:%s\n";
#endif
switch (message) {
case WM_ACTIVATE:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_ACTIVATE");
break;
case WM_CHAR:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_CHAR");
break;
case WM_CLOSE:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_CLOSE");
break;
case WM_CREATE:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_CREATE");
break;
case WM_DESTROY:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_DESTROY");
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_KEYDOWN");
break;
case WM_KEYUP:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_KEYUP");
break;
case WM_KILLFOCUS:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_KILLFOCUS");
break;
case WM_PAINT:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_PAINT");
WmPaintProc(hwnd, wParam, lParam);
break;
case WM_SETFOCUS:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_SETFOCUS");
break;
case WM_SIZE:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_SIZE");
break;
case WM_SYSCOMMAND:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_SYSCOMMAND");
break;
case WM_TIMER:
cwFprintf(NULL,szFormat,wParam,lParam,(LPSTR)"WM_TIMER");
break;
}
return DefWindowProc(hwnd, message, 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, "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, "ComWin ver 2.60", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
SelectObject(hdc, hFontOld);
DeleteObject(hFont);
EndPaint(hwnd, &ps);
return 0;
}