-
Wm_paint
it draws the txt on the screen but it doesnt seem to redraw
is there any way i could fix this ?
Code:
#include <windows.h>
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndCls;
static char szAppName[] = "GDISuite";
MSG Msg;
WndCls.cbSize = sizeof(WndCls);
WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WndCls.lpfnWndProc = WindProcedure;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = hInstance;
WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = szAppName;
WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&WndCls);
CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
szAppName,
"GDI Accessories and Tools",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage( &Msg);
}
return static_cast<int>(Msg.wParam);
}
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
HWND hwnd = FindWindow(NULL, "Age of Empires");
switch(Msg)
{
case WM_PAINT:
while(1)
{
hDC = BeginPaint(hwnd, &Ps);
TextOut(hDC, 50, 42, "Test", 13);
EndPaint(hwnd, &Ps);
}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
-
What are you hoping to accomplish with this code snippet?
Code:
case WM_PAINT:
while(1)
{
hDC = BeginPaint(hwnd, &Ps);
TextOut(hDC, 50, 42, "Test", 13);
EndPaint(hwnd, &Ps);
}
break;
??
-
im trying to draw on another screen, i need to know how to do it
-
I haven't analysed your code, but you may need to use an API such as InvalidateRect to invalidate the area to be redrawn. Then the wm_paint message is generated, the area should be redrawn.
-
remove the while, it is not needed and will cause problems.
Use InvalidateRect() and UpdateWindow() to call for a paint and then tell the app to process the paint immediately. Do this when you want the text to change.
In your paint use GetUpdateRect() and IsRectEmpty() BEFORE the BeginPaint() to ensure you have an area to draw.
Code:
RECT Rect;
GetUpateRect(hWnd, &Rect);
if(IsRectEmpty(&Rect))
GetClientRect(hWnd,&Rect); // fill Rect with entire screen
BeginPaint(hWnd, &ps);
//ensure nothing is on the screen by painting it white
FillRect( ps.hdc , &Rect, GetStockObject(WHITE_BRUSH) );
//print text
GetTextExtentPoint32() can be used to find the area the actual text will take up as strings containing different characters take up diff amounts of space.