SetLayeredWindowAttributes(hWnd, 0, 100, LWA_ALPHA);
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KeyboardEvent, hInstance, NULL);
LRESULT CALLBACK KeyboardEvent(int nCode, WPARAM wParam, LPARAM lParam)
{
if ((nCode == HC_ACTION))
{
KBDLLHOOKSTRUCT* hooked_key = (KBDLLHOOKSTRUCT*)lParam;
if (hooked_key->vkCode == VK_LSHIFT || hooked_key->vkCode == VK_RSHIFT) {
bool shiftPressed = (wParam == WM_KEYDOWN);
LONG oldStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
if (shiftPressed) {
SetWindowLong(hWnd, GWL_EXSTYLE, oldStyle & (~WS_EX_TRANSPARENT));
}
else {
SetWindowLong(hWnd, GWL_EXSTYLE, oldStyle | WS_EX_TRANSPARENT);
}
}
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
UnhookWindowsHookEx(hKeyboardHook);
static HPEN Pen = CreatePen(PS_SOLID, 3, RGB(0, 0, 255));
static BOOL fDraw = FALSE;
static POINT ptPrevious = { 0, 0 };
case WM_PAINT: {
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
// TODO: рисовать здесь
EndPaint(hWnd, &ps);
break;
}
ptPrevious.x = GET_X_LPARAM(lParam);
ptPrevious.y = GET_Y_LPARAM(lParam);
#include <iostream>
#include <conio.h>
#include <vector>
using namespace std;
int main()
{
int rez;
int arr_src[] = {1,8,3,2};
std::vector<int> arr(arr_src, arr_src + sizeof(arr_src)/sizeof(arr_src[0]));
arr.push_back(7);
arr.push_back(8);
rez = arr.size(); //кол-во элементов в массиве
cout << rez << endl;
for (int i = 0; i < rez; i++)
cout << arr[i] << ' ';
getch();
return 0;
}
vector<bool>
специальным стандартным контейнером, в котором каждый элемент bool использует только один бит памяти вместо того, чтобы занимать 1 байт, как занимает обычный bool. Ценой этой оптимизации является то, что этот контейнер не предоставляет всех возможностей и интерфейс, как это делает нормальный стандартный контейнер. bool &pb =v[0]
не является валидным кодом. #include "enum.h"
BETTER_ENUM(etype, int, laborer, secretary, manager, accountant, executive, researcher);
//...
struct employee {
int number;
float pension;
etype post = etype::laborer;
date start;
};
int main()
{
//... пропущено
for (etype i : etype::_values())
{
std::cout << i << " ";
}
std::cout << std::endl;
std::string etypeStr;
std::cin >> etypeStr;
first.post = etype::_from_string(etypeStr.c_str());
}
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
...
const char *url = "http://localhost/test.mp3";
AVFormatContext *pFormatCtx = NULL;
int ret = avformat_open_input(&pFormatCtx, url, NULL, NULL);
if (ret >= 0) {
avformat_find_stream_info(pFormatCtx, NULL);
int seconds = (pFormatCtx->duration / AV_TIME_BASE);
int64_t size = avio_size(pFormatCtx->pb);
avformat_close_input(&pFormatCtx);
avformat_free_context(pFormatCtx);
}
void CMFCApplication1Dlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) {
Default();
}
BOOL CMFCApplication1Dlg::OnNcActivate(BOOL active)
{
if (m_nFlags & WF_STAYACTIVE)
active = TRUE;
return(BOOL)DefWindowProc(WM_NCACTIVATE, active, 0L);
}
#include <fstream>
#include <ios>
#include <ctime>
#include <iostream>
#include <windows.h>
class MyBitmap {
BITMAPFILEHEADER header_;
BITMAPINFOHEADER info_;
bool loaded_;
char* pixels_;
size_t data_size_;
size_t row_padded_;
public:
MyBitmap(const char* fileName) {
loaded_ = false;
pixels_ = 0;
std::ifstream bmp(fileName, std::ios::binary);
if (!bmp) {
return;
}
bmp.read((char*)&header_, sizeof(header_));
if (!bmp) {
return;
}
if (header_.bfType != 'MB') {
std::cout << "Format is not supported" << std::endl;
return;
}
bmp.read((char*)&info_, sizeof(info_));
if (!bmp) {
return;
}
if (info_.biBitCount != 24) {
std::cout << "Format is not supported" << std::endl;
return;
};
row_padded_ = (info_.biWidth * 3 + 3) & (~3);
int height = info_.biHeight;
data_size_ = row_padded_ * height;
pixels_ = new char[data_size_];
bmp.read(pixels_, data_size_);
if (bmp) {
loaded_ = true;
}
return;
}
bool Save(const char* fileName) {
if (!loaded_) {
return false;
}
std::ofstream f(fileName, std::ios::binary);
if (!f) {
return false;
}
f.write((char*)&header_, sizeof(header_));
f.write((char*)&info_, sizeof(info_));
f.write(pixels_, data_size_);
if (f) {
return true;
}
return false;
}
void AddBorderInside(int borderSize = 15) {
for (int i = 0; i < info_.biWidth; i++) {
for (int j = 0; j < info_.biHeight; j++) {
if (i < borderSize || i >= info_.biWidth - borderSize
|| j < borderSize || j >= info_.biHeight - borderSize) {
int pos = row_padded_* j + i * 3;
pixels_[pos] = rand() % 256;
pixels_[pos + 1] = rand() % 256;
pixels_[pos + 2] = rand() % 256;
}
}
}
}
void AddBorderOutside(int borderSize = 15) {
int new_width = info_.biWidth + borderSize * 2;
int new_row_padded = (new_width * 3 + 3) & (~3);
int new_height = info_.biHeight + borderSize * 2;
int new_data_size = new_row_padded * new_height;
char* new_pixels_ = new char[new_data_size];
for (int i = 0; i < info_.biHeight; i++) {
int old_pos = row_padded_* i;
int new_pos = new_row_padded * (borderSize+i) +3 * borderSize;
memcpy(new_pixels_ + new_pos, pixels_ + old_pos, info_.biWidth * 3);
}
delete[] pixels_;
info_.biWidth = new_width;
info_.biHeight = new_height;
pixels_ = new_pixels_;
row_padded_ = new_row_padded;
data_size_ = new_data_size;
AddBorderInside(borderSize);
}
bool IsLoaded() const {
return loaded_;
}
~MyBitmap() {
delete[] pixels_;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));
MyBitmap bmp("input.bmp");
if (!bmp.IsLoaded()) {
std::cout << "Unable to load bitmap" << std::endl;
return 1;
}
bmp.AddBorderOutside();
if (!bmp.Save("output.bmp")) {
std::cout << "Unable to save bitmap" << std::endl;
}
return 0;
}
InternetGetCookie does not return cookies that the server marked as non-scriptable with the "HttpOnly" attribute in the Set-Cookie header.
QNetworkRequest request(QUrl("http://site.net/index.php"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QUrlQuery postData;
postData.addQueryItem("username", login);
postData.addQueryItem("password", pass);
postData.addQueryItem("submit_button", "Submit!");
QNetworkAccessManager * pManager = new QNetworkAccessManager(this);
QNetworkReply * reply = pManager->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
#include <windows.h>
#include <tlhelp32.h>
int _tmain(int argc, _TCHAR* argv[])
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE) {
while (Process32Next(snapshot, &entry) == TRUE) {
if (_tcsicmp(entry.szExeFile, _T("explorer.exe")) == 0) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, entry.th32ProcessID);
if (hProcess) {
TCHAR path[MAX_PATH];
DWORD cchExeName = MAX_PATH;
if (QueryFullProcessImageName(hProcess, 0, path, &cchExeName) != 0) {
_tprintf(_T("%s\r\n"), path);
}
CloseHandle(hProcess);
}
}
}
}
CloseHandle(snapshot);
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, const char * argv[]) {
ifstream file("file.txt");
if (!file) {
std::cout << "Unable to open file" << std::endl;
}
string separators = " \t\r\n,.!?;:";
int i = 0;
char c;
bool lastWasSep = true;
std::string tokens[4];
std::string curToken;
while (file.get(c)) {
bool isSep = separators.find(c) != string::npos;
if (lastWasSep == isSep) {
curToken += c;
} else {
tokens[i++] = curToken;
curToken = c;
}
lastWasSep = isSep;
if (i == 4) {
cout << tokens[0] << tokens[3] << tokens[2] << tokens[1];
i = 0;
}
}
tokens[i++] = curToken;
if (i == 4) {
cout << tokens[0] << tokens[3] << tokens[2] << tokens[1];
} else {
for (int j = 0; j < i; j++) {
cout << tokens[j];
}
}
return 0;
}
signals:
void someSignal1(QString a);
void someSignal2(int a, QString b);
void someSignal3(float a, int b, QString c);
...
void someSlot(QVariant arg1,QVariant arg2, QVariant arg3);
connect(sender, &Sender::someSignal1, std::bind( &Receiver::someSlot, receiver, std::placeholders::_1, QVariant(), QVariant() ));
connect(sender, &Sender::someSignal2, std::bind( &Receiver::someSlot, receiver, std::placeholders::_1, std::placeholders::_2, QVariant()));
connect(sender, &Sender::someSignal3, std::bind( &Receiver::someSlot, receiver, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3 ));