#define _CRT_SECURE_NO_WARNINGS
#undef _UNICODE
#include <Windows.h>
#include <fstream>
using namespace std;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ChildFont(HWND hWnd, LPARAM lParam);
BOOL CALLBACK TLMSNWnd(HWND hWnd, LPARAM lParam);
VOID CALLBACK TimerProc(
__in HWND hwnd,
__in UINT uMsg,
__in UINT_PTR idEvent,
__in DWORD dwTime
);
void SaveBitmap(HWND hWnd, TCHAR *szName)
{
BITMAPFILEHEADER bfHeader;
BITMAPINFOHEADER biHeader;
BITMAPINFO bInfo;
HDC winDC, memDC;
TCHAR filename[1024];
int d_x, d_y, outBytes;
RECT rsRect;
HBITMAP hBitmap;
ofstream file;
BYTE* memory = 0;
DWORD dwTC;
GetWindowRect(hWnd, &rsRect);
d_x = rsRect.right-rsRect.left;
d_y = rsRect.bottom-rsRect.top;
bfHeader.bfType = ('B' | ('M' << 8));
bfHeader.bfSize = 0;
bfHeader.bfReserved1 = 0;
bfHeader.bfReserved2 = 0;
bfHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
biHeader.biSize = sizeof(biHeader);
biHeader.biHeight = d_y;
biHeader.biWidth = d_x;
biHeader.biPlanes = 1;
biHeader.biBitCount = 24;
biHeader.biCompression = BI_RGB;
biHeader.biSizeImage = 0;
biHeader.biXPelsPerMeter = 0;
biHeader.biYPelsPerMeter = 0;
biHeader.biClrImportant = 0;
biHeader.biClrUsed = 0;
dwTC = GetTickCount();
sprintf(filename, "%s%c%.8d.bmp", szName, '_', dwTC);
file.open(filename, ios::binary);
if(!file)
{
TCHAR mbBuf[500];
sprintf(mbBuf, "Could not open %s for writing. Ensure that this application is running in a directory where it has permission to write files, and that the path, including the file name, does not exceed %d characters.", filename, MAX_PATH);
MessageBox(0, mbBuf, "Error", MB_OK | MB_ICONSTOP);
ExitProcess(0x0);
}
file.write((char*)&bfHeader, sizeof(bfHeader));
file.write((char*)&biHeader, sizeof(biHeader));
bInfo.bmiHeader = biHeader;
winDC = GetDC(hWnd);
memDC = CreateCompatibleDC(winDC);
hBitmap = CreateDIBSection(winDC, &bInfo, DIB_RGB_COLORS, (void**) &memory, 0, 0);
SelectObject(memDC, hBitmap);
BitBlt(memDC, 0, 0, d_x, d_y, winDC, 0, 0, SRCCOPY);
DeleteDC(memDC);
ReleaseDC(hWnd, winDC);
outBytes = (((24*d_x+31) & (~31))/8)*d_y;
file.write((char*)memory, outBytes);
DeleteObject(hBitmap);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX WinCl;
MSG Msg;
HWND hWnd, hStart, hStop;
WinCl.cbClsExtra = 0;
WinCl.cbSize = sizeof(WNDCLASSEX);
WinCl.cbWndExtra = 0;
WinCl.hbrBackground = (HBRUSH) COLOR_WINDOW;
WinCl.hCursor = LoadCursor(NULL, IDC_ARROW);
WinCl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WinCl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
WinCl.hInstance = hInstance;
WinCl.lpfnWndProc = WndProc;
WinCl.lpszClassName = "WlxSSWnd";
WinCl.lpszMenuName = NULL;
WinCl.style = 0;
RegisterClassEx(&WinCl);
hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "WlxSSWnd", "MSN Screenshot Taker", WS_VISIBLE | WS_SYSMENU, 100, 100, 160, 60, NULL, NULL, hInstance, NULL);
hStart = CreateWindowEx(0, "BUTTON", "Start", WS_VISIBLE | WS_CHILD | BS_TEXT, 0, 0, 75, 30, hWnd, NULL, hInstance, NULL);
hStop = CreateWindowEx(0, "BUTTON", "Stop", WS_VISIBLE | WS_CHILD | BS_TEXT | WS_DISABLED, 75, 0, 75, 30, hWnd, NULL, hInstance, NULL);
ShowWindow(hWnd, SW_SHOW);
EnumChildWindows(hWnd, ChildFont, 0);
UpdateWindow(hWnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL CALLBACK ChildFont(HWND hWnd, LPARAM lParam)
{
HFONT hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hWnd, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM(FALSE, 0));
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
if((HWND)lParam==FindWindowEx(hWnd, NULL, "BUTTON", "Start"))
{
// button disabled = 0x58000000 enabled = 0x50000000
//time_t s;
EnableWindow(FindWindowEx(hWnd, NULL, "BUTTON", "Start"), FALSE);
EnableWindow(FindWindowEx(hWnd, NULL, "BUTTON", "Stop"), TRUE);
SetTimer(hWnd, 1001, 30000, TimerProc);
EnumWindows(TLMSNWnd, 0);
}
else if((HWND)lParam==FindWindowEx(hWnd, NULL, "BUTTON", "Stop"))
{
EnableWindow(FindWindowEx(hWnd, NULL, "BUTTON", "Start"), TRUE);
EnableWindow(FindWindowEx(hWnd, NULL, "BUTTON", "Stop"), FALSE);
KillTimer(hWnd, 1001);
}
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
break;
}
return 0;
}
BOOL CALLBACK TLMSNWnd(HWND hWnd, LPARAM lParam)
{
TCHAR cnBuf[256];
GetClassName(hWnd, cnBuf, 255);
if(strcmp(cnBuf, "TabbedHostWndClass")==0)
{
HWND wlx = FindWindowEx(hWnd, 0, "WLXDUI", NULL);
if(wlx)
{
SaveBitmap(wlx, "m");
}
}
return TRUE;
}
VOID CALLBACK TimerProc(
__in HWND hwnd,
__in UINT uMsg,
__in UINT_PTR idEvent,
__in DWORD dwTime
)
{
if(idEvent==1001)
{
EnumWindows(TLMSNWnd, 0);
}
}