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 8034991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:10:53+00:00 2026-06-05T02:10:53+00:00

This code displays a window with a text label saying: Please Enter A Number,

  • 0

This code displays a window with a text label saying: “Please Enter A Number”, and a button.

When you click the button it should replace the text with ” TEXT “. It works, but it writes/prints the new text on top of the first text. So its overlapping.

I want the string of text to change instead of writing over the first one, but I don’t know how as I’m new to windows application development.

Please help me out guys.

The whole source is:

#include <windows.h>
#include <iostream>


using namespace std;


enum { ID_LABEL = 1,ID_BUTTON0};

static  HWND static_label, button0;

HDC          hdc;
HBRUSH  NewBrush;
HINSTANCE g_hInst;


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    LPCTSTR className = TEXT("myClass");
    WNDCLASSEX wc;

    wc.cbSize        = sizeof(wc);
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.cbWndExtra    = 0;
    wc.cbClsExtra    = 0;
    wc.lpfnWndProc   = WndProc;
    wc.hInstance     = hInstance;
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = TEXT("myClass");


    wc.hbrBackground  = (HBRUSH)(CreateSolidBrush(RGB(48, 38, 88)));

    wc.hIcon             = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm           = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor           = LoadCursor(NULL, IDC_ARROW);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, TEXT("ERROR! FAILED TO REGISTER CLASS!"), TEXT("FATAL ERROR!"), MB_IConerror | MB_OK);
        return 1;
    }

    HWND hwnd = CreateWindowEx(0, TEXT("myClass"), TEXT("WINDOW TITLE"), WS_OVERLAPPEDWINDOW, 450, 100, 500 + 7, 500 + 33 , NULL, NULL, hInstance, NULL);

    if(!hwnd)
    {
        MessageBox(NULL, TEXT("ERROR! FAILED TO CREATE WINDOW!"), TEXT("FATAL ERROR!"), MB_IConerror | MB_OK);

        return true;
    }  

    ShowWindow(hwnd, nShowCmd);                
    UpdateWindow(hwnd); 

    MSG msg;

    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}



LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_PAINT:
        {

        }

        case WM_CTLCOLORSTATIC:
        {
           SetBkMode((HDC) wParam, TRANSPARENT);        

           return (LONG) GetStockObject(NULL_BRUSH);
    }

    break;

    case WM_CREATE:
    {
        static_label = CreateWindow(L"Static",L"Please Enter A Number",WS_CHILD | WS_VISIBLE,35,15,175,25,hwnd,0, g_hInst,0);

        button0 = CreateWindow(L"Button",L"OK",BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE ,80,220,35,35,hwnd,(HMENU)ID_BUTTON0,g_hInst,0);   
      }

      break;

      case WM_COMMAND: //Command from Child windows and menus are under this message

      switch(wParam) //the ID is wParam
      {
         case ID_BUTTON0: //check for our button ID
         {
             SetWindowText(static_label,L"TEXT");

             break;
         }
      }//switch. 

  break;

  case WM_DESTROY: 
         PostQuitMessage(0);
         break; // pass to DefWindowProc(...) as well

      case WM_CLOSE:
         DestroyWindow(hwnd);
         break;
   } 

    return DefWindowProc(hwnd, msg, wParam, lParam);    
}
  • 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-05T02:10:54+00:00Added an answer on June 5, 2026 at 2:10 am

    The problem is here:

    case WM_CTLCOLORSTATIC:
    {
       SetBkMode((HDC) wParam, TRANSPARENT);        
       return (LONG) GetStockObject(NULL_BRUSH);
    }
    

    This code tells the static control to draw the text without a background color and not to repaint the background. So the new text is drawn on top of the old text instead of on a fresh background.

    If you need some custom background to show through, then you’ll have to invalidate that part of the underlying parent window and possibly use something like WS_EX_TRANSPARENT to ensure the child static control is drawn last. That way, by the time it tries to draw the new text, a fresh background should be painted.

    Note that this means you cannot use WS_CLIPCHILDREN on the underlying parent window, which can increase flicker when things redraw.

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

Sidebar

Related Questions

This code should generate a page that displays a random number. Why doesn't it
This code correctly fetches data, and displays it; however, the sort is completely ignroed.
I am using this code to display a grid $('#table1 tr').bind('click', shows); function shows()
As far as I can tell, this code is fine, and should display some
I'm trying to add a control(Label) inside of a panel. Please see the code:
This time my test code displays a TextBox and two TextBlocks. The TextBox and
It seems to me that the following code should display text right in the
I have this code: def display(self): print self.doc.toprettyxml(indent= ) strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) +
I have this code to display the data retrieved from DB in accounts_view.php :
This code lets me display/hide a custom message msg_one msg_two msg_three when the appropriate

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.