Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I want to show a line in a window

I want to show a line in a window

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bloodwinner
    wrote on last edited by
    #1

    by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?

    _ H C S 4 Replies Last reply
    0
    • B bloodwinner

      by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      What problem with this code? and i said you about WM_CREATE & WM_PAINT

      _**


      **_

      WhiteSky


      B 1 Reply Last reply
      0
      • B bloodwinner

        by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        bloodwinner wrote:

        case WM_CREATE to realise it

        WM_CREATE: The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible. WM_PAINT: The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window ie when we want to draw something on the window.

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

        1 Reply Last reply
        0
        • H Hamid Taebi

          What problem with this code? and i said you about WM_CREATE & WM_PAINT

          _**


          **_

          WhiteSky


          B Offline
          B Offline
          bloodwinner
          wrote on last edited by
          #4

          there is nothing wrong with the code, I just want to know, why can't I move this code into WM_CREATE to get the same result- just draw a line in the window when the window is created.

          C H 2 Replies Last reply
          0
          • B bloodwinner

            there is nothing wrong with the code, I just want to know, why can't I move this code into WM_CREATE to get the same result- just draw a line in the window when the window is created.

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            Because when it receives the WM_PAINT message, the window will be redrawn and thus if you don't redraw your line too, it will be erased.


            Cédric Moonen Software developer
            Charting control [Updated - v1.1]

            1 Reply Last reply
            0
            • B bloodwinner

              by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Run notepad, and calculator. Drag the notepad over the calculator. Move it away. Why does the calculator redraw itself ? The answer is, it generates a WM_PAINT message, windows uses this to tell a window to repaint itself. If you draw outside WM_PAINT, then your window will lose what you draw when it redraws itself.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              1 Reply Last reply
              0
              • B bloodwinner

                there is nothing wrong with the code, I just want to know, why can't I move this code into WM_CREATE to get the same result- just draw a line in the window when the window is created.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                And From the MSDN: WM_CREATE: This message is sent when an application requests that a window be created

                _**


                **_

                WhiteSky


                1 Reply Last reply
                0
                • B bloodwinner

                  by adding these code to the case WM_PAINT: hdc = BeginPaint(hWnd, &ps); MoveToEx (hdc, 100, 100, NULL) ; LineTo (hdc, 100, 200) ; EndPaint(hWnd, &ps); why can I adding them to the case WM_CREATE to realise it?

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  Because when Windows wants to repaint a window, because an obscured part was exposed or for another reason, it sends a WM_PAINT message to the window to get it to repaint itself. If you put the rendering code elsewhere you'll see the rendering but when a part of the window is obscured and then exposed (or for some other reason needs to be re-rendered) the WM_PAINT handler will regenerate the image but it will not include the line. Aside from this I suspect the WM_CREATE handler is too early anyway. This situation is set to change with Vista's DWM but still the WM_PAINT handler will remain the correct place to perform most rendering operations.

                  Steve

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups