Re: ? Modeless Dialog: No OnInitDialog, No Template (No Controls)



Create for a dialog is *not* the same as Create for a window; note that CDialog::Create
actually does a ::CreateDialog call, not a ::CreateWindow call. Well, to be precise, it
does a ::CreateDialogIndirect call. So there is *NO* reason to assume that CreateEx
applies to a CDialog, and therefore using it is incorrect.

BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
... dropped irrelevant code from this text

HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, lpszTemplateName, RT_DIALOG);
HGLOBAL hTemplate = LoadResource(hInst, hResource);
BOOL bResult = CreateIndirect(hTemplate, pParentWnd, hInst); // <= note this line!
FreeResource(hTemplate);

return bResult;
}

Compare this to CWnd::CreateEx:

BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
{
...stuff omitted here

AfxHookWindowCreate(this);
HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);

... stuff omitted here
if (hWnd == NULL)
return FALSE;
... stuff omitted here
return TRUE;
}

Since you can't really use ::CreateWindow or ::CreateWindowEx to create a dialog, its
usage is incorrect. I'm even surprised that it can create a window. So just don't call
CreateEx.

On Mon, 4 Sep 2006 17:31:19 -0400, "Alec S." <@> wrote:

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:24vmf2h2eu7pfa59er2f4943d9raqcc52j@xxxxxxxxxx
There is no CreateEx that creates a dialog, so you are doing something deeply wrong.
There*is* a Create method. That's what you should be using.

From what I understand, CreateEx allows you to create a window in the same way that Create does, but also set extended style
attributes in one step. Either way, I am using Create instead and manually setting the extended styles.
****
CreateEx would be inappropriate for the reasons given above
****

This is what I've got now:

CWWnd* pWnd = new CWWnd;
pWnd->Create(IDD_DIALOG_A, NULL);
****
Why not do
pWnd->Create(CWWnd::IDD);
? It is easier to write, and avoids any need to reference the actual symbol used for the
dialog ID.
****
pWnd->ModifyStyleEx(NULL, WS_EX_TOPMOST|WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT);
****
I believe you have to do SetWindowPos to set the "topmost" property; I'm not sure that
setting it in this way actually does anything. Many style bits cannot be changed after
window creation, and some style bits cannot be changed just by ModifyStyle, but must be
modified by calling an appropriate method, and the style bits merely reflect the change
that the API method effected.
****
pWnd->ModifyStyle(WS_CAPTION, NULL);
****
ModifyStyle takes two DWORD arguments, so why are you giving it a pointer argument such as
NULL? I can believe
pWnd->ModifyStyle(WS_CAPTION, 0);
but I can't understand why you would think a NULL pointer represents a DWORD value
****
pWnd->MoveWindow(m_Left, m_Top, m_Width, m_Height);
****
How do you determine these values? If they are hardwired integers, you can assume they
will only work correctly on your machine.
****
::SetLayeredWindowAttributes(pWnd->GetSafeHwnd(), NULL, m_Opacity, LWA_ALPHA);

It seems to work just fine.
****
Yes, it should work fine. But you said in your original message

however when I use CreatEx to spawn it modeless, the dialog's controls are not created.

which is exactly the behavior I would expect from calling CreateEx, since it is flat-out
incorrect for creating a dialog.
joe

*****
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • is this MFC? + Book recommendations?
    ... import Bool MessageBeep ... import int RegisterWindowMessage ... import HWnd SetActiveWindow ... import DWord SetForegroundWindow ...
    (microsoft.public.vc.mfc)
  • Re: is this MFC? + Book recommendations?
    ... import Bool MessageBeep ... import int RegisterWindowMessage ... import HWnd SetActiveWindow ... import DWord SetForegroundWindow ...
    (microsoft.public.vc.mfc)
  • Re: C++ DLL Usage (p/invoke?)
    ... BOOL CreateCtrl(CWnd* pParentWnd, int top, int left, int bottom, int ... maybe you can recode it a little to take a HWND as its first argument. ... I know enough MFC to believe that this is possible, ... Interop.Marshal to convert an mfc BOOL into a VB Boolean. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Call back function and VC 2005
    ... delegate int EnumWindowsDelegate2(int hWnd, int lParam); ... delegate bool EnumWindowsDelegate1; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: help w/ c/c++ problem
    ... Standard REQUIRES main to return an int. ... Then it is still incorrect. ... The function called at program startup is named main. ...
    (comp.lang.c)