Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Hey! I drew on my desktop!

This thread is locked; no one can reply to it. rss feed Print
Hey! I drew on my desktop!
Synapse Jumps
Member #3,073
December 2002

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
Member #1,134
March 2001
avatar

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 ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Synapse Jumps
Member #3,073
December 2002

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
Member #1,134
March 2001
avatar

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 ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Synapse Jumps
Member #3,073
December 2002

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
Member #3,373
March 2003

Have you tried:

InvalidateRect(NULL,NULL,TRUE);

Synapse Jumps
Member #3,073
December 2002

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
Member #3,373
March 2003

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

Synapse Jumps
Member #3,073
December 2002

No, it does not work. :(

Go to: