Hallo,
wie kann ich eine Druckfunktion programmieren, sodass Texte von WM_PAINT ausgedruckt werden?
Sebastian
PS:smiley:anke im Voraus.
Code:
#include
HWND CreateMainWindow(HINSTANCE hInstance);
//Callback Funktion
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
HWND hWnd = 0;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hWnd = CreateMainWindow(hInstance);
if(0 == hWnd)
{
MessageBox(0,"Es gab ein Problem!","Es gab ein Problem!",MB\_OK);
return 0;
}
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
HWND CreateMainWindow(HINSTANCE hInstance)
{
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS\_DBLCLKS | CS\_OWNDC |
CS\_HREDRAW | CS\_VREDRAW;
wndClass.lpfnWndProc = WindowFunc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE\_BRUSH);
wndClass.hCursor = LoadCursor(NULL, IDC\_ARROW);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "WindowClass";
wndClass.hIcon = LoadIcon(NULL, IDI\_WINLOGO);
wndClass.hIconSm = LoadIcon(NULL, IDI\_WINLOGO);
RegisterClassEx(&wndClass);
return CreateWindowEx(NULL,
"WindowClass",
"Ein einfaches Fenster",
WS\_OVERLAPPEDWINDOW |
WS\_VISIBLE,
10, 10, 900, 700,
NULL,
NULL,
hInstance,
NULL);
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HPEN hPen;
PAINTSTRUCT ps;
HDC hDC;
switch(msg)
{
case WM\_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM\_LBUTTONDOWN:
hDC = GetDC(hWnd);
int x,y;
x = LOWORD(lParam);
y = HIWORD(lParam);
if(x \> 10 & x 80 & 130 \> y){
SetTextColor(hDC,RGB(0,255,0));
//-------------------------------------------------------------------
//Wie kann ich hier eine Druckfunktion einbauen?
//--------------------------------------------------------------------
}
return 0;
break;
case WM\_PAINT:
PAINTSTRUCT ps;
HDC hDC;
hDC = BeginPaint(hWnd,&ps);
SetTextColor(hDC,RGB(0,0,0));
TextOut(hDC,50,50,"Hier steht der zudruckende Text!!!",34);
SetTextColor(hDC,RGB(0,0,0));
TextOut(hDC,20,100,"Drucken",7);
EndPaint(hWnd,&ps);
return 0;
break;
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
MOD hat den Quellcode formatiert.