#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <jpeglib.h>
HINSTANCE hInst;
int much=1;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR CmdLine, int nCmdShow) {
MSG msg;
BOOL bRet;
hInst=hInstance;
HWND hWnd;
int xwin=0;
int ywin=0;
char winclass[] = "Fensterklasse";
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
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) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = winclass;
RegisterClass (&wc);
xwin=GetSystemMetrics(SM_CXSCREEN);
ywin=GetSystemMetrics(SM_CYSCREEN);
xwin /= 2;
xwin -= 400; //800 Breit
ywin /= 2;
ywin -= 200; //400 Hoch
hWnd = CreateWindow (winclass, "Hello World", WS_OVERLAPPEDWINDOW, xwin, ywin, 800, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
HDC hdc, hdcb;
HBITMAP hbit;
PAINTSTRUCT ps;
RECT crect, wrect;
int xdiff;
int ydiff;
int x, y, i;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE *infile;
byte *buffer;
byte r, g, b;
if (msg == WM_PAINT) {
if (much==1) {
much=2;
GetWindowRect(hWnd,&wrect);
GetClientRect(hWnd,&crect);
xdiff=(wrect.right - wrect.left) - crect.right;
ydiff=(wrect.bottom - wrect.top) - crect.bottom;
wrect.left=wrect.left - (xdiff / 2);
wrect.top=wrect.top - (ydiff / 2);
xdiff += 800;
ydiff += 400;
MoveWindow(hWnd,wrect.left,wrect.top,xdiff,ydiff,TRUE);
hdc=BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
InvalidateRect(hWnd,NULL,FALSE);
return 0;
} else if (much==2) {
much=3;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
if ((infile=fopen("zb.jpg","rb")) == NULL) {
MessageBox(hWnd,"Grafik konnte nicht geöffnet werden: zb.jpg","Error",MB_OK);
PostQuitMessage(0);
return 0;
}
jpeg_stdio_src(&cinfo, infile);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
buffer = (byte*) malloc(2400);
hdc=BeginPaint(hWnd,&ps);
hdcb=CreateCompatibleDC(hdc);
hbit=CreateCompatibleBitmap(hdc,800,400);
SelectObject(hdcb,hbit);
y=0;
while(cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, (JSAMPARRAY) &buffer, 1);
i=0;
for(x=0; x < 800; x++) {
r=buffer[i];
g=buffer[i+1];
b=buffer[i+2];
i+=3;
SetPixel(hdcb,x,y,RGB(r,g,b));
}
y++;
}
EndPaint(hWnd,&ps);
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
InvalidateRect(hWnd,NULL,FALSE);
return 0;
} else {
hdc=BeginPaint(hWnd,&ps);
BitBlt(hdc,0,0,800,400,hdcb,0,0,SRCCOPY);
SelectObject(hdc,(HPEN) GetStockObject(WHITE_PEN));
MoveToEx(hdc,50,50,NULL);
LineTo(hdc,100,100);
SetPixel(hdc,100,50,RGB(255,0,0));
EndPaint(hWnd,&ps);
return 0;
}
}
if (msg == WM_DESTROY) {
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}