Thread: Control problems.. where are they?

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    Control problems.. where are they?

    Can someone give me some insight as to why this will display no error message, nor will it display the actual control? I am doing this in the WM_CREATE message of my main windows message handler. Here is one of the controls I'm trying to create:

    Code:
    if( (hcowner = CreateWindow("EDIT", "", WS_VISIBLE | WS_DISABLED | WS_CHILD | WS_CLIPCHILDREN, x, y, 200, 40, hwnd, NULL, g_hInst, NULL)) == NULL )
    			{
    				sprintf(error, "Could not initialize controls. (Error Code: 0006; %u)", GetLastError());
    				MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    				return(0);
    			}
    the x and y values have been set according to the GetClientRect() call and - or + values to the returned co-ords from that call.

    Any help is appreciated,
    Tyouk

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Your edit control is being created but, with the WS_DISABLED style, is probably invisible against the parent's background (a disabled edit control's background colour defaults to COLOR_BTNFACE, see GetSysColor). For testing purposes you might consider giving the control a border style (or extended style if using CreateWindowEx) or setting some text via the lpWindowName of CreateWindow/Ex; that way you'll at least have a visual cue of the window's existence.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    132
    The problem isn't with the background. I am also creating STATIC controls in the same method and it's still not producing anything for me. I see no text, even though I have set text (no point to creating a STATIC control without text).

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    why don't you post some more code. Maybe that will elicit more help.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The problem isn't with the background. I am also creating STATIC controls in the same method and it's still not producing anything for me. I see no text, even though I have set text (no point to creating a STATIC control without text).
    Pity: I was fairly certain that, given the code and description you had supplied, the control was being created but was simply not visible.

    If you haven't already done so, here's some things to check:
    • IsWindow on the parent handle and the return value from CreateWindow.
    • Is g_hInst valid? Try replacing it with GetModuleHandle(0).
    • Replace x and y with absolute values.
    • Create a small, test windows application that uses similar code to create these various controls. Can you replicate the problem with this example?

    If you still have problems then post the test example code; if you work out what the problem is then post a description of the solution so that others may benefit.

    Good luck and Happy New Year.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay my problem was with the x and y values. I tried each of your suggestions (from top to bottom) and as soon as I got to that, I now can see one of the controls. I guess when I called the...

    Code:
    RECT rect;
    
    GetClientRect(hwnd, &rect);
    It's values were messing things up. I'm going to see what values are returned from that call and see what I can do from there. The x and y values where being determined in a fashion such as:

    Code:
    x = rect.left + xlspace;
    xlspace was a value determined based on how far from the left this control needed to be placed, but I think I could just place xlspace in the parameter where it asks for the x value because from what I can tell it would place it exactly where it needs to go

    I'm trying to keep the controls relative to a certain position on the screen (and during WM_SIZE messages I am calling the MoveWindow() call in order to make sure that the controls stay relative to the same spots so then the look stays the same).

    Thanks for your help,
    Tyouk
    Last edited by tyouk; 01-01-2005 at 04:56 PM. Reason: Adding more to solution to problem.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Ummmm....

    your using the CHILD style but not setting the controls ID number (you set them all to NULL). This may cause problems as multiple controls of the same parent can/should not have the same ID number.

    cast the HMENU param to a #define ID number

    #define IDC_SOME_EDIT 30001

    CreateWindow(........., (HMENU)IDC_SOME_EDIT,.....)
    "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

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    132
    Ya I was going to get to that a little bit later. Didn't think it was that important to have them all ID'd right off the bat.

    I'll add that though. I got them visible already though.

    Thanks,
    Tyouk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  2. tab control
    By tyouk in forum Windows Programming
    Replies: 6
    Last Post: 02-07-2005, 11:47 PM
  3. Tree View control not appearing
    By Garfield in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 01:47 PM
  4. creating an activex control
    By Benzakhar in forum Windows Programming
    Replies: 9
    Last Post: 12-29-2003, 06:32 PM
  5. Updating a list control
    By MPSoutine in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2003, 02:03 AM