⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一个ascii 码值计算原代码的例子
💻 C
📖 第 1 页 / 共 4 页
字号:
					 (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 >= MAIN_MENU_NO_OF_ITEMS) MenuIndex = 0;
					}
					// CODEPAGE edit box
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						ebSelected[CODEPAGE_EB_CODEPAGE] = 0;
						ShowScreenCursor (0);
					}
				}
				else
				{
					MenuClicked = 0;
					MenuIndex++;
					if (MenuIndex >= MAIN_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 vertical menu buttons
				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 = 0; MenuSelected = 0;
					}
				}
				if ( (ir.Event.MouseEvent.dwMousePosition.X >= hX) &&
					 (ir.Event.MouseEvent.dwMousePosition.X <= hX+30) &&
					 (ir.Event.MouseEvent.dwMousePosition.Y >= PRINT_ASCII_Y+1) &&
					 (ir.Event.MouseEvent.dwMousePosition.Y <= PRINT_ASCII_Y+16) )
				{
					if ( (ASCII) && (ir.Event.MouseEvent.dwMousePosition.X % 2 == 0) )
					{
						Row    = (ir.Event.MouseEvent.dwMousePosition.X - hX) / 2;
						Line   = ir.Event.MouseEvent.dwMousePosition.Y - (hY + 2);
						Result = 16 * Line + Row;
						Print (gbCodePage->x + 2, gbCodePage->y + 11, FRONT_WHITE | BACK_LIGHTGREY, "ASCII code for '%c' is %03d.", Result, Result);
					}
				}
				// CODEPAGE edit box
				if ( (ir.Event.MouseEvent.dwMousePosition.X >= ebX[CODEPAGE_EB_CODEPAGE]) &&
					 (ir.Event.MouseEvent.dwMousePosition.X <= ebX[CODEPAGE_EB_CODEPAGE]+ebLength[CODEPAGE_EB_CODEPAGE]-1) &&
					 (ir.Event.MouseEvent.dwMousePosition.Y == ebY[CODEPAGE_EB_CODEPAGE]) )
				{
					// show screen cursor and select edit box
					ShowScreenCursor (1);
					ebSelected[CODEPAGE_EB_CODEPAGE] = 1;
					// x[CODEPAGE_EB_CODEPAGE] value is equal to the "mouse click" x[CODEPAGE_EB_CODEPAGE] coordinate
					x[CODEPAGE_EB_CODEPAGE] = ir.Event.MouseEvent.dwMousePosition.X;
					GotoXY (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]); // set the screen cursor to the right position
					// ebIndex[CODEPAGE_EB_CODEPAGE] must be between 0 and Edit->Length-1
					ebIndex[CODEPAGE_EB_CODEPAGE] = x[CODEPAGE_EB_CODEPAGE] - ebX[CODEPAGE_EB_CODEPAGE];
				}
				else
				{
					ebSelected[CODEPAGE_EB_CODEPAGE] = 0;
					ShowScreenCursor (0);
				}
			} // end if FROM_LEFT_1ST_BUTTON_PRESSED
		} // end if MOUSE_EVENT
		if ( (MenuSelected) || (ebSelected[CODEPAGE_EB_CODEPAGE]) )
		{
			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;
					// Unselect edit boxes
					ebSelected[CODEPAGE_EB_CODEPAGE] = 0;
					ShowScreenCursor (0);
				}
				// key LEFT_ALT + ('c' or 'C') for codepage edit box
				else if ( ((ir.Event.KeyEvent.wVirtualKeyCode   == 'c') ||
					       (ir.Event.KeyEvent.wVirtualKeyCode   == 'C')) &&
						   (ir.Event.KeyEvent.dwControlKeyState == LEFT_ALT) )
				{
					if (!ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						// menu
						WriteMenu    = 1;
						MarkMenu     = 0;
						MenuSelected = 0;
						// edit box
						ebSelected[CODEPAGE_EB_CODEPAGE] = 1;
						ShowScreenCursor (1);
						// x[CODEPAGE_EB_CODEPAGE] value is equal to the "mouse click" x[CODEPAGE_EB_CODEPAGE] coordinate
						x[CODEPAGE_EB_CODEPAGE] = ebX[CODEPAGE_EB_CODEPAGE];
						GotoXY (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]); // set the screen cursor to the right position
						// ebIndex[CODEPAGE_EB_CODEPAGE] must be between 0 and Edit->Length-1
						ebIndex[CODEPAGE_EB_CODEPAGE] = x[CODEPAGE_EB_CODEPAGE] - ebX[CODEPAGE_EB_CODEPAGE];
					}
				}
				// up arrow key
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_UP)
				{
					if (MenuSelected)
					{
						WriteMenu = 1;
						MarkMenu  = 1;
						MenuTempIndex -= 1;
						MenuClicked = 0;
						if (MenuTempIndex < 0) MenuTempIndex = MAIN_MENU_NO_OF_ITEMS-1;
					}
				}
				// down arrow key
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
				{
					if (MenuSelected)
					{
						WriteMenu = 1;
						MarkMenu  = 1;
						MenuTempIndex += 1;
						MenuClicked = 0;
						if (MenuTempIndex >= MAIN_MENU_NO_OF_ITEMS) MenuTempIndex = 0;
					}
				}
				// left arrow key
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
				{
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						// screen cursor is moving left
						if (ebIndex[CODEPAGE_EB_CODEPAGE] > 0)
						{
							GotoXY (--x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]);
							--ebIndex[CODEPAGE_EB_CODEPAGE];
						}
					}
				}
				// right arrow key
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
				{
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						// screen cursor is moving right
						if (ebIndex[CODEPAGE_EB_CODEPAGE] < ebLength[CODEPAGE_EB_CODEPAGE]-1)
						{
							GotoXY (++x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]);
							++ebIndex[CODEPAGE_EB_CODEPAGE];
						}
					}
				}
				// return and space key
				else if ( (ir.Event.KeyEvent.wVirtualKeyCode == VK_RETURN) ||
					      (ir.Event.KeyEvent.wVirtualKeyCode == VK_SPACE) )
				{
					if (!ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						// if menu item is enabled then continue else do nothing
						if ( (!DisabledItem[MenuTempIndex]) && (!MenuClicked) )
						{
							MainMenuValue = MenuTempIndex;
							MarkMenu = 1;
							MenuClicked = 1;
							if (MainMenuValue == MAIN_MENU_SHOW_ASCII_TABLE)
							{
								CodePage = atol (ebCodePage);
								if ( (CodePage <= 65001) && (CodePage > 0) )
								{
									ASCII = TRUE;
									ASCII_Table (CodePage);
								}
								else
								{
									ASCII = FALSE;
									ErrorMsg ("       Code page must be between 65001 and 0 !!");
								}
							}
							else if (MainMenuValue == MAIN_MENU_HELP)
							{
								// free memory
								for (i = 0; i < MAIN_MENU_NO_OF_ITEMS; i++)
								{
									free (MainMenuItems[i]);
									MainMenuItems[i] = NULL;
									free (MainMenuHelp[i]);
									MainMenuHelp[i] = NULL;
								}
								// help dialog
								HelpDialog ();
								// redraw main menu
								ReDrawMainMenu = TRUE;
							}
							else if (MainMenuValue == MAIN_MENU_AUTHOR)
							{
								// free memory
								for (i = 0; i < MAIN_MENU_NO_OF_ITEMS; i++)
								{
									free (MainMenuItems[i]);
									MainMenuItems[i] = NULL;
									free (MainMenuHelp[i]);
									MainMenuHelp[i] = NULL;
								}
								// author dialog
								AuthorDialog ();
								// redraw main menu
								ReDrawMainMenu = TRUE;
							}
							else if (MainMenuValue == MAIN_MENU_EXIT)
							{
								// free memory
								for (i = 0; i < MAIN_MENU_NO_OF_ITEMS; i++)
								{
									free (MainMenuItems[i]);
									MainMenuItems[i] = NULL;
									free (MainMenuHelp[i]);
									MainMenuHelp[i] = NULL;
								}
								free (gbCodePage);
								gbCodePage = NULL;
								// disable main menu loop and exit the program
								MainMenuLoop = FALSE;
							}
						}
					}
					if (ir.Event.KeyEvent.wVirtualKeyCode == VK_SPACE)
					{
						if (ebSelected[CODEPAGE_EB_CODEPAGE])
						{
							if (ebIndex[CODEPAGE_EB_CODEPAGE] < ebLength[CODEPAGE_EB_CODEPAGE]) 
							{
								// filling array with the character
								ebCodePage[ebIndex[CODEPAGE_EB_CODEPAGE]] = (char) ir.Event.KeyEvent.uChar.AsciiChar;
								// printing character on the screen
								SetColor (ebColor[CODEPAGE_EB_CODEPAGE]);
								GotoXY (x[CODEPAGE_EB_CODEPAGE]++, ebY[CODEPAGE_EB_CODEPAGE]);
								putchar (ebCodePage[ebIndex[CODEPAGE_EB_CODEPAGE]++]);
							}
							ebCodePage[ebLength[CODEPAGE_EB_CODEPAGE]] = '\0';
						}
					}
				} // end if key return or space was pressed
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_BACK) // backspace key
				{
					if ( (ebIndex[CODEPAGE_EB_CODEPAGE] > 0) && (ebSelected[CODEPAGE_EB_CODEPAGE]) )
					{
						Print (--x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE], ebColor[CODEPAGE_EB_CODEPAGE], " ");
						GotoXY (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]);
						ebCodePage[--ebIndex[CODEPAGE_EB_CODEPAGE]] = ' ';
					}
				}
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_HOME) // home key
				{
					// move screen cursor to the start of the EDIT component only if the edit box is selected
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						x[CODEPAGE_EB_CODEPAGE] = ebX[CODEPAGE_EB_CODEPAGE];
						GotoXY (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]);
						ebIndex[CODEPAGE_EB_CODEPAGE] = 0;
					}
				}
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_END) // end key
				{
					// move screen cursor to the end of the EDIT component only if the edit box is selected
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						x[CODEPAGE_EB_CODEPAGE] = ebX[CODEPAGE_EB_CODEPAGE]+ebLength[CODEPAGE_EB_CODEPAGE]-1;
						GotoXY (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]);
						ebIndex[CODEPAGE_EB_CODEPAGE] = ebLength[CODEPAGE_EB_CODEPAGE]-1;
					}
				}
				else if (ir.Event.KeyEvent.wVirtualKeyCode == VK_DELETE) // delete key
				{
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						ebCodePage[ebIndex[CODEPAGE_EB_CODEPAGE]] = ' ';
						Print (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE], ebColor[CODEPAGE_EB_CODEPAGE], "%c", ebCodePage[ebIndex[CODEPAGE_EB_CODEPAGE]]);
					}
				}
				else if ( (ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
				          (ir.Event.KeyEvent.wVirtualKeyCode == VK_UP) ||
					      (ir.Event.KeyEvent.wVirtualKeyCode == VK_DOWN) ||
						  (ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
						  (ir.Event.KeyEvent.dwControlKeyState == LEFT_ALT) )
				{
					// do nothing !!
				}
				else
				{
					if (ebSelected[CODEPAGE_EB_CODEPAGE])
					{
						// only accept numbers
						if ( (ir.Event.KeyEvent.uChar.AsciiChar >= '0') && (ir.Event.KeyEvent.uChar.AsciiChar <= '9') )
						{
							if (ebIndex[CODEPAGE_EB_CODEPAGE] < ebLength[CODEPAGE_EB_CODEPAGE]) 
							{
								// filling array with the character
								ebCodePage[ebIndex[CODEPAGE_EB_CODEPAGE]] = (char) ir.Event.KeyEvent.uChar.AsciiChar;
								// printing character on the screen
								SetColor (ebColor[CODEPAGE_EB_CODEPAGE]);
								GotoXY (x[CODEPAGE_EB_CODEPAGE]++, ebY[CODEPAGE_EB_CODEPAGE]);
								putchar (ebCodePage[ebIndex[CODEPAGE_EB_CODEPAGE]++]);
							}
							ebCodePage[ebLength[CODEPAGE_EB_CODEPAGE]] = '\0';
						}
					}
				}
			} // end if keyboard
		}
		else // end if MenuSelected
		{
			if ( (ShowHelp) && (HelpIsDisplayed) )
			{
				Print (HELP_X, HELP_Y, HelpColor, "Press F10 for menu.                                                          ");
				HelpIsDisplayed = FALSE;
			}
			// key F10 is available only when the menu is unselected
			if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
			{
				// key F10
				if (ir.Event.KeyEvent.wVirtualKeyCode == VK_F10)
				{
					MenuSelected = 1;
					WriteMenu = 1;
					MarkMenu = 1;
					MenuClicked = 0;
					// edit box
					ebSelected[CODEPAGE_EB_CODEPAGE] = 0;
					ShowScreenCursor (0);
				}
				// key LEFT_ALT + ('c' or 'C') for file name edit box
				else if ( ((ir.Event.KeyEvent.wVirtualKeyCode   == 'c') ||
					       (ir.Event.KeyEvent.wVirtualKeyCode   == 'C')) &&
						   (ir.Event.KeyEvent.dwControlKeyState == LEFT_ALT) )
				{
					// menu
					WriteMenu    = 1;
					MenuSelected = 0;
					// edit box
					ebSelected[CODEPAGE_EB_CODEPAGE] = 1;
					ShowScreenCursor (1);
					// x[CODEPAGE_EB_CODEPAGE] value is equal to the "mouse click" x[CODEPAGE_EB_CODEPAGE] coordinate
					x[CODEPAGE_EB_CODEPAGE] = ebX[CODEPAGE_EB_CODEPAGE];
					GotoXY (x[CODEPAGE_EB_CODEPAGE], ebY[CODEPAGE_EB_CODEPAGE]); // set the screen cursor to the right position
					// ebIndex[CODEPAGE_EB_CODEPAGE] must be between 0 and Edit->Length-1
					ebIndex[CODEPAGE_EB_CODEPAGE] = x[CODEPAGE_EB_CODEPAGE] - ebX[CODEPAGE_EB_CODEPAGE];
				}
			}
		}
		if (WriteMenu)
		{
			for (i = 0; i < MAIN_MENU_NO_OF_ITEMS; i++)
			{
				if (MainMenuItems[i] != NULL)
				{
					if (DisabledItem[i]) Print (xStartMenu[i], yStartMenu[i], DisabledItemColor, "%s", MainMenuItems[i]);
					else Print (xStartMenu[i], yStartMenu[i], ItemColor, "%s", MainMenuItems[i]);
				}
			}
			if (MarkMenu)
			{
				if (MainMenuItems[MenuTempIndex] != NULL)
				{
					if (DisabledItem[MenuTempIndex]) Print (xStartMenu[MenuTempIndex], yStartMenu[MenuTempIndex], DisabledItemHighLightColor, "%s", MainMenuItems[MenuTempIndex]);
					else Print (xStartMenu[MenuTempIndex], yStartMenu[MenuTempIndex], ItemHighLightColor, "%s", MainMenuItems[MenuTempIndex]);
					// print help in the status line
					if (ShowHelp)
					{
						Print (HELP_X, HELP_Y, HelpColor, "%s", MainMenuHelp[MenuTempIndex]);
						HelpIsDisplayed = TRUE;
					}
				}
				MarkMenu = 0;
			}
			WriteMenu = 0;
		}
	} // end of while (MainMenuLoop)
	return 0;
}
/* !! DO NOT REMOVE THIS COMMENT !!
 *
 * Function name:    GotoXY
 * Function version: 1.0
 * Input parameters: - x (short)
 *                   - y (short)
 * Return value:     none
 * Description:      moving screen cursor
 * Example:          GotoXY (0, 0);
 * Limits:           0 <= x <= 78
 *                   0 <= y <= 24
 * Warnings:         If the x value is 79 and y value is 24 and if you're using this function with printf
 *                   function then there will be problems beacuse of the screen cursor. When the character
 *                   is displayed on the screen, then the screen cursor will always automatically move forward
 *                   and beacuse of that the new line will occur and corrupt the output. To avoid this then you
 *                   must use Print function.
 *
 * Updates:
 *   - (!! here you write the updates - do not remove this line !!)
 *
 */
void GotoXY (short x, short y)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -