Change a control class during runtime

This is a discussion on Change a control class during runtime within the Windows Programming forums, part of the Platform Specific Boards category; Hi Is it possible to change a classname during runtime? For example: I have created a single line static control... ...

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308

    Lightbulb Change a control class during runtime

    Hi

    Is it possible to change a classname during runtime?

    For example:

    I have created a single line static control... during runtime convert the static into a edit control, preserving same x,y,w,h dimensions.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    1. Get the position of the control: GetClientRect
    2. Destroy the old control: DestroyWindow
    3. Create the new control with stored position: CreateWindowEx

    However, a far better solution may be to use an edit control only and set the read-only style as required. This can be done with the EM_SETREADONLY message.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Another option is to hide one control and show other control. This is helpful if the controls are very different types or you want to change multiple times.

    Set the controls WS_VISIBLE style in the resource editor or when creating the control. As required use ShowWindow() (SW_SHOW==visible and SW_HIDE==invisible).

    In this case I think the read only / disabled edit is the best idea.
    "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

  4. #4
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Thanks for your replies:
    Code:
    HWND hIcon = FindWindowEx(HWND(wParam), 0, "STATIC", 0);
    				HWND hText = FindWindowEx(HWND(wParam), hIcon, "STATIC", 0);
    				GetWindowRect(hText, &rctxt);
    				OffsetRect(&rctxt, -rctxt.left, -rctxt.top);
    				DestroyWindow(hText);
    				HWND hLink = CreateWindowEx(0, "SysLink", "Hola, mi <A HREF=\"http://www.joelito.net/\">sitio</a>, bye.", WS_CHILD|WS_VISIBLE|WS_TABSTOP, 0, 0, rctxt.right-rctxt.left, rctxt.bottom-rctxt.top, HWND(wParam), HMENU(1006), GetModuleHandle(0), 0);
    				SetWindowPos(hLink, 0, rctxt.left, rctxt.bottom, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
    This is what I have...my only problem is rctxt.left because isn't in the right place, anyideas?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 09:44 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Control class
    By Mithoric in forum Windows Programming
    Replies: 0
    Last Post: 11-28-2003, 08:35 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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