How do you change the window class for a CDialogImpl?

Robbie Gluon 1 Reputation point
2022-10-20T21:57:19.12+00:00

With respect to WTL/ATL, I noticed that when you call DoModal on a CDialogImpl, atlwin.h calls:

return ::DialogBoxParam(_AtlBaseModule.GetResourceInstance(),  
                        MAKEINTRESOURCE(static_cast<T*>(this)->IDD),   
                        hWndParent,  
                        T::StartDialogProc,  
                        dwInitParam);  

, retrieving the dialog box information from the DIALOGEX description in the .rc file. I can't see how to add a CLASS item to this structure to set the window class to a custom one, as I need the T::StartDialogProc. When I put in the T::StartDialogProc for ATL::CDialogImpl, DialogBoxParam threw an access violation exception. I have to assume this is some kind of thunking problem.

My motivation is I have a specific issue with the IDC_WAIT cursor being shown for a few ms (it "flashes up" when I call DoModal) and my working theory right now is that my DIALOGEX doesn't have a default cursor. The reason I think this is because when I do the following in my WM_INITDIALOG handler:

SetClassLong(m_hWnd, GCL_HCURSOR, (LONG) ::SetCursor(::LoadCursor(0, IDC_ARROW)));  

, the problem is minimised, i.e. the cursor sometimes briefly flashes to wait. I think if it had a default cursor before it arrived at WM_INITDIALOG, i.e. from the window class, the problem will disappear completely.

So, is it possible to add a custom window class to a CDialogImpl, or to add a default cursor to the class CDialogImpl uses, and if so, how?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,609 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,719 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 45,476 Reputation points
    2022-10-20T23:18:32.653+00:00

    Both WTL and ATL use the system's dialog class. This window class includes a default cursor. See for yourself --

       WNDCLASS wc{};  
       GetClassInfo(NULL, WC_DIALOG, &wc);  
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.