// DBエンジンサンプル:読み込み 07/09/98 #include "lxapi.h" #include "dbapi.h" // 文字列 char far *msgAppName = "DB-R1"; char far *msgQuit = "&Quit"; char far *msgNull = ""; char far **StringTable[] = { &msgAppName, &msgQuit, }; // グローバル変数 LHAPIBLOCK LhapiData; EVENT_NORM app_event; BOOL Done; // 関数プロトタイプ void far DoQuit(void); int far MainHandler(PLHWINDOW Wnd, WORD Message, WORD Data, WORD Extra,...); ///////////////////////////////////////////////////////////////////// // // 以下,DBエンジン関連 DBBLOCK dblk; #define MAX_CARD_WNDS 16 char far *SysMgrPtrs[MAX_CARD_WNDS + 27]; char db_filename[30] = "c:\\_dat\\phone.pdb"; //DBファイル名 char filetype = 'D'; //タイプ == GDB char paswd[] = ""; char Name[100] = ""; char Business[100] = ""; void DB_read_record(void); int DB_open_and_setvpt(void); ///////////////////////////////////////////////////////////////////// // ファンクションキー定義 LHFKEY MainFkeys[] = { { (PLHRES)&msgQuit, (PLHFUNC)DoQuit, 1+FKEY_LAST, 0 }, }; // メニュー定義 LHMENU MainMenu[] = { { (PLHRES)&msgQuit, (PLHFUNC)DoQuit, 0, 0, NO_HELP }, { 0, 0, 0, 0} }; // WINDOW 定義 LHWINDOW TDateTime = { DateTime, 0, 0, 0, 0, 0, 0, 0, STYLE_DATETIME | STYLE_NOFOCUS, NULL, NO_FKEYS, NO_MENU, NO_HELP }; LHWINDOW MainTitle = { TitleBar, 0, 0, 0, 0, (PLHRES)&msgAppName, 0, 0, STYLE_NOFOCUS, NULL, NO_FKEYS, (PLHMENU)&TDateTime, NO_HELP }; LHWINDOW MainView = { (PLHCLASS)MainHandler, 0, 0, 640, 200, (PLHRES)&msgNull, 0, 0, 0, NULL, MainFkeys, MainMenu, NO_HELP }; // ハンドラー int far MainHandler(PLHWINDOW Wnd, WORD Message, WORD Data, WORD Extra,...) { switch (Message) { case KEYSTROKE: switch (Data) { case 0x0D: ClearRect(Wnd->x+25, Wnd->y+25, Wnd->w-50, Wnd->h-50); DB_read_record(); DrawText(200, 80, Name, DRAW_NORMAL, FONT_DEFAULT); DrawText(200, 120, Business, DRAW_INVERSE, FONT_DEFAULT); return TRUE; } } return SubclassMsg(Object, Wnd, Message, Data, Extra); } void far DoQuit(void) { Done = TRUE; } int DB_open_and_setvpt(void) { if (DB_Open(&dblk, db_filename, filetype, NULL, paswd, 0, 0) < 0) return FALSE; if (DB_SetCurrentViewpt(&dblk, 0) < 0) { //VIEWPTTABLE set 0 DB_Close(&dblk); return FALSE; } return TRUE; } void DB_read_record(void) { static int no = 0; int len; //実際に読み込まれたレコードの長さ char buf[2048]; //レコード読み込みバッファ if (no < dblk.viewptcount) { DB_ReadRecord(&dblk, TYPE_DATA, (*dblk.viewpt)[no], buf, 2048, &len); DB_GetNamedField(&dblk, buf, "Name", Name, 100); DB_GetNamedField(&dblk, buf, "Business", Business, 100); no++; } else { strcpy(Name, "-- End of Record --"); strcpy(Business, "bye !"); } } void FixupFarPtrs(void) { int i; for (i = 0; i < countof(StringTable); i++) *((int *)StringTable[i] + 1) = _DS; } // メイン void main(void) { InitializeLHAPI(&LhapiData); m_init_app(SYSTEM_MANAGER_VERSION); m_reg_app_name(msgAppName); m_reg_far(&SysMgrPtrs, countof(SysMgrPtrs), 4); // far pointer テーブル準備 m_flush_kb(); SetDefaultFont(FONT_NORMAL); SetMenuFont(FONT_NORMAL); DB_Init(); //DBの初期化 DB_open_and_setvpt(); //DBオープン SendMsg(&MainView, CREATE, CREATE_FOCUS, 0); SendMsg(&MainTitle, CREATE, CREATE_NORMAL, 0); //イベントループ Done = FALSE; while (!Done) { DB_FlushFile(&dblk); // app_event.do_event = DO_EVENT; m_action(&app_event); switch (app_event.kind) { case E_ACTIV: case E_REFRESH: FixupFarPtrs(); DB_Reactivate(&dblk); // ReactivateLHAPI(&LhapiData); break; case E_DEACT: DB_Deactivate(&dblk); // DeactivateLHAPI(); break; case E_TERM: case E_BREAK: FixupFarPtrs(); Done = TRUE; break; case E_NONE: SendMsg(&TDateTime, DRAW, DRAW_ALL, 0); break; case E_KEY: SendFocusMsg(KEYSTROKE, app_event.data, app_event.scan); break; } } DB_Close(&dblk); // app_event.do_event = DO_FINI; m_action(&app_event); } |
Count (05/17/1999) ->
update 05/17/1999, since 07/09/1998(original)
Copyright (c) 1999 by guel. All rights reserved.