Stupid Question.........

This is a discussion on Stupid Question......... within the Windows Programming forums, part of the Platform Specific Boards category; Code: const int BITMAPHEIGHT=32; const int BITMAPWIDTH=64; ////////////////////////////////////////////////////////////////////////////// //PROTOTYPES ////////////////////////////////////////////////////////////////////////////// bool Prog_Init();//game data initalizer void Prog_Loop();//main game loop void Prog_Done();//game ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Arrow Stupid Question.........

    Code:
    const int BITMAPHEIGHT=32;
    const int BITMAPWIDTH=64;
    
    //////////////////////////////////////////////////////////////////////////////
    //PROTOTYPES
    //////////////////////////////////////////////////////////////////////////////
    bool Prog_Init();//game data initalizer
    void Prog_Loop();//main game loop
    void Prog_Done();//game clean up
    
    //////////////////////////////////////////////////////////////////////////////
    //GLOBALS
    //////////////////////////////////////////////////////////////////////////////
    HINSTANCE hInstMain=NULL;//main application handle
    HWND hWndMain=NULL;//handle to our main window
    //memory dc
    HDC hdcMem=NULL;
    //bitmaps
    HBITMAP hbmNew=NULL;
    HBITMAP hbmOld=NULL;
    
    //////////////////////////////////////////////////////////////////////////////
    //WINDOWPROC
    //////////////////////////////////////////////////////////////////////////////
    LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    	//which message did we get?
    	switch(uMsg)
    	{
    	case WM_LBUTTONDOWN:
    		{
    			//borrow dc from main window
    			HDC hdc=GetDC(hWndMain);
    
    			//blit from the memory dc to the window's dc
    			BitBlt(hdc,LOWORD(lParam)-BITMAPWIDTH/2,HIWORD(lParam)-BITMAPHEIGHT/2,BITMAPWIDTH,BITMAPHEIGHT,hdcMem,0,0,SRCCOPY);
    
    			//return the borrowed dc to the system
    			ReleaseDC(hWndMain,hdc);
    
    			//handled, so return 0
    			return(0);
    		}break;



    Ok this is a problem I am having with the BitBlt Function.
    Warning!!! Some questions might sound stupid, but the problem is that I am really a newbie......

    const int BITMAPHEIGHT=32; //Why is this initialized as the size?
    const int BITMAPWIDTH=64;//same here

    BitBlt(hdc,LOWORD(lParam)-BITMAPWIDTH/2,HIWORD(lParam)-BITMAPHEIGHT/2,BITMAPWIDTH,BITMAPHEIGHT,hdcMem,0,0,SRCCOPY);


    Ok, the book says that the second and third parameter are the destion of the x and y coordinate of the bitmap respectively........why is the height of the bitmap divided by two? Warning stupid question coming.........and what does it have that little "-" Sign before the BITMAPWDTH parameter.........

    Please help...I need to know this before I continue......
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    From MSDN:

    BOOL BitBlt(
    HDC hdcDest, // handle to destination device context
    int nXDest, // x-coordinate of destination rectangle's upper-left
    // corner
    int nYDest, // y-coordinate of destination rectangle's upper-left
    // corner
    int nWidth, // width of destination rectangle
    int nHeight, // height of destination rectangle
    HDC hdcSrc, // handle to source device context
    int nXSrc, // x-coordinate of source rectangle's upper-left
    // corner
    int nYSrc, // y-coordinate of source rectangle's upper-left
    // corner
    DWORD dwRop // raster operation code
    );

    When the msg is a mouse message (ie: WM_LBUTTONDOWN)
    (LOWORD)lparam is the current mouse x coord.
    (HIWORD)lparam is the current mouse y coord.



    By subtracting half of our Bitmap width from the x coord we blit our bitmap positioned on the screen with the current mouse x coord as it's center (same goes for the y and Bitmap height).

    The "-" is the subtraction operator. Used to get the proper left/top coords to "center" our blitted bitmap based on the current mouse coord.
    Last edited by jdinger; 04-06-2002 at 08:35 PM.

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    (LOWORD)lparam is the current mouse x coord.

    (HIWORD)lparam is the current mouse y coord.


    Thank you, why couldn't the book had just said so....God


    By subtracting half of our Bitmap width from the x coord we blit our bitmap positioned on the screen with the current mouse x coord as it's center (same goes for the y and Bitmap height).

    not quite sure I follow......sorry.........



    const int BITMAPHEIGHT=32;
    const int BITMAPWIDTH=64;

    is this the size of the window or the bitmap? If it is of the bitmap how do we know this is the size of the bitmap?


    Thank you once again.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    BitBlt(hdc,LOWORD(lParam)-BITMAPWIDTH/2,HIWORD(lParam)-BITMAPHEIGHT/2,BITMAPWIDTH,BITMAPHEIGHT,hdcMem,0,0,SRCCOPY);


    I think I got it........this makes the mouse insert the image while pointing to the center of the bitmap...........32/2=center?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by elchulo2002
    not quite sure I follow......sorry.........
    In that particular example you want to draw the bitmap onto the screen each time you click. You want to draw it with it's center based on wherever the mouse was when you clicked.

    You clicked at coord (10,10)
    Your bitmap is 20x20
    (LOWORD)lparam-BITMAPWIDTH/2 = 20 - (20/2) *which* = 10
    (HIWORD)lparam-BITMAPHEIGHT/2 = 20 - (20/2) *which* = 10

    so your bitmap with be drawn in the upper left hand corner.

    Once you compile the example notice that where ever you click the bitmap is drawn "centered" on you mouse.

    const int BITMAPHEIGHT=32;
    const int BITMAPWIDTH=64;

    Originally posted by elchulo2002
    is this the size of the window or the bitmap? If it is of the bitmap how do we know this is the size of the bitmap?
    This is the size of the bitmap.

    Normally you would grab the bitmap width/height with GetObject. The author just hard coded it here for simplicities sake.

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by elchulo2002
    BitBlt(hdc,LOWORD(lParam)-BITMAPWIDTH/2,HIWORD(lParam)-BITMAPHEIGHT/2,BITMAPWIDTH,BITMAPHEIGHT,hdcMem,0,0,SRCCOPY);


    I think I got it........this makes the mouse insert the image while pointing to the center of the bitmap...........32/2=center?
    I was typing my last reply when you posted this.

    Yes. That's the way it works.

  7. #7
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Thank you very much Jdinger for your time, and patience.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-03-2005, 11:17 PM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 07:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21