/* TPWinCrt window creation, shutdown callback, and Pascal unit startup. */ #include "tdkpin_tpwincrt_lifecycle.h" #include "tdkpin_borland_files.h" enum { DGROUP_TPWINCRT_TITLE = 0x4a6e, DGROUP_TPWINCRT_INPUT_RECORD = 0x4b38, DGROUP_TPWINCRT_OUTPUT_RECORD = 0x4c38, TPWINCRT_APPLICATION_ICON = 0x7f00, TPWINCRT_WINDOW_STYLE = 0x00ff0000, TPWINCRT_SC_CLOSE = 0xf060, }; /* 1008:2442 -- lazily create, show, and update the process TPWinCrt window. */ void tpwincrt_create_window(void) { if (g_tpwincrt_window_created != 0) { return; } g_tpwincrt_window = CreateWindow16( g_tpwincrt_window_class.class_name, win16_dgroup_pointer(DGROUP_TPWINCRT_TITLE), TPWINCRT_WINDOW_STYLE, g_tpwincrt_initial_x, g_tpwincrt_initial_y, g_tpwincrt_initial_width, g_tpwincrt_initial_height, 0, 0, g_win16_instance, 0); (void)ShowWindow16(g_tpwincrt_window, (INT16)g_win16_show_command); (void)UpdateWindow16(g_tpwincrt_window); } /* * 1008:24a5 -- TPWinCrt ExitProc. Restore the predecessor before doing any * work so Borland's mutable ExitProc walker can continue the chain. A clean * exit with a live window changes the caption to "(Inactive %s)", re-enables * Close, disables Ctrl-C checking, and runs a final blocking message loop. */ void tpwincrt_shutdown_exit_proc(void) { g_borland_exit_proc = g_tpwincrt_saved_exit_proc; if (g_tpwincrt_window_created == 0 || g_borland_error_offset != 0 || g_borland_error_segment != 0) { return; } uint16_t arguments[2] = { win16_far_offset(win16_dgroup_pointer(DGROUP_TPWINCRT_TITLE)), win16_far_selector(win16_dgroup_pointer(DGROUP_TPWINCRT_TITLE)), }; char inactive_title[128]; (void)wvsprintf16( inactive_title, g_tpwincrt_inactive_format, arguments); (void)SetWindowText16(g_tpwincrt_window, inactive_title); HMENU16 system_menu = GetSystemMenu16(g_tpwincrt_window, 0); (void)EnableMenuItem16(system_menu, TPWINCRT_SC_CLOSE, 0); g_tpwincrt_break_check_enabled = 0; MSG16 message; while (GetMessage16(&message, 0, 0, 0) != 0) { (void)TranslateMessage16(&message); (void)DispatchMessage16(&message); } } /* * 1008:2554 -- initialize TPWinCrt's class, standard TextRec pair, title, and * ExitProc link. Class registration occurs only for the first Win16 instance. */ void tpwincrt_initialize_runtime_unit(void) { if (g_win16_previous_instance == 0) { g_tpwincrt_window_class.instance = g_win16_instance; g_tpwincrt_window_class.icon = LoadIcon16( 0, win16_make_far_pointer(0, TPWINCRT_APPLICATION_ICON)); g_tpwincrt_window_class.cursor = LoadCursor16( 0, win16_make_far_pointer(0, TPWINCRT_APPLICATION_ICON)); g_tpwincrt_window_class.background_brush = 6; (void)RegisterClass16(&g_tpwincrt_window_class); } Win16FarPtr input_record = win16_dgroup_pointer(DGROUP_TPWINCRT_INPUT_RECORD); tpwincrt_initialize_text_record(input_record); borland_reset_file(input_record); borland_require_io_success(); Win16FarPtr output_record = win16_dgroup_pointer(DGROUP_TPWINCRT_OUTPUT_RECORD); tpwincrt_initialize_text_record(output_record); borland_rewrite_file(output_record); borland_require_io_success(); Win16FarPtr title = win16_dgroup_pointer(DGROUP_TPWINCRT_TITLE); (void)GetModuleFileNameFar16(g_win16_instance, title, 0x50); (void)OemToAnsi16(title, title); g_tpwincrt_saved_exit_proc = g_borland_exit_proc; g_borland_exit_proc = win16_relocated_code_pointer(2, 0x24a5); }