Re: Graphics "goes away" - New Information

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



>> When it stops, does it stop forever (ie... minimizing / restoring the
> dialog
>> causes it to not redraw)? If so, this would allow you to place a debug
>> the
>> code and place a breakpoint in it when the problem occurs.
>>
>
> The code does not stop. The only thing that stops is the lines do not
> display.
>

By stop, I mean, do the lines stop drawing from that point forward
(subsequent WM_PAINT messages execute but nothing is drawn)?

>> You mentioned that you were doing the drawing in the WM_PAINT. Is this
where
>> the calculations to determine the points are occurring also? Could you
>> precalculate the points and simply draw them in WM_PAINT (this would
>> speed
>> up the drawing)?

>The points are calculated in WM_PAINT. It would take 1000 * 120 * 2
>points.
>I will have to think about that.

I'm not sure where the 120 comes from. I thought you were drawing 1000
lines. Anyways, even if you're drawing 120,000 lines.

1000 * 120 * 2 = 240,000 points
Each point is 8 bytes.
240,000 * 8 = 1,920,000 bytes

So, for almost 2 MB of memory you could have a much faster repaint. If you
have that memory to spare, it may be worth it. It might not address this
issue though, but it would separate the point calculations from the actual
drawing code which might be a good thing.

How long does the WM_PAINT message take to execute now?

Can you replace the WM_PAINT with something simpler now that draws the same
number of points (maybe even the same points since you mentioned you had
recorded these points)?

>> Does this happen just on the one machine or does it happen on other
machines
>> as well? Could it be an issue with the video card driver?

>It happens on all machines.

Are all of these machines configured the same way? Same OS, vid card, etc?
Have you tried upgrading the video card driver to the latest version?

>> Is there anyway you can post a code snippet of your WM_PAINT?

>Not in its present configuration. The calculations are spead over dozens
>of
functions.

Without seeing the code and what it's doing, I'm just guessing at what your
problem could be.

Here's a simple sample program that draws 1000 random lines using different
pens. It uses a timer to keep it drawing. I didn't do any double-buffering,
so it'll flash. See if this works for you.

// LineDraw.cpp : Defines the entry point for the application.
//

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows
headers
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;

srand(GetTickCount());

// Initialize global strings
_tcscpy(szTitle, _T("LineDraw Test"));
_tcscpy(szWindowClass, _T("LINEDRAW"));
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this
function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable
and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

SetTimer(hWnd, 1, 100, NULL);

return TRUE;
}

POINT GetRandPoint(LPCRECT prc)
{
POINT pt;
pt.x = prc->left + rand() * (prc->right - prc->left) / RAND_MAX;
pt.y = prc->top + rand() * (prc->bottom - prc->top) / RAND_MAX;

// Uncomment to pretend that this function takes a while to compute.
// Sleep(5);
return pt;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;

case WM_TIMER:
InvalidateRect(hWnd, NULL, TRUE);
break;

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
hdc = GetDC(hWnd);

RECT rc;
GetClientRect(hWnd, &rc);
for(int i = 0; i < 1000; i++)
{
POINT ptMove = GetRandPoint(&rc);
POINT ptLine = GetRandPoint(&rc);

HPEN pen = CreatePen(PS_SOLID, 1, RGB(rand() * 255 / RAND_MAX, rand() *
255 / RAND_MAX, rand() * 255 / RAND_MAX));
HPEN penOld = (HPEN) SelectObject(hdc, pen);
MoveToEx(hdc, ptMove.x, ptMove.y, NULL);
LineTo(hdc, ptLine.x, ptLine.y);
DeleteObject(SelectObject(hdc, penOld));
}

ReleaseDC(hWnd, hdc);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


.



Relevant Pages

  • metafile records rclBounds again
    ... ATOM MyRegisterClass(HINSTANCE hInstance); ... LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); ... HWND hWnd; ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Serial data + DialogBox
    ... > int WINAPI WinMain(HINSTANCE hInstance, ... > if (!hWnd) ... > LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM ...
    (microsoft.public.windowsce.embedded)
  • Re: Serial data + DialogBox
    ... > int WINAPI WinMain(HINSTANCE hInstance, ... > if (!hWnd) ... > LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM ...
    (microsoft.public.pocketpc)
  • Re: Serial data + DialogBox
    ... > int WINAPI WinMain(HINSTANCE hInstance, ... > if (!hWnd) ... > LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM ...
    (microsoft.public.windowsce.app.development)
  • Re: Serial data + DialogBox
    ... > int WINAPI WinMain(HINSTANCE hInstance, ... > if (!hWnd) ... > LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM ...
    (microsoft.public.pocketpc.developer)