Hey! I drew on my desktop!
Synapse Jumps

Alright, so I'm working on drawing with WinAPI (Yes fellas, this topic again ::)). And so I'm trying to draw to a (what I think is a) bitmap in a dialog. So I do this in my proc (before the switch)

if(PlaceLoaded){ // if we have something to draw
    HDC ToBlit = GetDC((HWND)GetDlgItem(hwnd, IDC_BITMAP_PREV)); //gets the DC from the dialog
    blit_to_hdc(place_buffer, ToBlit, PlaceCameraX, PlaceCameraY, 0, 0, place_buffer ->w, place_buffer ->h);
//^-- put my Allegro bitmap onto the DC I've gotten from the dialog
}

Anyways, this shows up right (except that the bitmap overflows past the bitmap and I can't clip it even though I've tried clipping the DC, hwnd, and allegro bitmap, anyways this is another subject). So when I close the window, the bitmap shows up on whatever folder/window/desktop that the program was over. I don't want this! It's bad! Any ideas as to why this may be happening?

Thanks for the help guys!

23yrold3yrold

1#include <windows.h>
2 
3#define NUM 300
4 
5LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
6 
7int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
8 PSTR szCmdLine, int iCmdShow)
9{
10 static int iKeep [NUM][4] ;
11 HDC hdcScr, hdcMem ;
12 int cx, cy ;
13 HBITMAP hBitmap ;
14 HWND hwnd ;
15 int i, j, x1, y1, x2, y2 ;
16 
17 if (LockWindowUpdate (hwnd = GetDesktopWindow ()))
18 {
19 hdcScr = GetDCEx (hwnd, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE) ;
20 hdcMem = CreateCompatibleDC (hdcScr) ;
21 cx = GetSystemMetrics (SM_CXSCREEN) / 10 ;
22 cy = GetSystemMetrics (SM_CYSCREEN) / 10 ;
23 hBitmap = CreateCompatibleBitmap (hdcScr, cx, cy) ;
24
25 SelectObject (hdcMem, hBitmap) ;
26 
27 srand ((int) GetCurrentTime ()) ;
28
29 for (i = 0 ; i < 2 ; i++)
30 for (j = 0 ; j < NUM ; j++)
31 {
32 if (i == 0)
33 {
34 iKeep [j] [0] = x1 = cx * (rand () % 10) ;
35 iKeep [j] [1] = y1 = cy * (rand () % 10) ;
36 iKeep [j] [2] = x2 = cx * (rand () % 10) ;
37 iKeep [j] [3] = y2 = cy * (rand () % 10) ;
38 }
39 else
40 {
41 x1 = iKeep [NUM - 1 - j] [0] ;
42 y1 = iKeep [NUM - 1 - j] [1] ;
43 x2 = iKeep [NUM - 1 - j] [2] ;
44 y2 = iKeep [NUM - 1 - j] [3] ;
45 }
46 BitBlt (hdcMem, 0, 0, cx, cy, hdcScr, x1, y1, SRCCOPY) ;
47 BitBlt (hdcScr, x1, y1, cx, cy, hdcScr, x2, y2, SRCCOPY) ;
48 BitBlt (hdcScr, x2, y2, cx, cy, hdcMem, 0, 0, SRCCOPY) ;
49
50 Sleep (10) ;
51 }
52
53 DeleteDC (hdcMem) ;
54 ReleaseDC (hwnd, hdcScr) ;
55 DeleteObject (hBitmap) ;
56
57 LockWindowUpdate (NULL) ;
58 }
59 return FALSE ;
60}

I have no time for a proper answer (not sure what the question was; OP very garbled) but maybe that'll offer insight. Or something. Okay, I gotta go ...

Synapse Jumps

Hmm, I think you're getting my problem wrong. I don't want to draw the desktop or draw on the desktop. I really like that code though! It looks like some evil virus! Hehe! But anyways, you are right, my code/question was not clear. I've rewritten it. I hope it's more clear.

Again, that code is really fun!

23yrold3yrold

Okay, I'm back :)

I get that error sometimes when the system is low on memory (especially in Mozilla Firebird). So you close the program and the window below doesn't repaint? Unless you're doing something really freaky, then your program shouldn't be responsible for that ...

Synapse Jumps

Alright, well, it's probably just my shitty ass computer. Well, if you feel like it, will you just download the attatched .zip and see if the program will run on your computer? I have included a .setting file (that's what this editor edits). I have also included the main.cpp which has all of the windows stuff, the rest of the stuff is just part of my game (please excuse the GPF at closing/reloading of a level, it's a bug in the cleanup of the game).

Thank you very much for your time!

dawei chen

Have you tried:

InvalidateRect(NULL,NULL,TRUE);

Synapse Jumps

I'm sorry for the lateness of this reply, I have not had access to my source until just right now. I tried that before the dialog closed, however, I changed the first NULL to hwnd, because I looked up the function on MSDN and it looks like that was the appropriate thing to do. Oh, yea ::) that didn't work :-/

EDIT: 23, lets never fight again. Cuz I love you and need your help :)

dawei chen

when the first parameter is NULL,it means to redraw all the windows,
doesn't it work?

Synapse Jumps

No, it does not work. :(

Thread #283975. Printed from Allegro.cc