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!)
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.
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?
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...
Re: CButton in child window
Quote:
Originally Posted by
nitinmalapalli
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?
Re: CButton in child window
Quote:
Originally Posted by
VictorN
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.
Re: CButton in child window
Quote:
Originally Posted by
nitinmalapalli
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!
Re: CButton in child window
Quote:
Originally Posted by
VictorN
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!
Re: CButton in child window
Your codepath obviously doesn't lead to that line of code.
Re: CButton in child window
Quote:
Originally Posted by
GCDEF
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?
Re: CButton in child window
Quote:
Originally Posted by
nitinmalapalli
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.
Re: CButton in child window
Quote:
Originally Posted by
nitinmalapalli
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? :confused:
Re: CButton in child window
Quote:
Originally Posted by
VictorN
Are you sure this CMainChildWnd::OnCreate(...) is ever called? :confused:
Quite sure. Some other lines are getting executed in the same function!
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. :cool:
Re: CButton in child window
Update: Actually, I am not sure that the function is being called. But i assume OnCreate is definitely called!
Re: CButton in child window
Quote:
Originally Posted by
nitinmalapalli
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.
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!