#include <windows.h>
#include <stdio.h>
#include "resource.h"
#define FileName "c:\\test.dat"
struct SShot
{
char test[5];
HDC hdc;
HBITMAP hbmp;
int w, h;
};
SShot *Main = NULL;
BOOL CALLBACK MainProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hwnd, &ps);
if(Main != NULL)
{
if(!SelectObject(Main->hdc, Main->hbmp))
MessageBox(0, "SelectObject() Failed", "WARNING!", MB_OK | MB_ICONWARNING);
BitBlt(hdc, 0, 0, Main->w, Main->h, Main->hdc, 0, 0, SRCCOPY);
}
else
{
TextOut(hdc, 20, 20, "Failed", 6);
}
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
}
return false;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
FILE *pFile;
SShot *s = new SShot;
char temp[255] = {""};
if(MessageBox(0, "Take Snapshot?", "", MB_YESNO | MB_ICONQUESTION) == IDNO)
{
pFile = fopen(FileName, "r");
fread(&Main, sizeof(SShot), 1, pFile);
if(pFile != NULL)
{
sprintf(temp, "W: %i, H: %i\nTEST: %s", Main->w, Main->h, Main->test);
MessageBox(0, temp, 0, MB_OK);
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), 0, MainProc);
fclose(pFile);
}
else
MessageBox(0, "File Not Found!", "Error", MB_OK | MB_ICONERROR);
exit(0);
}
HWND hwnd;
HDC hdc;
s->w = GetSystemMetrics(SM_CXSCREEN);
s->h = GetSystemMetrics(SM_CYSCREEN);
hwnd = GetDesktopWindow();
hdc = GetDC(hwnd);
s->hdc = CreateCompatibleDC(hdc);
s->hbmp = CreateCompatibleBitmap(hdc, s->w, s->h);
SelectObject(s->hdc,s->hbmp);
BitBlt(s->hdc, 0, 0, s->w, s->h, hdc, 0, 0, SRCCOPY);
ReleaseDC(hwnd, hdc);
strcpy(s->test, "bla");
pFile = fopen(FileName, "wb");
fwrite(&s, sizeof(SShot), 1, pFile);
fclose(pFile);
Main = s;
sprintf(temp, "W: %i, H: %i\nTEST: %s", Main->w, Main->h, Main->test);
MessageBox(0, temp, 0, MB_OK);
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), 0, MainProc);
return 0;
}