News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GDI problem

Started by TNick, June 22, 2006, 09:04:09 AM

Previous topic - Next topic

TNick

After I create the main window like this:

    INVOKE    CreateWindowEx,      NULL,  ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,\
            CW_USEDEFAULT, CW_USEDEFAULT, 600,400,\
            NULL,NULL,hInst,NULL
    mov       hWndMain,         eax


I create a thread for initial drawing


   mov   ebx,            OFFSET InitDraw
   invoke   CreateThread,         0,0,ebx,0,0,addr IDThInitDraw


In <<InitDraw>> I create the objects I need

- a compatible DC (BackDC) with my window's DC
- a compatible bitmap with my window's DC wich I select in the BackDC
- (brushes, pens, fonts)


Aftherthat I start drawing in my DC, starting with a ExtFloodFill, then MoveToEx-es and LineTo-es, and more ExtFloodFill's


Main window, when it recive a WM_PAINT, call BitBlt and copy the rectangle that need to be updated from BackDC


Now THE PROBLEM:

When I build the executable and run it in WIndows XP, my system crash with blue screen, saing thet there is a problem in <win32k.sys>
When I run it in Windows 98 the system doesn't crash, but in my window appear a lot of strange things (sorry, I don't have a screen shoot).  :eekAnyway, the upper part of this window looks like there was a shift in video memory ... something like that:

*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   
   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   
*    *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   
  *    *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   

NOTE: I tried without creating a thread; the result was the same.

I solved this problem by drawing a rectangle after I select the bitmap in BackDC on all his area.

My question is: Why is this happening?


Casper

Are you dropping the selection into the rectangle in your solution?  If so it may be that you have not gotten the screen coordinates and setting focus to it and are dropping the selection out of bounds.

Casper

TNick

I created the bitmap like this:

   INVOKE   GetSystemMetrics,SM_CYSCREEN
   push   eax
   INVOKE   GetSystemMetrics,SM_CXSCREEN
   push   eax
   push   hDCMain
   CALL   CreateCompatibleBitmap

so it is large enough. The bounds are not exceded in any way - I am absolutly shure!

Thanks anyway, Casper!

Casper


raymond

Set up some kind of a flag in your data section to indicate that your "drawing" is ready to be BitBlt.

When you process the WM_PAINT message, check that flag BEFORE attempting to BitBlt anything.  Remember that a WM_PAINT message may be sent to your WinProc before you have set up your back DC. The system may not like the parameters which are then supplied.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

TNick

I will try that, raymond.
So, if I understand corectly, there shouldn't be 2 or more threads that work with the same hDC at the same time? That was the problem? Because, as I was saing in the first message, I tried to work in the same thread (create the BackDC after CreateWIndowEx and before the message loop)

Tedd

Did you SelectObject the compatible-bitmap into the back hdc? This is what gives you the actual 'surface' to draw onto - without this, you will get no drawing (just junk - whatever image was already in memory.)


As for 2 threads drawing on the same dc..
WNDCLASSEX.style:
QuoteCS_CLASSDC

Allocates one device context to be shared by all windows in the class. Because window classes are process specific, it is possible for multiple threads of a multithreaded application to create a window of the same class. It is also possible for the threads to attempt to use the device context simultaneously. When this happens, the operating system allows only one of the threads to successfully finish its drawing operation.
No snowflake in an avalanche feels responsible.

TNick

Thanks for your answer, Tedd.
As I was saing in my first post :

In <<InitDraw>> I create the objects I need

- a compatible DC (BackDC) with my window's DC
- a compatible bitmap with my window's DC wich I select in the BackDC


About CS_CLASSDC: in my window's DC I perform only BitBlt's. No other drawing. This flag affects all DC's created with CreateCompatibleDC? Because, if not, it doesn't affect my program.

Tedd

Sorry, I must've missed that ::)

CLASS_DC affects the dc your process draws onto the 'screen.' So while you may create your own DCs, at some point you will blt them to the screen (wm_paint?), which will copy the contents onto the process 'screen dc' -- which is the one affected.


Maybe posting code will be easier than us trying to guess what's going on?
Also, try stripping down your code to the point where only the necessary parts to create the problem are left (this can be a useful way of debugging.)
No snowflake in an avalanche feels responsible.

TNick

You are right, Tedd. I will post the code the day after tomorrow. Thanks anyway. Regards!

TNick

Sorry because I cannot keep my promise. It is because I don't have time. I will post it in future.