Thread: Child Window Text/Buttons Missing [WIN32 API/C++/VS 2010]

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    32

    Child Window Text/Buttons Missing [WIN32 API/C++/VS 2010]

    I have a parent window and two children windows. I want the child windows to display text, buttons, text fields, and a checkbox. I remembered to specify the WS_EX_CONTROLPARENT argument in the main window definition, so I don't think the parent window is my problem.

    Here are the windows that I declare (they are in the WM_CREATE case):
    Code:
    HWND win1 = CreateWindowExW(NULL,
            L"STATIC",
            NULL,
            WS_VISIBLE|WS_CHILD|SS_EDITCONTROL,
            10,//x
            50,//y
            400,//width
            200,//height
            hwnd,
            HMENU(WIN1),
            GetModuleHandle(NULL),
            NULL);
    
        HWND win2 = CreateWindowExW(NULL,
            L"STATIC",
            NULL,
            WS_VISIBLE|WS_CHILD|SS_EDITCONTROL,
            10,//x
            300,//y
            200,//width
            450,//height
            hwnd,
            HMENU(WIN2),
            GetModuleHandle(NULL),
            NULL);
    
        HWND button1 = CreateWindowExW(NULL,
            L"BUTTON",
            L"BUTTON1",
            WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
            25,//x
            200,//y
            150,//width
            24,//height
            win2,
            (HMENU)BUTTON1,
            GetModuleHandle(NULL),
            NULL);
    
        HWND button2 = CreateWindowExW(NULL,
            L"BUTTON",
            L"BUTTON2",
            WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
            25,//x
            250,//y
            150,//width
            24,//height
            win2,
            (HMENU)BUTTON2,
            GetModuleHandle(NULL),
            NULL);
    
        HWND check = CreateWindowExW(NULL,
            L"BUTTON",
            NULL,
            WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX,
            170,//x
            400,//y
            16,//width
            16,//height
            win2,
            HMENU(BUTTON3),
            GetModuleHandle(NULL),
            NULL);
    
        HWND text1 = CreateWindowExW(NULL,
            L"EDIT",
            NULL,
            WS_VISIBLE|WS_CHILD|WS_BORDER,
            150,//x
            400,//y
            25,//width
            16,//height
            win2,
            HMENU(TEXT1),
            GetModuleHandle(NULL),
            NULL);
    
        HWND text2 = CreateWindowExW(NULL,
            L"EDIT",
            NULL,
            WS_VISIBLE|WS_CHILD|WS_BORDER,
            150,//x
            650,//y
            25,//width
            16,//height
            win2,
            HMENU(TEXT2),
            GetModuleHandle(NULL),
            NULL);
    All of the above are then passed through EnableWindow() and set to TRUE.

    Here is all of my code for the WM_PAINT case:
    Code:
    HDC hdc = BeginPaint(hwnd, &ps);
            HDC hdc2 = BeginPaint(win1, &ps);
            HDC hdc3 = BeginPaint(win2, &ps);
    
            LPCWSTR title = L"Title";
            LPCWSTR win1Label[5] = {L"A", L"B", L"C", L"D",
                L"E"};
            LPCWSTR win2Label[7] = {L"E", L"F", L"G", L"H",
                L"I", L"J", L"K"};
            long lfHeightTitle = -MulDiv(20, GetDeviceCaps(hdc, LOGPIXELSY), 72);
            long lfHeightLabel = -MulDiv(12, GetDeviceCaps(hdc2, LOGPIXELSY), 72);
            HGDIOBJ titleFont = CreateFont(lfHeightTitle, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");
            HGDIOBJ win1Font = CreateFont(lfHeightLabel, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");
            HGDIOBJ win2Font = win1Font;
    
            SelectObject(hdc, titleFont);
            SetBkMode(hdc, TRANSPARENT);
            TextOut(hdc, 0, 0, title, 15);
            EndPaint(hwnd, &ps);
    
            SelectObject(hdc3, win2font);
            SetBkMode(hdc3, TRANSPARENT);
            TextOut(hdc3, 0, 0, win2Label[0], 1);
            TextOut(hdc3, 0, 50, win2Label[1], 1);
            TextOut(hdc3, 0, 100, win2Label[2], 1);
            TextOut(hdc3, 0, 150, win2Label[3], 1);
            //leave room for buttons!
            TextOut(hdc3, 0, 300, win2Label[4], 11);
            TextOut(hdc3, 0, 350, win2Label[5], 11);
            TextOut(hdc3, 0, 400, win2Label[6], 11);
            EndPaint(win2, &ps);
    
            SelectObject(hdc2, mainLabelFont);
            SetBkMode(hdc2, TRANSPARENT);
            TextOut(hdc2, 0, 0, win1Label[0], 1);
            TextOut(hdc2, 0, 20, win1Label[1], 1);
            TextOut(hdc2, 0, 40, win1Label[2], 1);
            TextOut(hdc2, 0, 60, win1Label[3], 1);
            TextOut(hdc2, 0, 80, win1Label[4], 1);
            EndPaint(win1, &ps);
    
            RedrawWindow(hwnd, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW);
            RedrawWindow(win1, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW);
            RedrawWindow(win2, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW);
    I should also point out that any rect validation makes my window flicker and that the text is Unicode-formatted (hence the L in front of all text).

    Is there any way I can print this text?

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    32
    I've discovered my problem. I needed to define 3 different HDCs and PAINTSTRUCTs.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why are you using Worst Interface 32 Awful Productiveness Interface instead of a GUI Framework, such as Qt?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    To reduce flicker add a WM_ERASEBKGND handler that just returns TRUE (indicating the msg was processed).

    You are getting flicker because you are trying to do a lot of drawing, GDI creation, etc within the paint handler (rather than using a form of double buffering).

    Normally a WM_PAINT handler consists of a BeginPaint, a BitBlt and an EndPaint.
    It should not contain any complex drawing, this should be done in response to otehr messages (WM_CREATE, WN_INITDLG or user action / input).
    These events should call the drawing code that updates a back buffer (memory DC) with the required changes and then generates a WM_PAINT msg.

    The WM_PAINT should be generated with a InvalidateRect using the smallest possible RECT (to ensure the fastest BitBlt) and UpdateWindow call (to bypass the OS msg queue where WM_PAINT has the lowest priority and will be ignored in favor of other messages)


    >>RedrawWindow(hwnd, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW)

    You know this creates a WM_PAINT msg? It should not be in your WM_PAINT handler as it has the potential to create an infinte loop.

    As WM_PAINT msgs are processed (concatinated) within the msg queue you are probably not yet experiencing the full impact of this code/bug.

    It also creates a WM_ERASEBKGRN message, which it then tries to supress. Not sure what that will do...


    >>Why are you using Worst Interface 32 Awful Productiveness Interface instead of a GUI Framework, such as Qt?

    Good to see you don't let your personal prejudices get in the way of you giving (useless) advice!

    Your post contributed NOTHING to this topic and appears that it was only posted to inflate your own ego by denegrating / mocking the choices made by others.

    In otherwords if you have nothing constructive to contribute to this topic, GTFO!
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parent window minimizing on child window destruction
    By Yarin in forum Windows Programming
    Replies: 1
    Last Post: 03-02-2008, 09:34 AM
  2. buttons won't work when in child window!?
    By psychopath in forum Windows Programming
    Replies: 5
    Last Post: 06-17-2004, 02:18 PM
  3. Child window inside child window
    By Magos in forum Windows Programming
    Replies: 13
    Last Post: 04-20-2004, 06:51 AM
  4. text box & buttons on window .. pls help urgent ???
    By intruder in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2002, 10:28 PM
  5. Win32 child window split bars
    By S in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2002, 03:42 AM

Tags for this Thread