📄 ugmessagewindowuse.c
字号:
/*----------------------------------------------------------------------------- File: UgMessageWindowUse.c Description: ProTK doc code sample PTC File Date Version Author Vers Comment--------- ------- -------- ----- ---------------------------------------------04-dec-97 H-02-02 CHI $$1 Setup.22-mar-00 J-01-04 JCN $$2 Update to latest UG code & correct.25-apr-00 J-01-07 JCN $$3 Add X-ref comment.-----------------------------------------------------------------------------*//*----------------------------------------------------------------------------- NOTE TO QA: Functionality shown in this file is tested in PTestMessages.c in pt_tests application. -----------------------------------------------------------------------------*/#include <ProToolkit.h>#include <ProMessage.h>#include <TestError.h>#define MAX_IN_LEN PRO_NAME_SIZE/*==================================================================*\FUNCTION: UserMessageDemo()PURPOSE: Display messages and read user input.\*==================================================================*/ProError UserMessageDemo(){ int i1, i2; const int default_int = 0; double d; int irange[2] = {0, 10}; ProName wstr, default_wstr; ProCharName str; ProLine msg_line; ProCharLine line; ProError err; ProFileName msgfil; FILE *msg_test;/*------------------------------------------------------------------*\ Set up the name of the message file.\*------------------------------------------------------------------*/ ProStringToWstring (msgfil, "msg_ugmessage.txt");/*------------------------------------------------------------------*\ Read an integer without a default value. Message will display as a prompt.\*------------------------------------------------------------------*/ err = ProMessageDisplay (msgfil, "USER Enter any integer: "); err = ProMessageIntegerRead (NULL, &i1); if (err != PRO_TK_NO_ERROR) return (err);/*------------------------------------------------------------------*\ Read an integer with a restricted range and a default value. Message will display as a prompt.\*------------------------------------------------------------------*/ err = ProMessageDisplay (msgfil, "USER Enter any integer between %0d and %1d: |||%2d", &irange[0], &irange[1], &default_int); err = ProMessageIntegerRead (irange, &i2); if (err != PRO_TK_NO_ERROR && err != PRO_TK_GENERAL_ERROR) return (err);/*------------------------------------------------------------------*\ If user entered the default value - warn the user. Message will display as a warning.\*------------------------------------------------------------------*/ if (err == PRO_TK_GENERAL_ERROR) { i2 = default_int; /* Using the default */ err = ProMessageDisplay (msgfil, "USER Warning: using default value", &default_int); }/*------------------------------------------------------------------*\ Read a double without a default value. Message will display as a prompt.\*------------------------------------------------------------------*/ err = ProMessageDisplay (msgfil, "USER Enter any double: "); err = ProMessageDoubleRead (NULL, &d); if (err != PRO_TK_NO_ERROR) return (err);/*------------------------------------------------------------------*\ Read a string with a default value. Message will display as a prompt.\*------------------------------------------------------------------*/ ProStringToWstring (default_wstr, "default string"); err = ProMessageDisplay (msgfil, "USER Enter any string: |||%0w", default_wstr); err = ProMessageStringRead (MAX_IN_LEN, wstr); if (err != PRO_TK_NO_ERROR && err != PRO_TK_GENERAL_ERROR) return (err); if (err == PRO_TK_GENERAL_ERROR) ProUtilWstrcpy (wstr, default_wstr); /* Using the default *//*------------------------------------------------------------------*\ Write a message that states the values entered. Message will display as info.\*------------------------------------------------------------------*/ err = ProMessageDisplay (msgfil, "USER Values entered were %0d, %1d, %2(5.3)f, %3w", &i1, &i2, &d, wstr);/*------------------------------------------------------------------*\ Write the values to a file.\*------------------------------------------------------------------*/ msg_test = fopen ("msg_test.dat", "w"); if (msg_test != NULL) { err = ProMessageToBuffer (msg_line, msgfil, "USER Values entered", wstr, &d, &i2, &i1); ProWstringToString (line, msg_line); fprintf (msg_test, "ProMessageToBuffer output |%s|\n", line); fclose (msg_test); } return (PRO_TK_NO_ERROR);}#undef MAX_IN_LEN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -