• Advertisement
Sign in to follow this  

SetClassLong not work with CDialog

This topic is 4247 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

SetClassLong(dlg.GetSafeHwnd(),GCL_HBRBACKGROUND,(long)GetStockObject(WHITE_BRUSH)); why?

Share this post


Link to post
Share on other sites
Advertisement
What exactly are you trying to accomplish? What makes you say this "doesn't work"? Are you getting an error result from SetClassLong? Are you getting a crash or other failure? Are you simply not getting the results you expect?

Share this post


Link to post
Share on other sites
Quote:
Original post by ApochPiQ
What exactly are you trying to accomplish? What makes you say this "doesn't work"? Are you getting an error result from SetClassLong? Are you getting a crash or other failure? Are you simply not getting the results you expect?


yes I simply not getting the result. the dialog background color is still unchhanged.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike2343
Have you checked GetLastError()?

Post more code, likely help us.


yes ,it return 0;

source code here

HWND h = AfxGetMainWnd()->GetSafeHwnd(); // main window is dialog
DWORD d = SetClassLong(h,GCL_HBRBACKGROUND,(long)GetStockObject(WHITE_BRUSH)); // not work

CWnd *cc = AfxGetMainWnd();


MoveWindow(103,13,777,888);


if (c.Create(AfxRegisterWndClass(
CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),
NULL),
NULL,WS_VISIBLE,
CRect(0,0,0,0),cc,11,NULL)==FALSE)
return false;
SetClassLong(c.GetSafeHwnd(),GCL_HBRBACKGROUND,(long)GetStockObject(GRAY_BRUSH)) ; // work



Share this post


Link to post
Share on other sites
if (c.CreateEx(
WS_EX_TOPMOST,
AfxRegisterWndClass(
CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),
NULL),
NULL,
WS_VISIBLE,
CRect(0,0,0,0),
0,
11,
NULL)==0)
{
int i = GetLastError();
::MessageBox(0,"tetse",0,0);
return false;
}



another question : how can GetLastError() return 0?????

Share this post


Link to post
Share on other sites
I'm not sure what you're trying to achieve. Why register a new window class with one background colour then promptly try and change it to another background colour??? Referring back to the original title you need to process WM_CTLCOLOR to change the background colour of a dialog...

Jans.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jansic
I'm not sure what you're trying to achieve. Why register a new window class with one background colour then promptly try and change it to another background colour??? Referring back to the original title you need to process WM_CTLCOLOR to change the background colour of a dialog...

Jans.


I just experience the function for exercise. the question still confuse me.
why CreateEx fail and why GetLastError return 0 when CreateEx fail?

Share this post


Link to post
Share on other sites
Not all functions set the error code. Only those that actually document setting the error code do so. The documentation for CWnd::CreateEx does not mention setting the error code in case of failure.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jansic
I'm not sure what you're trying to achieve. Why register a new window class with one background colour then promptly try and change it to another background colour??? Referring back to the original title you need to process WM_CTLCOLOR to change the background colour of a dialog...

Jans.


I found many function fail to work with dialog. so some extra step need to do for dialog. for example Modifystyle(WS_POPUP,0) has no effect on dialog.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave Hunt
Not all functions set the error code. Only those that actually document setting the error code do so. The documentation for CWnd::CreateEx does not mention setting the error code in case of failure.


I found compiler output window tell me "Warning: Window creation failed: GetLastError returns 0x00000579" but GetLastError in my source code return 0; my god

Share this post


Link to post
Share on other sites
Blending MFC and straight Win32 API calls can be tricky. Often MFC will "grab" the error value from GetLastError() and clear it or alter it, meaning that the debug output from MFC (and MFC's own error handling mechanisms) are the only way to detect certain errors.

Actually, that's part of the reason why most experienced programmers despise MFC [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement