Results 1 to 37 of 37

Thread: BitBlt and Make Blitted Image Stay...

  1. #1

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    ok got the WM_PAINT msg handled

    Ok now everything updates smoothly and stays where its supposed to, but now i have another problem. I have created a simple function that bitblts my titlebar, my main form and my buttons. I have put this function in the WM_PAINT and the bitblt works fine and system resources aren't being used, but i also have another function in the WM_LBUTTONDOWN that checks the mouse coord, and if within a specified region will respond accordingly. Lets say that i have a button thats my rewind button, the mouse is clicked and its within the specified region for the rewind button my function in the WM_LBUTTONDOWN msg will call bitblt and blit the down image to the form... the problem is that the image does not show.... i was thinking its because of the WM_PAINT message that draws over the image before i can see it, so what i did was declare (bool Is_Btn_Down, then in my rewind function, i set (Is_Btn_Down = TRUE), then in my WM_PAINT function i check if (Is_Btn_Down = TRUE) or (FALSE), if it = TRUE then i bitblt the down button image and if its FALSE it should bitblt the UP button image. the problem is that the WM_PAINT message doesn't update the window unless it is moved offscreen, minimized or covered by another window. So i click my rewind button, it seems that nothing happens, but if i minimize the app and restore it, i see my down state rewind button, so this tells me that my functions are working properly but WM_PAINT isn't updating, how do i send a WM_PAINT message or something to my main window, I've tried UpdateWindow but it didn't work. is there something else..
    Thanx for any input

    AAG
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess you would find out this too, but the deal is simple, let WM_LBUTTONDOWN and WM_PAINT both call the function to blit up/down image
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    amac
    Guest
    There is always this function...

    Code:
    BOOL RedrawWindow (
      HWND hWnd,                    // handle of window
      CONST RECT * lprcUpdate,      // address of structure with update rectangle
      HRGN hrgnUpdate,              // handle of update region
      UINT flags                    // array of redraw flags
    );

  4. #4
    Zaei
    Guest
    ValidateRect() might be in order here as well.

    Z.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I just think the simplest solution is in order.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    kedamn i have tried doing your solution right now, it even said so in my first post, i call bitblt on WM_LBUTTON down and also in WM_PAINT and the button still doesn't show, i'll try the other options and see what i come up with...

    Thanx everyone for your input..
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  7. #7

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    ok still having problems

    ok i'm still having problems, i just took off the WM_PAINT message and clicked in the predefined area and it shows the down button state of the rewind button but when i release and handle the LBUTTONUP msg it doesn't show the i've tried all the redraw window and things like that and still nothing... i have posted the redrawwindow code i'm using, tell me if its right

    Code:
                    Redraw_Skin();
    	BitBlt(hdcWindow, 10,  19,  23,  19, hdcMemory,  0,  84, SRCCOPY);
    
    
    	RECT BTN_RECT;
    
    	BTN_RECT.top = 19;
    	BTN_RECT.bottom = 38;
    	BTN_RECT.left = 33;
    	BTN_RECT.right = 56;
    
    	RedrawWindow (Main_Hwnd, &BTN_RECT, NULL, 
    	RDW_INTERNALPAINT | RDW_INTERNALPAINT | RDW_ERASENOW | RDW_UPDATENOW);
    Redraw skin calls a function that automatically assigns all the variables with thier appropiate values..
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Ah if you're using a memory dc then you have to blit the changes there as well, as the memory DC will overwrite it next time WM_PAINT is called
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Can you .zip and post you project so I can look at it? I have done what you are asking a ton of times (I have skined almost 1/2 the projects I have done. It's cooler that way) but its impossible for me to tell what you have going on from what you have said thus far.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  10. #10

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    ok heres my project

    heres my project, if its messy sorry....
    Attached Files Attached Files
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  11. #11
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    It is not messy at all believe me. Your code was real easy to read. Ok here is the deal, I am running out of time today but I will look at it first thing tomorrow. I can't seem to see why your not refreshing. But let me give you 3 pieces of advice.

    1) Make a global var like POINT pt; then when you catch your mouse events use:
    pt.x = LOWORD(lparam);
    pt.x = HIWORD(lparam);
    That way your pt.x and pt.y will be the correct placement on your window. If not it gets messed up on breaks and you dont have to calc it and stuff.

    2) add:

    BeginPaint(hwnd,&ps);
    EndPaint(hwnd,&ps);

    after:

    case WM_PAINT:
    {
    Redraw_Skin();

    Your WM_PAINT needs to complete the paint commands. This should speed things up.

    3) Looks like you have a bunch of memory leaks. I would make a destory function that kills:

    HBITMAP MAINBMP;
    HDC hdcMemory, hdcWindow;

    This should help your program. I will figure out your refresh problem tomorrow, unless someone beats me to it.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  12. #12

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    thanx.

    thanx a bunch man i will do what you have told me and see what happens thanx again, i'll be awaiting your next reply

    Laterz,
    AAG
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  13. #13

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok added the global point struct, that works great hehe i have question about the begin and end paint, i already have them in the function thats in the WM_PAINT msg, so why would i need to put them in the WM_PAINT again ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    PHP Code:
    void Redraw_Skin()
    {
        if(
    MAINBMP)
        {
            
    BeginPaint(Main_Hwnd, &ps);
            
    hdcWindow =GetDC(Main_Hwnd);
            
    hdcMemory CreateCompatibleDC(hdcWindow);

            
    SelectObject(hdcMemoryMAINBMP);

            
    BitBlt(hdcWindow,  0,   0275,  17hdcMemory,  0,   0SRCCOPY);    //TitleBar
            
    BitBlt(hdcWindow,  0,  17275,  30hdcMemory,  0,  36SRCCOPY);    //Bottom
            
            
    if (RewindBtnState == TRUE)

            {
                
    BitBlt(hdcWindow10,  19,  23,  19hdcMemory,  0,  84SRCCOPY);    //Rewind

            
    }
            else
            {
                
    BitBlt(hdcWindow10,  19,  23,  19hdcMemory,  0,  67SRCCOPY);    //Rewind
            
    }

            
    BitBlt(hdcWindow33,  19,  23,  19hdcMemory23,  67SRCCOPY);    //Play
            
    BitBlt(hdcWindow56,  19,  23,  19hdcMemory46,  67SRCCOPY);    //Pause
            
    BitBlt(hdcWindow79,  19,  23,  19hdcMemory69,  67SRCCOPY);    //Stop
            
    BitBlt(hdcWindow10219,  22,  19hdcMemory92,  67SRCCOPY);    //Foward
            
    BitBlt(hdcWindow13020,  22,  17hdcMemory11467SRCCOPY);    //Open

            
    DeleteDC(hdcMemory);
            
    ReleaseDC(Main_Hwnd,hdcWindow);
            
    EndPaint(Main_Hwnd, &ps);
        }

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    yup thats what it was.. I had to take the begin and endpaint out of the draw skin function thanx to all it now works properly



    Laterz,
    AAG
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  16. #16

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    Another Problem :(

    got another problem... whenever i click the rewind button, the images show properly and u can click it as fast as u want and it will always show to appropiate image, but sometimes the image flickers, not just the button image but the whole image.... i know its not supposed to do this... i'll will post my project in a few minutes so someone can take a look at it..
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  17. #17
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Try making globals for your DCs and bitmaps. Then make a loader function to load everything in and a deloader to reverse it. That way you are not wasting CPU time everytime you go to paint the images. That should help.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  18. #18

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    ok.

    so i call the loader function on WM_CREATE and then the Unload function on WM_DESTROY ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  19. #19
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I would use WM_CLOSE not WM_DESTORY
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  20. #20

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    yea, thats what i thought when i was looking thru the case functions since wm destroy gets called last and wm close fires the wm destroy message i figured it would be better
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  21. #21
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Yep. You mess around in Destroy and sometimes your program gets hozed. If it still flashes after this, post the new code and I will check it out for you again.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  22. #22

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    ok made the loader/unloader functions

    i have a wierd problem now, i call the loader function on WM_CREATE which does the following

    Code:
    void Load_Bmp_Globals()
    {
    	MAINBMP = LoadBitmap(h_Inst, "IDBMAIN");
    
    	hdcWindow = GetDC(Main_Hwnd);
    	hdcMemory = CreateCompatibleDC(hdcWindow);
    
    	SelectObject(hdcMemory, MAINBMP);
    }
    then on WM_CLOSE i call the unloader which does the following

    Code:
    void Unload_Bmp_Globals()
    {
    	DeleteDC(hdcMemory);
    
    	delete MAINBMP;
    	delete hdcMemory;
    	delete hdcWindow;
    }
    the problem is now i get a really really wierd reaction. now after i execute my program, it loads fine but when i move the window to another location on my screen, the bitblt gets blitted to the desktop in the location that the program orginally started up at and my actual form goes blank... if click where the rewind button is supposed to be, nothing appears on the main form but in the image thats being blitted to the forms original location, the proper function happens! LOL do u know whats wrong ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  23. #23
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Nothing jumps out at me. Post the code please and I will check it out.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  24. #24

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    heres the project..
    Attached Files Attached Files
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  25. #25
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ok the DC for the window changes before and after WM_CREATE. You need to put hdcWindow = GetDC(Main_Hwnd); into your Redraw_Skin()

    Also remove the Redraw_Btn_Rect() you dont need it and its slowing you down.

    Try that.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  26. #26

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    i do need the redraw_btn_rect, otherwise my form will not display the appropiate image. i also tried updatewindow but that didn't work....
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  27. #27
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Works just fine with out that. Did you try with out it?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  28. #28

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    yes i did try it without it, send me the project u have so i can see if maybe u did something different or something
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  29. #29
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Here
    Attached Files Attached Files
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  30. #30

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ok i got it, i had put DeleteDC in the Draw_Skin Function for some reason, so i took it out and put it in the Unload_Bmp_Globals and now it works fine thanx for your help i really appreciate it

    Laterz,
    AAG
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  31. #31
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Cool, glad to help.

    If you ever want to BitBlt is a great way to do it easily, but its a memory hog. If you ever want to do it faster and better you can use Direct Draw.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  32. #32

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    how does winamp do it, i'm sure they use bitblt and stretchblt right ??
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  33. #33

    Thread Starter
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    got a new problem :(

    ok got a new wierd problem. i have create a dialog resource box, set its window property to popup and its style to none... its callback is BOOL, what properties does this type of callback have... like for instance it doesn't seem to have a WM_SIZE.. i couldn't find anything in the SDK either can u give me some help on this... i tried register a new WndClassEx and create a new window and that worked fine and i got all the stretching and blt and resizing for the skinned form working perfect except for some strange reason in XP the forms would work fine but in 98 the main form would get mixed up with the resizable form, i think it deals with how XP and 98 handle memory operations or something but i don't see why it would be a problem if i was using totally different hwnds and HTBITMAPS and dc and dc memory objects as well, or it could have been the way i created the new window, perhaps they were running in the same process or something i don't know and got confused LOL or something...
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  34. #34
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I believe that in ver 2 (The most current version) of Winamp they did use BitBlt. In ver 3 (In Beta) they are using Direct Draw.


    For your Dialog box use the function DialogBox

    Here is an example of one I used

    PHP Code:
    void OptionDisplayWindow()
    {
      
    DialogBox((HINSTANCE)g_hInst_OptionsMAKEINTRESOURCE(IDD_OPTIONS), g_hWnd, (DLGPROC)OptionsProc);
    }

    BOOL CALLBACK OptionsProc(HWND hWndUNIT uMsgWPARAM wParamLPARAM lParam)
    {
      switch(
    uMsg)
      {
        case 
    WM_INITDIALOG:
        {
          
    ReadValues();
          
    SetValues();
          break;
        }
        case 
    WM_DESTROY:
        {
          
    EndDialog(hWndNULL);   //<----Important
          
    break;
        }
       default:
          break;
      }

    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  35. #35
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    are you sure they use DD? As far as I know, it is a ***** to use in windowed mode.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  36. #36
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I am not 100% sure that they are using DD (Well technically its not even that DX8 and above anymore. But its to early for me to remember what its called right now) but thats what the rumor is. Its really not that hard when you use all the built in functions that DX provides. Infact it takes about half the code to do it in DD than BitBlt if you do it right.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  37. #37
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    but with BitBlt you don't have to worry about color modes, with DD you have
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width