?? main.c
字號:
Wait ();
exit (1);
}
// text: Close
if ((ErrMsgMenuItems[0] = (char *) malloc (sizeof (char *) * (strlen ("Close") + 1))) != NULL)
{
strncpy (ErrMsgMenuItems[0], "Close", strlen ("Close") + 1);
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error occured while allocating space for variable");
Print (0, 1, FRONT_LIGHTGREY, "ErrMsgMenuItems[0] in function ErrMsg (file");
Print (0, 2, FRONT_LIGHTGREY, "\"main.c\").");
Print (0, 4, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
// text: Save To File
if ((ErrMsgMenuItems[1] = (char *) malloc (sizeof (char *) * (strlen ("Save To File") + 1))) != NULL)
{
strncpy (ErrMsgMenuItems[1], "Save To File", strlen ("Save To File") + 1);
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error occured while allocating space for variable");
Print (0, 1, FRONT_LIGHTGREY, "ErrMsgMenuItems[1] in function ErrMsg (file");
Print (0, 2, FRONT_LIGHTGREY, "\"main.c\").");
Print (0, 4, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
// text: Exit
if ((ErrMsgMenuItems[2] = (char *) malloc (sizeof (char *) * (strlen ("Exit") + 1))) != NULL)
{
strncpy (ErrMsgMenuItems[2], "Exit", strlen ("Exit") + 1);
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error occured while allocating space for variable");
Print (0, 1, FRONT_LIGHTGREY, "ErrMsgMenuItems[2] in function ErrMsg (file");
Print (0, 2, FRONT_LIGHTGREY, "\"main.c\").");
Print (0, 4, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
// load menu help for each item
// help: ErrMsg & close the dialog.
if ((ErrMsgMenuHelp[0] = (char *) malloc (sizeof (char *) * (strlen ("Closes the dialog.") + 1 + HELP_ERASE_LENGTH))) != NULL)
{
strncpy (ErrMsgMenuHelp[0], "Closes the dialog.", strlen ("Closes the dialog.") + 1 + HELP_ERASE_LENGTH);
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error occured while allocating space for variable");
Print (0, 1, FRONT_LIGHTGREY, "ErrMsgMenuHelp[0] in function ErrMsg (file");
Print (0, 2, FRONT_LIGHTGREY, "\"main.c\").");
Print (0, 4, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
if ((ErrMsgMenuHelp[1] = (char *) malloc (sizeof (char *) * (strlen ("Saves error message into a file \"error.log\" and closes the dialog box.") + 1 + HELP_ERASE_LENGTH))) != NULL)
{
strncpy (ErrMsgMenuHelp[1], "Saves error message into a file \"error.log\" and closes the dialog box.", strlen ("Saves error message into a file \"error.log\" and closes the dialog box.") + 1 + HELP_ERASE_LENGTH);
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error occured while allocating space for variable");
Print (0, 1, FRONT_LIGHTGREY, "ErrMsgMenuHelp[1] in function ErrMsg (file");
Print (0, 2, FRONT_LIGHTGREY, "\"main.c\").");
Print (0, 4, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
if ((ErrMsgMenuHelp[2] = (char *) malloc (sizeof (char *) * (strlen ("Exits the program.") + 1 + HELP_ERASE_LENGTH))) != NULL)
{
strncpy (ErrMsgMenuHelp[2], "Exits the program.", strlen ("Exits the program.") + 1 + HELP_ERASE_LENGTH);
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error occured while allocating space for variable");
Print (0, 1, FRONT_LIGHTGREY, "ErrMsgMenuHelp[2] in function ErrMsg (file");
Print (0, 2, FRONT_LIGHTGREY, "\"main.c\").");
Print (0, 4, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
// with this, before the help gets printed, I can avoid to delete the previous text - very useful
// I don't have to use ClrScr function
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
for (j = 0; j < HELP_ERASE_LENGTH; j++)
{
if (ErrMsgMenuHelp[i][j] == '\0')
{
ErrMsgMenuHelp[i][j] = ' ';
ErrMsgMenuHelp[i][j+1] = '\0';
}
}
}
// calculate load menu coordinates
for (i = 0, xItemNameLength = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
xStartMenu[i] = ERRMSG_MENU_X + xItemNameLength;
xEndMenu[i] = xStartMenu[i] + (short) strlen (ErrMsgMenuItems[i]) - 1;
yStartMenu[i] = ERRMSG_MENU_Y;
xItemNameLength += 0 + (short) strlen (ErrMsgMenuItems[i]);
// do not count the space for the last menu button
if (i != ERRMSG_MENU_NO_OF_ITEMS-1) xItemNameLength += 0 + ERRMSG_MENU_SPACE_BETWEEN_ITEMS;
}
// print ErrMsg menu
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
if (ERRMSG_MENU_DEFAULT_SELECTED == i)
{
// checking if the menu item is disabled. If it is then color it diferently
if (DisabledItem[i]) Print (xStartMenu[i], yStartMenu[i], DisabledItemHighLightColor, "%s", ErrMsgMenuItems[i]);
else Print (xStartMenu[i], yStartMenu[i], ItemHighLightColor, "%s", ErrMsgMenuItems[i]);
MarkMenu = MenuSelected = 1;
// print help in the status line
if (ShowHelp)
{
Print (HELP_X, HELP_Y, HelpColor, "%s", ErrMsgMenuHelp[i]);
HelpIsDisplayed = 1;
}
}
else
{
if (DisabledItem[i]) Print (xStartMenu[i], yStartMenu[i], DisabledItemColor, "%s", ErrMsgMenuItems[i]);
else Print (xStartMenu[i], yStartMenu[i], ItemColor, "%s", ErrMsgMenuItems[i]);
}
}
// print exclamation mark
Print (dbErrMsg->x + 2, dbErrMsg->y + 3, FRONT_WHITE | BACK_LIGHTRED, " ");
Print (dbErrMsg->x + 2, dbErrMsg->y + 4, FRONT_WHITE | BACK_LIGHTRED, " !! ");
Print (dbErrMsg->x + 2, dbErrMsg->y + 5, FRONT_WHITE | BACK_LIGHTRED, " ");
// formating text in a dialog box
MsgCharY = 0;
for (i = 0; i < MsgLength; i++)
{
if (MsgCharCount + dbErrMsg->x + 8 >= dbErrMsg->Length - dbErrMsg->x + 8)
{
Print (dbErrMsg->x + 8 + MsgCharX1, dbErrMsg->y + 5 + MsgCharY, FRONT_LIGHTGREY, "%c", FormattedMessage[i]);
MsgCharX1++;
MsgCharY++;
MsgCharX2 = -1;
MsgCharCount = -1;
}
else Print (dbErrMsg->x+8+MsgCharX2, dbErrMsg->y+4+MsgCharY, FRONT_LIGHTGREY, "%c", FormattedMessage[i]);
MsgCharX2++;
MsgCharCount++;
}
// load main loop
ErrMsgDialogLoop = 1;
while (ErrMsgDialogLoop)
{
ReadConsoleInput (Stdin, &ir, 1, &Read);
dbErrMsg = DialogBoxComponent (dbErrMsg, ir, FALSE);
if (dbErrMsg->ExitIconClicked)
{
// same as Close button
ErrMsgDialogLoop = 0;
// free memory
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
free (ErrMsgMenuItems[i]);
ErrMsgMenuItems[i] = NULL;
free (ErrMsgMenuHelp[i]);
ErrMsgMenuHelp[i] = NULL;
}
free (dbErrMsg);
dbErrMsg = NULL;
}
// mouse
if (ir.EventType == MOUSE_EVENT)
{
if (ir.Event.MouseEvent.dwEventFlags == MOUSE_MOVED)
{
// within the range of a load menu items
if ( (ir.Event.MouseEvent.dwMousePosition.X >= xStartMenu[MenuIndex]) &&
(ir.Event.MouseEvent.dwMousePosition.X <= xEndMenu[MenuIndex]) &&
(ir.Event.MouseEvent.dwMousePosition.Y == yStartMenu[MenuIndex]) )
{
// print the menu button only once
if ( (MenuTempIndex != MenuIndex) || (!MenuSelected) )
{
WriteMenu = 1;
MarkMenu = MenuSelected = 1;
MenuTempIndex = MenuIndex;
MenuIndex++;
if (MenuIndex >= ERRMSG_MENU_NO_OF_ITEMS) MenuIndex = 0;
}
}
else
{
MenuClicked = 0;
// menu
MenuIndex++;
if (MenuIndex >= ERRMSG_MENU_NO_OF_ITEMS) MenuIndex = 0;
}
} // end if MOUSE_MOVED
if (ir.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED) // left mouse click
{
// within the range of a horizontal menu button
if ( (ir.Event.MouseEvent.dwMousePosition.X >= xStartMenu[MenuTempIndex]) &&
(ir.Event.MouseEvent.dwMousePosition.X <= xEndMenu[MenuTempIndex]) &&
(ir.Event.MouseEvent.dwMousePosition.Y == yStartMenu[MenuTempIndex]) )
{
if (!MenuClicked)
{
// simulating key return
keybd_event (VK_RETURN, 0x1c, 0, 0);
keybd_event (VK_RETURN, 0x1c, KEYEVENTF_KEYUP, 0);
}
}
else
{
if (MenuSelected)
{
// menu
WriteMenu = 1; MarkMenu = MenuSelected = 0;
}
}
} // end if FROM_LEFT_1ST_BUTTON_PRESSED
} // end if MOUSE_EVENT
// if component is selected
if (MenuSelected)
{
if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
{
// key F10 for menu
if (ir.Event.KeyEvent.wVirtualKeyCode == VK_F10)
{
// menu
MenuSelected = 1;
WriteMenu = 1;
MarkMenu = 1;
MenuClicked = 0;
}
// left arrow key
else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
{
if (MenuSelected)
{
WriteMenu = 1;
MarkMenu = 1;
MenuTempIndex -= 1;
MenuClicked = 0;
if (MenuTempIndex < 0) MenuTempIndex = ERRMSG_MENU_NO_OF_ITEMS-1;
}
}
// right arrow key
else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
{
if (MenuSelected)
{
WriteMenu = 1;
MarkMenu = 1;
MenuTempIndex += 1;
MenuClicked = 0;
if (MenuTempIndex >= ERRMSG_MENU_NO_OF_ITEMS) MenuTempIndex = 0;
}
}
// return and space key
else if ( (ir.Event.KeyEvent.wVirtualKeyCode == VK_RETURN) ||
(ir.Event.KeyEvent.wVirtualKeyCode == VK_SPACE) )
{
if (!MenuClicked)
{
ErrMsgMenuValue = MenuTempIndex;
if (ErrMsgMenuValue == ERRMSG_MENU_CLOSE)
{
MenuClicked = 1;
MarkMenu = 1;
ErrMsgDialogLoop = 0;
dbErrMsg->Active = 0;
// write previous data back on the screen
WriteDialogBoxData (dbErrMsg->Data, dbErrMsg->x, dbErrMsg->y, dbErrMsg->Length, dbErrMsg->Height);
// free memory
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
free (ErrMsgMenuItems[i]);
ErrMsgMenuItems[i] = NULL;
free (ErrMsgMenuHelp[i]);
ErrMsgMenuHelp[i] = NULL;
}
free (dbErrMsg);
dbErrMsg = NULL;
}
else if (ErrMsgMenuValue == ERRMSG_MENU_SAVETOFILE)
{
MenuClicked = 1;
MarkMenu = 1;
ErrMsgDialogLoop = 0;
dbErrMsg->Active = 0;
// save error message into a file
if ((FileSave = fopen ("error.log", "at+")) != NULL)
{
// allocate space
if ((DateAndTime = (char *) malloc (sizeof (char) * 80)) != NULL)
{
DateAndTime = TimeAndDate ();
fprintf (FileSave, "------------------ Error message generated at %s ------------------\n", DateAndTime);
fprintf (FileSave, "%s\n", FormattedMessage);
fprintf (FileSave, "-------------------------------------------------------------------------------------------------------\n\n");
fclose (FileSave);
free (DateAndTime);
DateAndTime = NULL;
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Error allocating space for variable DateAndTime in function");
Print (0, 1, FRONT_LIGHTGREY, "ErrorMsg (file \"main.c\").");
Print (0, 3, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
}
else
{
Print (0, 0, FRONT_LIGHTGREY, "Can not create file \"error.log\".");
Print (0, 2, FRONT_LIGHTGREY, "Press any key to exit to the system ...");
Wait ();
exit (1);
}
// write previous data back on the screen
WriteDialogBoxData (dbErrMsg->Data, dbErrMsg->x, dbErrMsg->y, dbErrMsg->Length, dbErrMsg->Height);
// free memory
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
free (ErrMsgMenuItems[i]);
ErrMsgMenuItems[i] = NULL;
free (ErrMsgMenuHelp[i]);
ErrMsgMenuHelp[i] = NULL;
}
free (dbErrMsg);
dbErrMsg = NULL;
}
else if (ErrMsgMenuValue == ERRMSG_MENU_EXIT)
{
MenuClicked = 1;
MarkMenu = 1;
ErrMsgDialogLoop = 0;
dbErrMsg->Active = 0;
// write previous data back on the screen
WriteDialogBoxData (dbErrMsg->Data, dbErrMsg->x, dbErrMsg->y, dbErrMsg->Length, dbErrMsg->Height);
// free memory
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
free (ErrMsgMenuItems[i]);
ErrMsgMenuItems[i] = NULL;
free (ErrMsgMenuHelp[i]);
ErrMsgMenuHelp[i] = NULL;
}
free (dbErrMsg);
dbErrMsg = NULL;
exit (1);
}
}
} // end if key return or space was pressed
} // end if keyboard
}
else // end if MenuSelected
{
if ( (ShowHelp) && (HelpIsDisplayed) )
{
Print (HELP_X, HELP_Y, HelpColor, "Press F10 for menu. ");
HelpIsDisplayed = FALSE;
}
// these keys are available only when the component is unselected
if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
{
// key F10 for menu
if (ir.Event.KeyEvent.wVirtualKeyCode == VK_F10)
{
// menu
MenuSelected = 1;
WriteMenu = 1;
MarkMenu = 1;
MenuClicked = 0;
}
} // end if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
} // end if !MenuSelected
// printing menu items
if (WriteMenu)
{
for (i = 0; i < ERRMSG_MENU_NO_OF_ITEMS; i++)
{
if (ErrMsgMenuItems[i] != NULL)
{
if (DisabledItem[i]) Print (xStartMenu[i], yStartMenu[i], DisabledItemColor, "%s", ErrMsgMenuItems[i]);
else Print (xStartMenu[i], yStartMenu[i], ItemColor, "%s", ErrMsgMenuItems[i]);
}
}
if (MarkMenu)
{
if (ErrMsgMenuItems[MenuTempIndex] != NULL)
{
if (DisabledItem[MenuTempIndex]) Print (xStartMenu[MenuTempIndex], yStartMenu[MenuTempIndex], DisabledItemHighLightColor, "%s", ErrMsgMenuItems[MenuTempIndex]);
else Print (xStartMenu[MenuTempIndex], yStartMenu[MenuTempIndex], ItemHighLightColor, "%s", ErrMsgMenuItems[MenuTempIndex]);
// print help in the status line
if (ShowHelp)
{
Print (HELP_X, HELP_Y, HelpColor, "%s", ErrMsgMenuHelp[MenuTempIndex]);
HelpIsDisplayed = 1;
}
}
MarkMenu = 0;
}
WriteMenu = 0;
}
} // end of while (ErrMsgDialogLoop)
}
void Wait ()
{
getch ();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -