// Step 4: the Window Procedure LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { g_myWindows.push_back(hwnd); // if the message is WM_CREATE, the lParam contains a pointer to a CREATESTRUCT // the CREATESTRUCT can contain userdata in pcs->lpCreateParams // placing that in the window Userdata can be handy CREATESTRUCT *pCS = (CREATESTRUCT*)lParam; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG)pCS->lpCreateParams); UserDataWindow *pApp = (UserDataWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA); break; } case WM_CLOSE: PostQuitMessage(0); break; case WM_DESTROY: std::cout << "\ndestroying window (delete userdata and remove from list)\n" ; delete GetUserData(hwnd); g_myWindows.erase(std::find(g_myWindows.begin(), g_myWindows.end(), hwnd)); //PostQuitMessage(0) ; return 0L ; case WM_SIZE: { LOWORD(lParam); // width HIWORD(lParam); // height std::string title(std::to_string(LOWORD(lParam))+"X"+std::to_string(HIWORD(lParam))); SetWindowText(hwnd, title.c_str()); return DefWindowProc(hwnd, msg, wParam, lParam); } case WM_PAINT: if(GetAsyncKeyState('H') && GetAsyncKeyState('A') ) PostQuitMessage(0); break; case WM_KEYDOWN: if( wParam == 'C') CaptureAnImage(hwnd); else if ( wParam == VK_ESCAPE) PostQuitMessage(0); if( wParam == 'W') DestroyWindow(hwnd); else if( wParam == 'Q') PostQuitMessage(0); break; case WM_NCLBUTTONDOWN: // DestroyWindow(hwnd); std::cout << "\nmouse left button down at (" << LOWORD(lParam) << ',' << HIWORD(lParam) << ")\n" ; // fall thru default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { char class_name[80]; char title[80]; GetClassName(hwnd,class_name, sizeof(class_name)); GetWindowText(hwnd,title,sizeof(title)); //std::cout <<"Window title: "<<title<<std::endl; //std::cout <<"Class name: "<<class_name<<std::endl; CaptureAnImage(hwnd); return TRUE; }
int Screengrab::CaptureImagesOnInterval(HWND hWnd){ std::wstring baseFilename = L"tmp/myscreenshot."; int i = 0; while (true){ std::wstringstream stringStream; stringStream << baseFilename << i << ".bmp"; std::wstring imageFilename = stringStream.str(); CaptureAnImage(hWnd, imageFilename); Utils::log(imageFilename); i++; Sleep(1 * 1000); } }
LRESULT CALLBACK CWinApp::WinWinProc( __in HWND hwnd, __in UINT uMsg, __in WPARAM wParam, __in LPARAM lParam ) { switch (uMsg) { case WM_CLOSE: PostQuitMessage(0); break; case WM_CHAR: if (wParam == 0x63) { CaptureAnImage(hwnd); } break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); } return 0; }