CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Hybrid View

  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
    Hanover Germany
    Posts
    20,398

    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
    Hanover Germany
    Posts
    20,398

    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
    Hanover Germany
    Posts
    20,398

    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
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    Update: Actually, I am not sure that the function is being called. But i assume OnCreate is definitely called!

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CButton in child window

    Quote Originally Posted by nitinmalapalli View Post
    Update: Actually, I am not sure that the function is being called. But i assume OnCreate is definitely called!
    Don't assume anything. Verify it with the debugger.

  10. #10
    Join Date
    Feb 2011
    Posts
    39

    Re: CButton in child window

    It turns out, and I'm ashamed of myself, that I had the statements after the "return 0;" of the int OnCreate(...)

    I'm very grateful to you for having helped me out though, I never really had got around to using the Debugger. This was a learning experience, nevertheless.

    Thanks very much, GCDEF and Victor!

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
  •  





Click Here to Expand Forum to Full Width

Featured