Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #define _WIN32_WINNT 0x0601
  2.  
  3. #ifndef UNICODE
  4. #define UNICODE
  5. #define UNICODE_WAS_UNDEFINED
  6. #endif
  7.  
  8. #include <Windows.h>
  9.  
  10. #ifdef UNICODE_WAS_UNDEFINED
  11. #undef UNICODE
  12. #endif
  13.  
  14. #define WHITE_SPACE 9608
  15.  
  16. typedef struct _CONSOLE_FONT_INFOEX
  17. {
  18. ULONG cbSize;
  19. DWORD nFont;
  20. COORD dwFontSize;
  21. UINT FontFamily;
  22. UINT FontWeight;
  23. WCHAR FaceName[LF_FACESIZE];
  24. }CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
  25.  
  26. //the function declaration begins
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsoleOutput,
  31. BOOL bMaximumWindow,
  32. PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
  33. #ifdef __cplusplus
  34. }
  35. #endif
  36. //the function declaration ends
  37.  
  38. void setFontSize(int w, int h)
  39. {
  40. CONSOLE_FONT_INFOEX fontStructure={0};
  41. fontStructure.cbSize=sizeof(fontStructure);
  42. fontStructure.dwFontSize.X=w;
  43. fontStructure.dwFontSize.Y=h;
  44. HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
  45. SetCurrentConsoleFontEx(hConsole, true, &fontStructure);
  46. }
  47.  
  48. const int nScreenWidth = 100, nScreenHeight = 20;
  49. int columns, rows;
  50.  
  51. class Pile
  52. {
  53.  
  54. };
  55.  
  56. int main()
  57. {
  58. //setting correct window size
  59. setFontSize(10, 20);
  60. HWND hwnd = GetConsoleWindow();
  61. MoveWindow(hwnd, 0, 0, nScreenWidth*10.4, nScreenHeight*22, TRUE);
  62.  
  63. //initialising variables
  64.  
  65. //miscellaneous
  66. POINT mouse;
  67. CONSOLE_SCREEN_BUFFER_INFO csbi;
  68.  
  69. //console dimensions
  70. RECT r;
  71. GetWindowRect(hwnd, &r);
  72. //PCONSOLE_FONT_INFO lpConsoleCurrentFont = new CONSOLE_FONT_INFO;
  73. GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
  74. columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
  75. rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
  76.  
  77. //window output set up
  78. wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
  79. HANDLE hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  80. SetConsoleActiveScreenBuffer(hConsole);
  81. DWORD dwBytesWritten = 0;
  82.  
  83. while(1)
  84. {
  85. //clear screen
  86. int ii=-1;
  87. while(ii<nScreenHeight*nScreenWidth)//replace later
  88. {
  89. screen[++ii]=' ';
  90. }
  91.  
  92. //find out over which cell the mouse hovers
  93. GetCursorPos(&mouse);
  94. GetWindowRect(hwnd, &r);
  95. int mi = (mouse.y - r.top - 30)/20 ;
  96. int mj = (mouse.x - r.left - 8) / 10;
  97.  
  98.  
  99. if(mouse.x > 0 && mouse.x < 1010 && mouse.y > 0 && mouse.y < 436)
  100. {
  101.  
  102. //mouse stuff
  103.  
  104. screen[ mi * nScreenWidth + mj ] = WHITE_SPACE;//optional
  105. }
  106.  
  107. //optional {
  108. screen[2] = mi%10 + '0';
  109. screen[1] = mi%100/10 + '0';
  110. screen[0] = mi%1000/100 + '0';
  111.  
  112. screen[6] = mj%10 + '0';
  113. screen[5] = mj%100/10 + '0';
  114. screen[4] = mj%1000/100 + '0';
  115.  
  116. screen[100]='+';
  117. screen[nScreenHeight*nScreenWidth] = WHITE_SPACE;
  118. // }
  119.  
  120. //game stuff
  121.  
  122.  
  123.  
  124. //display
  125. screen[nScreenWidth * nScreenHeight - 1] = WHITE_SPACE;
  126. WriteConsoleOutputCharacter(hConsole, screen, nScreenHeight * nScreenWidth, { 0,0 }, &dwBytesWritten);
  127.  
  128. Sleep(0);
  129. }
  130.  
  131. return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement