child windows

This is a discussion on child windows within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I wrote this code to just get my child windows in position and everything before I continue to add ...

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    child windows

    Hi, I wrote this code to just get my child windows in position and everything before I continue to add the functionality of my program, but I have a porblem. It all compiles fine, but when I execute it, none of the child windows or the text come up. I'd also like to know how to make it so the maximise/restore buttons are greyed out.

    Thanks
    -Chris

    Here's the code:
    Code:
    // the basic template for TalkBack without any functionality
    
    #include <windows.h>
    HWND		  hinput;  // user input box
    HWND         houtput; // program output box
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("TalkBack v0.5 by Chris Pocock") ;
         HWND         hwnd ;   // main window
    
    	 MSG          msg ;
         WNDCLASS     wndclass ;
    
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
    
         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("'TalkBack' v0.5 by Chris Pocock"), // window caption
                              WS_OVERLAPPEDWINDOW,        // window style
                              CW_USEDEFAULT,              // initial x position
                              CW_USEDEFAULT,              // initial y position
                              455,                        // initial x size
                              232,                        // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
    
    
    		 
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         HDC         hdc ;
         PAINTSTRUCT ps ;
         RECT        rect ;
         
         switch (message)
         {
         case WM_CREATE:
    		GetClientRect (hwnd, &rect) ;
              hInst = ((LPCREATESTRUCT) lParam) -> hInstance ;
             hinput = CreateWindow ("User Input",             // window class name
                              NULL,                       // window caption
                              WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                                  WS_BORDER | ES_LEFT | ES_MULTILINE |
                                  ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,  // window style
                              7,                          // initial x position
                              21,                         // initial y position
                              225,                        // initial x size
                              45,                         // initial y size
                              hwnd,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
    		
    			 houtput = CreateWindow ("Program Output",             // window class name
                              NULL,                       // window caption
                              WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                                  WS_BORDER | ES_LEFT | ES_MULTILINE |
                                  ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL
    						  | ES_READONLY,               // window style
                              7,                          // initial x position
                              21,                         // initial y position
                              225,                        // initial x size
                              45,                         // initial y size
                              hwnd,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
              
              return 0 ;
              
         case WM_PAINT:
              hdc = BeginPaint (hwnd, &ps) ;
              
              DrawText (hdc, TEXT ("Type in your message and I will respond..."), -1, &rect,
                        DT_SINGLELINE | DT_TOP | DT_VCENTER) ;
    		
              
              EndPaint (hwnd, &ps) ;
              return 0 ;
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>hinput = CreateWindow ("User Input",// window class name
    A class name registered with RegisterClass()/Ex() not a title. You have only one registered class, wndclass (called with szAppName) need to use this or register another

    (maybe hinput = CreateWindow(szAppName,"User Input",)

    Need to do some error checking, takes longer to code but helps in finding errors. Test the returned values, in this case the HWND from CreateWindow()

    Code:
    if(hinput==NULL)
    {
         iError=GetLastError();
         sprintf(sBuffer,"Input window failed to create with error#%d.",iError);
         MessageBox(hWnd,sBuffer,"My App Error",MB_OK|MB_ICONERROR);
         return FALSE;
    }
    "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

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    To remove the system menu is a style, forgotten the one. Will find and let you know.

    try CS_NOCLOSE on the child windows
    "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
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >>(maybe hinput = CreateWindow(szAppName,"User Input",)

    How will this help? I'm pretty damn confused

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You have made a mistake in the call to create the child windows.

    The first param of CreateWindow() is a registered class name.

    That is, to use your code

    WNDCLASS wndclass ;

    where

    wndclass.lpszClassName = "User Input"; //not szAppName

    >>hinput = CreateWindow ("User Input", // this is wrong, need to register another winclass or use szAppName here
    >>houtput = CreateWindow ("Program Output",
    //as is this, same error
    You are using three win class names, szAppName,"User Input" and "Program Output" but only register one, szAppName.

    this will fail, returning hinput=NULL, if GetLastError() is then called it will return with error #87 'incorrect parameter'


    Try
    Code:
    hinput = CreateWindow(szAppName,//your registered win class name
                          "User Input", //window title
                          //ect
    "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

  6. #6
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Lightbulb hello!

    Soundz like u don't have a very good teacher when it comes to WINAPI, becouse u are not MAKING a class with CreateWindow you're USING one. U have to use "RegisterClass_" (as u already have in ur code, but are probably just copying becouse u are reaing some stupid book) to make classes, then USE them LATER with CreateWindow.

    I would and maybe could tutor you on this stuff, but im kinda busy tutoring this kid in colledge (computer science major ).

    SPH

    P.S. Im 13 Muahahahaha im 13!!!

  7. #7
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    >P.S. Im 13 Muahahahaha im 13!!!

    Up to your usual level of bragging already, I see.

  8. #8
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    oh yeah minime im 12 and ive been doing windows api since i was 11 and doing it in Borland Turbo C++ 3.1 for Windows 3.1!
    Anyway, with this modern type of windows programming, with
    Code:
    (HBRUSH)GetStockObject(COLOR_WINDOW+10)
    I want to replace COLOR_WINDOW+10 with the BTN_FACE tag, if you know what I mean. I can't quite remember what it was exactly called...and also too lazy to look it up on my other computer. So could you tell me what it is, -KEN-(or any other skilled person)? thanks.

  9. #9
    Unregistered
    Guest

    Re: hello!

    Originally posted by minime6696
    Soundz like u don't have a very good teacher when it comes to WINAPI, becouse u are not MAKING a class with CreateWindow you're USING one. U have to use "RegisterClass_" (as u already have in ur code, but are probably just copying becouse u are reaing some stupid book) to make classes, then USE them LATER with CreateWindow.

    I would and maybe could tutor you on this stuff, but im kinda busy tutoring this kid in colledge (computer science major ).

    SPH

    P.S. Im 13 Muahahahaha im 13!!!
    Hey kid learn to spell first before you think you are cool cuz you are helping out a college kid!!!!!

  10. #10
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Exclamation Ah, god!

    The Cboard 'Oligarchy'...The forever 'optimists' (Simpsons: *Sarcasm Detector Expolodes*). God, I don't give a **** about spelling in a casual convo on the net, I offer to help people and I get "blah blah blah"'d. Jeez, just a little judgemental 'ey KEN?!

    Live and let live ~SPH

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    "I am not young enough to know everything."
    Oscar Wilde
    "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

  12. #12
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Post ? Makes Sense...

    Philosophy... I love I love...

    Yeah I agree... I dunno If u were trying to make a point even minutely like this, but im turning it into this...

    Those in our society (in my opinion), that are older have been exposed to more and thingz, and think on a less open plain. I think to truely be "wise" you must not fall a victim to these things.

    I have to go to sleep now so I won't eloborate further, but on the other hand, if you were trying to say I think I know everything, then I say to you, "When did I say that? I actually deneid that many many, times if u may recollect..."

    ~SPH

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>I would and maybe could tutor you on this stuff, but im kinda busy tutoring this kid in colledge (computer science major ).

    Sorry, is this denying that you know everything? Or bragging that you do?

    >>and think on a less open plain.

    Because we have been where you are now and moved on. We have lived through what you are about to, and more. We have learned lessons you are not ready or willing too.

    We have lost (some) of our arrogance, lost most of our feelings of invunerability or immortality and gained, hopefully, tolerance. (except me)

    We have learned enough to know that we know nothing, to question what we do know.

    And yes, I remember you telling me off for treating YOU like a newbie. YOU didn't like it so why do it to someone else?

    A thirteen year old boy has so much testosterone running thru their bodies they would fail an olympic drug test!
    "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

  14. #14
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    HAHAHAHA!

    Hypocrits... Talk about Hypocrits...

    Subject: Arrogence

    % Detected in "novacain": 86.2

    Think about what you have just said, and think on the fact that, maybe I wasn't talking about myself when I posted last night...

    ~SPH

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Enough.

    If you still have a problem Chris, try again. Perhaps we can all be a little more civile and to the point next time.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't create child windows
    By OnionKnight in forum Windows Programming
    Replies: 4
    Last Post: 04-10-2011, 05:13 PM
  2. Displaying Text on MDI child windows
    By EmbeddedC in forum Windows Programming
    Replies: 4
    Last Post: 10-30-2008, 01:28 PM
  3. Child windows
    By beene in forum Windows Programming
    Replies: 2
    Last Post: 12-13-2006, 04:22 AM
  4. Keeping child windows in their place
    By Smallz in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2006, 07:22 AM
  5. Child Windows and Messages
    By Terrell in forum Windows Programming
    Replies: 10
    Last Post: 09-05-2002, 07:39 AM

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