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
|
// bmpDisplay2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include<windows.h>
#include <thread>
using namespace std;
bool running = true;
const wchar_t g_szClassName[] = L"myClass";
HINSTANCE hInstance; HINSTANCE hPrevInstance; LPSTR lpCmdLine; int nCmdShow = 1;
HBITMAP picture = NULL;
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_PAINT:
cout << "UPDATED\n";
{
picture = LoadBitmap(hInstance, L"screenShot.bmp");
if (picture == NULL){
cout << "picture didn't load\n";
}
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, picture);
GetObject(picture, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int screenShare(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.lpszMenuName = NULL;
wc.lpszClassName = LPCWSTR(g_szClassName);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wc)) {
cout << "window registration failed";
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, L"Window Name", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 600, 600, NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
cout << "window registration failed";
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&Msg, NULL, 0, 0) > 0) {
//cout << "message " << Msg.message << endl;
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
void commander() {
while (running) {
string input;
cin >> input;
if (input == "update") {
PostMessage(hwnd, WM_PAINT, 0, 0);
}
else if (input == "exit") {
running = false;
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
else {
cout << "Command not recognized\n";
}
}
}
int main() {
thread command(commander);
screenShare(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
while (running) {}
command.join();
}
|