1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#include <chrono>
#include <cstring>
#include <fstream>
#include <iostream>
#include <thread>
#include <windows.h>
using namespace std;
int Rn(int center, int width) {
int n = width + 1;
int m = 0 - width / 2;
int r = rand() % n + m + center;
return r;
}
void PS_activate(bool& PS_active, bool& EVT_TYPE_2, bool& exit_flag,
bool& event_over, HDC& hdcMemory, HDC& hdcMemoryFULL) {
event_over = false;
while ( Rn(50, 100) < 25 || Rn(50, 100) > 75 ) {
}
while ((!exit_flag) && (!event_over)) {
if ( Rn(50, 100) > 50) {
PS_active = true;
}
if (Rn(50, 100) < 50 ) {
EVT_TYPE_2 = true;
}
if ( Rn(50, 100) > 90 && Rn(50, 100) < 10 ) {
event_over = true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
std::cout << "PS Flag Stopping..." << endl;
}
void F_Cmd(bool& exit_flag, bool& event_over, POINT GWindowO, HDC& hdcMemory,
HDC& hdcMemoryFULL) {
// INITIALIZING VARIABLES
bool PS_active = false;
bool EVT_TYPE_2 = false;
int pressed = 1;
int i = 0;
std::thread t_PS_Flag(PS_activate, ref(PS_active), ref(EVT_TYPE_2), ref(exit_flag),
ref(event_over), ref(hdcMemory), ref(hdcMemoryFULL));
i = 0;
pressed = 1;
while (i = 0) {
if (Rn(50, 100) < 25) {
i = 1;
}
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
while ((!exit_flag) && (!event_over)) {
if ((pressed == 1) && (!event_over))
{
if (PS_active == true) {
PS_active = false;
}
if (EVT_TYPE_2 == true) {
EVT_TYPE_2 = false;
}
if ( Rn(50, 100) > 75 ) {
}
}
if ((pressed == 0) && (!event_over))
{
}
}
}
int get_Bitmap(int GxpSx, int GypSy, HDC& hdcMemory, int width, int height) {
HDC hdcSource = GetDC(NULL);
hdcMemory = CreateCompatibleDC(hdcSource);
HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, width, height);
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcMemory, hBitmap);
if (!BitBlt(hdcMemory, 0, 0, width, height, hdcSource, GxpSx, GypSy, CAPTUREBLT | SRCCOPY)) {
cout << "BitBlt failed!" << endl;
}
//clean up
DeleteObject(hBitmapOld);
DeleteObject(hBitmap);
ReleaseDC(NULL, hdcSource);
return 0;
}
void update_Bitmap(POINT GWindowO,
POINT S,
HDC& hdcMemory,
bool& exit_flag,
int width,
int height,
int refresh
) {
while ((!exit_flag)) {
get_Bitmap(S.x + GWindowO.x, S.y + GWindowO.y, hdcMemory, width, height);
std::this_thread::sleep_for(std::chrono::milliseconds(refresh));
}
std::cout << "thread: update Bitmap stopped" << endl;
return;
}
int main()
{
HDC hdcMemory = NULL;
HDC hdcMemoryFULL = NULL;
bool exit_flag = false;
bool event_over = false;
POINT GwindowO = { 0,0 };
POINT no_offset = { 0,0 };
int GwindowOx = 0;
int GwindowOy = 0;
int input = NULL;
HDC hDC = GetDC(NULL);
ReleaseDC(NULL, hDC);
get_Bitmap(0, 0, hdcMemory, 50, 50);
get_Bitmap(0, 0, hdcMemoryFULL, 100, 100);
exit_flag = false;
event_over = false;
if (hdcMemory == NULL) {
std::cout << "hdcMemory is NULL" << endl;
}
if (hdcMemoryFULL == NULL) {
std::cout << "hdcMemoryFULL is NULL" << endl;
}
std::thread t_Bitmap_FS(update_Bitmap, GwindowO, no_offset, ref(hdcMemoryFULL), ref(exit_flag), 100, 100, 1000);
std::thread t_Bitmap(update_Bitmap, GwindowO, no_offset, ref(hdcMemory), ref(exit_flag), 50, 50, 25);
std::thread t_F_Cmd(F_Cmd, ref(exit_flag), ref(event_over), GwindowO, ref(hdcMemory), ref(hdcMemoryFULL));
while (!exit_flag) {
while (event_over) {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::cout << "" << endl;
std::cout << "AGAIN?" << endl;
std::cout << "" << endl;
std::cin >> input;
system("PAUSE");
system("PAUSE");
std::cin >> input;
std::cout << "" << endl;
event_over = false;
}
}
}
|