Question about the windows routine...

This is a discussion on Question about the windows routine... within the Windows Programming forums, part of the Platform Specific Boards category; This is a well commented example, I am having problem following the course of a Win32 Program.........Like where it starts ...

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

    Question about the windows routine...

    This is a well commented example, I am having problem following the course of a Win32 Program.........Like where it starts and everything could someone by looking at this example tell me?


    I mean like it starts in WinMain then in checks for messages if it's a WM_LBUTTONDOWN, then this or that runs......but I am having problem knowing when Prog_Init () is actually run and stuff...Please I cannot go on with this book if I don't understand. Thank you, hey the code is well commented.
    Attached Files Attached Files
    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
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Never mind that I think I got it.........Now I want to know what happens between the two cases WM_LBUTTONDOWN and WM_MOUSEMOVE........how do those two cases move back and forth?
    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.

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    no replyes huh? Oh well this is what I think, tell me if I am close......


    Code:
    
    case WM_LBUTTONDOWN:
    		{
    			//extract x and y from lparam
    			int x=LOWORD(lParam);
    			int y=HIWORD(lParam);
    
    			//borrow the main window's DC
    			HDC hdc=GetDC(hWndMain);
                 //moves from here to
    			//update the CP
                ///here?
    			MoveToEx(hdc,x,y,NULL);
    
    			//return the dc to the system
    			ReleaseDC(hWndMain,hdc);
    
    			//handled, return 0
    			return(0);
    		}break;
    	case WM_MOUSEMOVE:
    		{
    			//if left button is down
    			if(wParam & MK_LBUTTON)
    			{
    				//extract x and y from lparam
    				int x=LOWORD(lParam);
    				int y=HIWORD(lParam);
    
    				//borrow the main window's DC
    				HDC hdc=GetDC(hWndMain);
    
    				//line to the x,y position
    				LineTo(hdc,x,y);
                    //here and then switches back when you're not
                    //moving it to.......
    
    				//return the dc to the system
    				ReleaseDC(hWndMain,hdc);
    			}
    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
    This is my analogy please clarify...........

    This happens when you press the mouse button;

    //this would be to set a starting point
    int x=LOWORD(lParam);
    int y=HIWORD(lParam);
    HDC hdc=GetDC(hWndMain);


    Then the Mouse is Moved........then this is happens......


    case WM_MOUSEMOVE:
    {

    if(wParam & MK_LBUTTON)
    {

    int x=LOWORD(lParam);
    int y=HIWORD(lParam);


    HDC hdc=GetDC(hWndMain);


    LineTo(hdc,x,y);


    ReleaseDC(hWndMain,hdc);

    }}



    Once the mouse stops moving. Then this would bring you over to this MoveToEx(hdc,x,y,NULL); which updates our points again so that this is on a strait line if you want to be when you keep drawing.........am I on the right track.



    This
    int x=LOWORD(lParam);
    int y=HIWORD(lParam);
    HDC hdc=GetDC(hWndMain);
    LineTo(hdc,x,y);


    takes the coordinates after you move the mouse to the second coordiates and put the lines from our starting point on the first WM_LBUTTONDOWN up to this.......then our coordinates are update when they're put on the CP.......Please people comment on this or correct me if I am wrong.


    [EDIT] Someone said that I kept on replying to my post for my "post count" as some of you might know once I hit 400 I stopped caring about those, so I am doing this edit, the reason why I reply to some of my posts is that first I post a code and then I comment below it...because it's kinda hard with the formatting to do that sometimes, also I post something, and then about 5 minutes later I learn something new which might apply to what I recently posted so I go back and check on it and commenet on it or something...... [EDIT]
    Last edited by incognito; 03-25-2002 at 08:57 PM.
    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
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Not quite, every move of the mouse will draw the line, if it draws at all.
    It may not draw if there is no Bitmap in the HDC, if there is no pen in the HDC or because the HDC is never drawn to the screen. (If you change the HDC contents, VERY carefully replace the original GDI resouces and DeleteObject() the created ones)

    What happens? What is the problem?

    A better way would be to keep the start points as a static and then do the lineto() after the button on the mouse is released, WM_LBUTTONUP.

    I don't know if your method will work. Is roughly OK except that there is no function to redraw the screen. Mostly I use a frame buffer system (do a search as I have already posted the code before) and handle WM_PAINT msg's.

    this might help, takes a mouse msg lParam and turns it into first a POINTS (short int) to a POINT (int) and converts from client to a screen cood.

    Code:
    POINTSTOPOINT(ptsBegin,MAKEPOINTS(lParam));
    CopyMemory(&ptScreenBegin,&ptsBegin,sizeof(POINT);
    ClientToScreen(hWnd,&ptScreenBegin);
    Other handy func incl
    PtInRect() (finds if the POINT is inside the right area.)
    ClipCursor() (confines the mouse to an area.)

    PS Give us some time to respond, we are in different time zones / days.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    This function works I just wanted to think of a way that this happens......to kinda of have a picture of it in my mind.



    I just want to know what's the routine when you press the mouse which part of the program is called, I am having problem understanding that, please explain if you can .
    Last edited by incognito; 03-26-2002 at 10:44 AM.
    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.

  7. #7
    Unregistered
    Guest
    sorry but bump.

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    >>I just want to know what's the routine when you press the mouse which part of the program is called, I am having problem understanding that, please explain if you can

    I don't really get what your asking, but here goes:
    All messages are recieved by your programme's message loop. The Dispatch message then passes that message to the message processing function. The case statment you included parts of then decides on the code that should be executed.
    I hope that helps.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>HDC hdc=GetDC(hWndMain);

    This is evil!

    To not do this in a callback. Better yet do not do this.

    If you 'get' a GDI you MUST 'release' it. In a callback literally hundreds of msg's are passing thru a second. Each looses another HDC.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Ok but these specific cases the functions inside the cases is that I don't understand, I want to know which case is called when the mouse is pressed, then when the other one is called, also when the function inside of these cases are executed, basically I dont' understand these functions.........PLEASE I love you all....


    Code:
    case WM_LBUTTONDOWN:
    		{
    			//extract x and y from lparam
    			int x=LOWORD(lParam);
    			int y=HIWORD(lParam);
    
    			//borrow the main window's DC
    			HDC hdc=GetDC(hWndMain);
                 //moves from here to
    			//update the CP
                ///here?
    			MoveToEx(hdc,x,y,NULL);
    
    			//return the dc to the system
    			ReleaseDC(hWndMain,hdc);
    
    			//handled, return 0
    			return(0);
    		}break;
    	case WM_MOUSEMOVE:
    		{
    			//if left button is down
    			if(wParam & MK_LBUTTON)
    			{
    				//extract x and y from lparam
    				int x=LOWORD(lParam);
    				int y=HIWORD(lParam);
    
    				//borrow the main window's DC
    				HDC hdc=GetDC(hWndMain);
    
    				//line to the x,y position
    				LineTo(hdc,x,y);
                    //here and then switches back when you're not
                    //moving it to.......
    
    				//return the dc to the system
    				ReleaseDC(hWndMain,hdc);
    			}
    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.

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Not sure I understand what you want.

    When you press the left mouse button the OS generates a message, WM_LBUTTONDOWN. This is sent to your app if the mouse was pressed inside one of your windows / dialogs. It contains data (LPARAM,WPARAM) on what / where happened.

    If you are looking for mouse msg's your code under the case is executed, otherwise the msg will be passed on to the default processing thru your

    DefFrameProc(); or DefWinProc() call.

    and the standard processing takes place. If you want to do something different your write code and intercept the msg before it can be handled in the default manner.

    EVERY move of the mouse in your app will generate a move msg. Depends on the speed of your PC but could be every pixell.

    Or are you saying you don't understand the actual code.
    int x=LOWORD(lParam);//get X cood of where the mouse was pressed from the extra data sent with the msg.
    hdc=GetDC(hWndMain);//find the standard handle to a device context so we can draw on the main screen

    A DC contains a BMP to draw on with the PEN, BRUSH or FONT selected into it. These can be changed with SelectObject(). You create them, select into DC, draw and then delete the objects. They use resources known as GDI's (Graphice Device Interface)

    MoveToEx(hdc,x,y,NULL);//set the starting point for the line to be draw on the main screen
    LineTo(hdc,x,y);//draw a line from the starting point to the new coods

    ReleaseDC(hWndMain,hdc);//return the HDC or loose mem (if an object (pen, brush ect) has been changed the default / original MUST be replaced before Released [if GetDC()] or DeleteDC() [if CreateDC()]
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  12. #12
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    So this would Extract the coordinates of where you let go of the mouse after you move it?

    if(wParam & MK_LBUTTON)
    {

    int x=LOWORD(lParam);
    int y=HIWORD(lParam);


    you know I mean extracts the coordinates of where you let go of the line and then makes a line with the pen from the first coordinates to these?


    after this case is excuted and you make another line again, does it goes back to this case ...case WM_LBUTTONDOWN:? To start making another line?Thank you for your help people.


    If so I have another question is //return the dc to the system
    ReleaseDC(hWndMain,hdc);
    on the case WM_LBUTTONDOWN: released before moving on to this other case case WM_MOUSEMOVE:
    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.

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>extracts the coordinates of where you let go of the line?

    Yes, (if the whole thing works). You may not see anything for reasons I have already mentioned.

    Every time you press the left mouse button it goes and resets the pen position.

    I think LineTo() will also update the pens position, so you may get a line drawn in the mouse's path, not a straight line from the point you pressed the button to the point you let go. (but I'm not 100% on that)

    Second question
    Yes

    Think of the callback as a being inside an infinite while loop (until the app ends). Messages are constantly flowing thru (hundreds per second). You process only a tiny fraction and let most msg's go past.


    The names in this code look very familar. Where did you get it?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  14. #14
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I got this from Isometric Game Programming with Direct X 7.0. I have a question though, when the pen draws a line from one coordinate to the other is everything done pixel by pixel? Or one single line, if it is one single line how come lthe line is not just stragith? (if you don't not understand my question let me know ) I mean when the line is made with the pen even if you don't let go of the mouse and you make curves of the lines pixel by pixel or how, is the line the path of where the mouse traveled through?

  15. #15
    incognito
    Guest
    Maybe the as you move the mouse this case WM_MOUSEMOVE:
    is called every single pixel therefore you can make curves when you make a line because this is called every single pixel, how does that sound?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. General question from a beginner to Windows C++ programming
    By Kontan in forum Windows Programming
    Replies: 1
    Last Post: 09-29-2006, 08:03 PM
  2. Replies: 5
    Last Post: 08-16-2006, 02:05 PM
  3. Two Windows on two different HDD??? Question
    By Sevrin in forum Tech Board
    Replies: 6
    Last Post: 06-19-2003, 10:22 AM
  4. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  5. Another windows service question... starting/stopping
    By BrianK in forum Windows Programming
    Replies: 1
    Last Post: 03-19-2003, 11:22 PM

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