Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:03:14+00:00 2026-06-06T23:03:14+00:00

I want to draw a line in a static control: case WM_CREATE: { hgraph=CreateWindow(WC_STATIC,NULL,WS_CHILD|WS_VISIBLE|SS_CENTER,20,20,660,80,hWnd,NULL,NULL,NULL);

  • 0

I want to draw a line in a static control:

case WM_CREATE:
    {
        hgraph=CreateWindow(WC_STATIC,NULL,WS_CHILD|WS_VISIBLE|SS_CENTER,20,20,660,80,hWnd,NULL,NULL,NULL);
        SendMessage(hgraph,WM_SETTEXT,NULL,(LPARAM) "My Static");
        break;
    }
    case WM_PAINT:
    {

        hdc=GetDC(hgraph);
        hp=CreatePen(0 ,5,RGB(0,100,0));
        SelectObject(hdc,hp); 
        MoveToEx(hdc, 0, 0, 0);
        LineTo(hdc, 100, 100);
        ReleaseDC(hgraph, hdc);
    }

    break;

but it goes under the static control:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:03:16+00:00Added an answer on June 6, 2026 at 11:03 pm

    When drawing to any child window, you need to do your drawing within the WM_PAINT of the child window procedure, not within the WM_PAINT of the parent window as you are doing.

    For system controls (e.g. statics), you need to subclass the window, which means that you need to replace the system-defined window procedure with your own. Once you have installed your own window procedure into the system control, you can catch the WM_PAINT event on the system control to do your painting.

    The complete procedure is as follows:

    1. Define your Replacement Window Procedure for the Static Control.

      We also must define a variable that we can use to store the original system Window Procedure for the control, which we must call at some point to allow the control to be drawn as normal.

      static WNDPROC pFnPrevFunc;
      
      static LRESULT CALLBACK ProcessStaticMessages(HWND hWindow,
                                                    UINT uMessage,
                                                    WPARAM wParam,
                                                    LPARAM lParam)
      {
          /*
           * call the original system handler so the control
           * gets painted as normal.
           */
          (*pFnPrevFunc)(hWindow, uMessage, wParam, lParam);
      
          /*
           * perform our custom operations on this control in
           * addition to system operations.
           */
          switch (uMessage)
          {
              ...
      
              case WM_PAINT:
                  /*
                   * static control has just been painted by system.
                   */
                  hDC = GetDC(hWindow);
      
                  /* draw your lines on the static control */
      
                  ReleaseDC(hWindow, hDC);
                  return TRUE;
          }
      
          return TRUE;
      }
      
    2. Create your static control window.

      hWndStatic = CreateWindow(WC_STATIC, (LPSTR) NULL, WS_CHILD|... );
      
    3. Subclass your static control window (install your window procedure)

      pFnPrevFunc = SetWindowLongPtr(hWndStatic,
                                     GWLP_WNDPROC,
                                     (LONG_PTR) ProcessStaticMessages);
      

    If this works correctly, then you should receive WM_PAINT messages inside your private message processing function for the static, and your drawing should occur correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to draw line, i have two textfiled in which i enter some
I want to draw line on UIImageView. I already draw line on UIImageView but
I want to Draw multiple line Graph with each line have different color and
I want to draw a line in Crystal report. I can do that from
I want to draw this in my view to draw this line, I have
I have a program where I want to draw a line between two points.
I want to draw a vertical line between the SectionIndex column and the cell
I want to draw a <hr> line in CSS. And there is a button
In my iPhone application i want do draw different shapes like line, circle and
I want to draw line from one point to another unknown point.I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.