home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1998 March
/
VPR9803A.ISO
/
OLS
/
Windows
/
WBAT137P
/
wbat137p.lzh
/
SAMPLE
/
WBAPISMP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-18
|
6KB
|
203 lines
// apismp.c Sample Program for WinBatchEh API 2.02
// (Borland C/C++ 4.52)
#define STRICT
#include <windows.h>
#pragma hdrstop
#include <windowsx.h>
// #include <stdarg.h>
#include "wbatapi.h"
#define BUF_SIZE 8192 // 文字列受け渡しに使うバッファのサイズ
HWND hwnd; // カレントアクティブウィンドウのHWND
void msgbox0(unsigned char *msg)
{
MessageBox(hwnd, msg, "APISMP", MB_OK);
}
/*
void msgbox2(void *s, ...)
{
unsigned char p[512];
va_list ap;
va_start(ap, s);
wvsprintf(p, s, ap);
va_end(ap);
msgbox0(p);
}
*/
#pragma argsused
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmd, int cmdShow)
{
int i;
LRESULT result; // リターンなどを受け取る
HWND bhwnd; // WinBatchEhExecのHWND
unsigned char work[1024]; // ワークバッファ
unsigned char far *buf; // 受け渡しのバッファの物理ポインタ
unsigned char str_wbshell[]="WinBatchEhShell"; // WinBatchEhのクラス名
#ifndef __WIN32__
HGLOBAL g_buf;
#else
HANDLE g_buf;
HANDLE hf_buf;
DWORD idprocess;
HANDLE hprocess;
#endif
hwnd=GetActiveWindow();
// Windowを見つける処理
#ifndef __WIN32__
if ( (bhwnd=FindWindow(str_wbshell,
"WinBatchEhShell - APISMP16.EXE")) == NULL && // for OLD Ver
(bhwnd=FindWindow(str_wbshell,
"WinBatchEhShell - APISMP16")) == NULL ) {
#else
if ( (bhwnd=FindWindow(str_wbshell,
"WinBatchEhShell - APISMP32.EXE")) == NULL && // for OLD Ver
(bhwnd=FindWindow(str_wbshell,
"WinBatchEhShell - APISMP32")) == NULL ) {
#endif
MessageBox(hwnd, "WinBatchEh上ではありません", "APISMP", MB_OK);
return NULL;
}
// 別のWinBatchEhが動作しているときの為にウィンドウタイトルを変更しておく
SetWindowText(bhwnd, "");
if ( ( SendMessage(bhwnd, WM_WB_GETVER, 0, 0L) & 0xff00 )
!= ( WINBAT_API_VER & 0xff00 ) ) {
msgbox0("バージョンエラー");
return NULL;
}
#ifndef __WIN32__
if ( (g_buf=GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, BUF_SIZE)) == NULL ) {
msgbox0("メモリ不足(1)");
return NULL;
}
if ( (buf=GlobalLock(g_buf)) == NULL ) {
msgbox0("メモリ不足(2)");
return NULL;
}
#else
if ( (hf_buf=CreateFileMapping((HANDLE)0xFFFFFFFF, NULL,
PAGE_READWRITE, 0, (DWORD)BUF_SIZE ,NULL)) == NULL ) {
msgbox0("メモリ不足(1)");
return NULL;
}
if ( (buf=MapViewOfFile(hf_buf, FILE_MAP_ALL_ACCESS, 0, 0, 0)) == NULL ) {
msgbox0("メモリ不足(2)");
CloseHandle(hf_buf);
return NULL;
}
GetWindowThreadProcessId(bhwnd, &idprocess);
hprocess=OpenProcess(PROCESS_DUP_HANDLE, TRUE, idprocess);
DuplicateHandle( GetCurrentProcess(), hf_buf, hprocess, &g_buf,
0, TRUE, DUPLICATE_SAME_ACCESS );
#endif
// WM_WB_PUTCHAR
for ( i=0 ; i<79 ; i++ ) {
SendMessage(bhwnd, WM_WB_PUTCHAR, (WPARAM)'S', (LPARAM)0);
}
SendMessage(bhwnd, WM_WB_PUTCHAR, (WPARAM)0x0a, (LPARAM)0);
// WM_WB_ERRPUTCHAR
for ( i=0 ; i<79 ; i++ ) {
SendMessage(bhwnd, WM_WB_ERRPUTCHAR, (WPARAM)'E', (LPARAM)0);
}
SendMessage(bhwnd, WM_WB_ERRPUTCHAR, (WPARAM)0x0a, (LPARAM)0);
// WM_WB_PUTSTR
lstrcpy(buf, "APISMPからの出力テストです(STDOUT).\n");
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_ERRPUTSTR
lstrcpy(buf, "再びAPISMPからの出力テストです(ERROUT).\n");
SendMessage(bhwnd, WM_WB_ERRPUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_GETBATNAME
SendMessage(bhwnd, WM_WB_GETBATNAME, (WPARAM)0, (LPARAM)g_buf);
lstrcpy(work, buf);
wsprintf(buf, "バッチファイル名は[%s]です.\n", work);
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_GETNOWLINE, GETBATNOWLINE
result=SendMessage(bhwnd, WM_WB_GETNOWLINE, (WPARAM)0, (LPARAM)0);
SendMessage(bhwnd, WM_WB_GETBATNOWLINE, (WPARAM)0, (LPARAM)g_buf);
lstrcpy(work, buf);
wsprintf(buf, "現在バッチは[%d]行目で内容は[%s]です.\n", (int)result, work);
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_GETBATNUMLINE
SendMessage(bhwnd, WM_WB_GETBATNUMLINE, (WPARAM)0, (LPARAM)g_buf);
lstrcpy(work, buf);
wsprintf(buf, "バッチの1行目の内容は[%s]です.\n", work);
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_SETNOWLINE
lstrcpy(buf, "バッチの現在位置を10行目に設定しました.\n");
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
SendMessage(bhwnd, WM_WB_SETNOWLINE, (WPARAM)9, (LPARAM)0);
// WM_WB_GETERRORLEVEL
result=SendMessage(bhwnd, WM_WB_GETERRORLEVEL, (WPARAM)0, (LPARAM)0);
wsprintf(buf, "ERRORLEVELは[%d]でした.\n", result);
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_SETERRORLEVEL
lstrcpy(buf, "ERRORLEVELを230に設定しました.\n");
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
SendMessage(bhwnd, WM_WB_SETERRORLEVEL, (WPARAM)230, (LPARAM)0);
// WM_WB_GETENV
lstrcpy(buf, "PATH");
SendMessage(bhwnd, WM_WB_GETENV, (WPARAM)0, (LPARAM)g_buf);
lstrcpy(work, buf);
wsprintf(buf, "環境変数 PATH は [%s] に設定されています.\n", work);
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
// WM_WB_PUTENV
lstrcpy(buf, "SETTEST=STRINGS");
if ( SendMessage(bhwnd, WM_WB_PUTENV, (WPARAM)0, (LPARAM)g_buf) == 0 ) {
lstrcpy(buf, "環境変数 SETTEST を [STRINGS] に設定しました.\n");
} else {
lstrcpy(buf, "環境変数 SETTEST を [STRINGS] に設定が失敗しました.\n");
}
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
lstrcpy(buf, "APISMPからのテスト終了.\n");
SendMessage(bhwnd, WM_WB_PUTSTR, (WPARAM)0, (LPARAM)g_buf);
#ifndef __WIN32__
GlobalUnlock(g_buf);
GlobalFree(g_buf);
#else
CloseHandle(hprocess);
UnmapViewOfFile(buf);
CloseHandle(g_buf);
CloseHandle(hf_buf);
#endif
return NULL;
}