CButton in child window
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: CButton in child window

  1. #1
    Join Date
    Feb 2011
    Posts
    39

    Question CButton in child window

    Hello all,

    I'm working on a little app and this is the first time I'm coding using MFC and VC++.

    I have a CFrameWnd derived main window as well as a CWnd derived child window. I wish to place a CBitmapButton in the child window. I create a CBitmapButton object, call it's create function with WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW but it refuses to show up where I need it to. On the other hand, when I create it in the main window, it shows up with no problem. So essentially, I can't seem to make a visible button (as a child) in the child window of a main window but I seem to be able to do it in the main window.

    What is going on? I'll be greatly appreciative of your advice, of course.

    Thanks a lot!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: CButton in child window

    What exactly is this "CWnd derived child window"?
    How do you create your button? Please show your code (don't forget using Code tags!)
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Hello Victor, thanks for replying.

    The CWnd derived child window is <Code> CMainChildWnd : public CWnd </Code>

    This is how I create my button:

    <Code>

    class CMainChildWnd : public CWnd
    {
    public:
    CBitmapButton cbut1;

    protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpcs);
    };

    </Code>

    The above is the class, as you can see.

    <Code>

    //Create
    //Load bitmaps
    cbut1.LoadBitmaps(IDB_BITMAP1);
    //Done
    cbut1.Create(_T("Add"), WS_CHILD | BS_OWNERDRAW | BS_PUSHBUTTON | WS_VISIBLE, CRect(110,20,140,50), this, 1);
    //done

    </Code>

    That's in CMainChildWnd::OnCreate(LPCREATESTRUCT lpcs).

    I repeat, the button is completely invisible. However, it does turn up if I put the very same code in the parent CMainWnd : public CFrameWnd object i.e, in the parent window.

    Cheers.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: CButton in child window

    1. You have to use [B][...][/B] for the tags, not <...>.
    2. Does this code in the class CMainChildWnd
    Code:
    cbut1.Create(_T("Add"), WS_CHILD | BS_OWNERDRAW | BS_PUSHBUTTON | WS_VISIBLE, CRect(110,20,140,50), this, 1);
    executed? Did you debug it to be sure it is executed?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Sorry about that, ... it is!

    Yes, I'm quite sure it compiles. The same line in the parent window creates and displays the required button...

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: CButton in child window

    Quote Originally Posted by nitinmalapalli View Post
    Yes, I'm quite sure it compiles. ..
    I don't ask you whether it "compiles". Sure it is! Otherwise you couldn't run your App.
    I ask you whether this line of code is executed! Set a break point to this line and then start your App from IDE using F5. If it is executed then it would be nide to know what this cbut1.Create(...) returns...

    Besides, you have hardcoded the CRect coordinates of the button. But will this rect lie in the client area of CMainChildWnd window?
    Victor Nijegorodov

  7. #7
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Quote Originally Posted by VictorN View Post
    I don't ask you whether it "compiles". Sure it is! Otherwise you couldn't run your App.
    I ask you whether this line of code is executed! Set a break point to this line and then start your App from IDE using F5. If it is executed then it would be nide to know what this cbut1.Create(...) returns...

    Besides, you have hardcoded the CRect coordinates of the button. But will this rect lie in the client area of CMainChildWnd window?
    I set a breakpoint as you suggested and ran it using F5. I have no idea about this procedure but I made these observations:

    1.) It did not break at that line, if that was expected.

    2.) It said exactly:


    'Temp.exe': Loaded 'C:\Users\Nitin\Documents\Visual Studio 2005\Projects\Temp\debug\Temp.exe', Symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\System32\ntdll.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\comdlg32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16385_none_ebf82fc36c758ad5\comctl32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\winspool.drv', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', No symbols loaded.
    'Temp.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', No symbols loaded.
    'Temp.exe': Unloaded 'C:\Windows\SysWOW64\ole32.dll'
    'Temp.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7600.16385_none_421189da2b7fabfc\comctl32.dll', No symbols loaded.
    Detected memory leaks!
    Dumping objects ->
    {84} client block at 0x025A7930, subtype c0, 84 bytes long.
    a CPaintDC object at $025A7930, 84 bytes long
    Object dump complete.
    The program '[1400] Temp.exe: Native' has exited with code 0 (0x0).


    3.) It did not trace/output the return value of the Create function at all.

    4.) I later checked the "Hit Count" of the breakpoint, which turned out to be 0.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: CButton in child window

    Quote Originally Posted by nitinmalapalli View Post
    I set a breakpoint as you suggested and ran it using F5. I have no idea about this procedure but I made these observations:

    1.) It did not break at that line, if that was expected.
    Well, it is the answer on your question why "the button is completely invisible" being placed on the "CWnd derived child window": This button is not created!
    Victor Nijegorodov

  9. #9
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Quote Originally Posted by VictorN View Post
    Well, it is the answer on your question why "the button is completely invisible" being placed on the "CWnd derived child window": This button is not created!
    That is astonishing to hear! Could you please tell me the possible reasons why the button may not be created? For example, can I not create buttons in CMainChildWnd::OnCreate(LPCREATESTRUCT lpcs)? What all could be preventing the execution of the line?

    Thanks a lot for the guidance so far!

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,120

    Re: CButton in child window

    Your codepath obviously doesn't lead to that line of code.

  11. #11
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Quote Originally Posted by GCDEF View Post
    Your codepath obviously doesn't lead to that line of code.
    Thanks for replying, GCDEF.
    I'm sorry, but how couldn't it? It's all nestled in the OnCreate function. Surely, that'll always get executed? Ideally, in which member function should I create a button?

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,120

    Re: CButton in child window

    Quote Originally Posted by nitinmalapalli View Post
    Thanks for replying, GCDEF.
    I'm sorry, but how couldn't it? It's all nestled in the OnCreate function. Surely, that'll always get executed? Ideally, in which member function should I create a button?
    Use your debugger to find out.

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: CButton in child window

    Quote Originally Posted by nitinmalapalli View Post
    T... For example, can I not create buttons in CMainChildWnd::OnCreate(LPCREATESTRUCT lpcs)? What all could be preventing the execution of the line?
    Are you sure this CMainChildWnd::OnCreate(...) is ever called?
    Victor Nijegorodov

  14. #14
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Quote Originally Posted by VictorN View Post
    Are you sure this CMainChildWnd::OnCreate(...) is ever called?
    Quite sure. Some other lines are getting executed in the same function!

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,467

    Re: CButton in child window

    Please, show your actual code of this function. (don't forget using Code tags!)
    Then point to to lines that are executed and the ones that are not.
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center