From: Matt Houser on
I've created modeless layered windows successfully before, now I am trying
to create a modal layered window. I am deriving from CWnd and duplicating
much of CDialog::DoModal() to accomplish this.

It seems to be working, except that pressing Alt+F4 destroys my window, but
does not exit from RunModalLoop().

How do I resolve this? Is there a style that's missing from my window?
Or is there an easier way to accomplish what I am trying to do?

Thanks
Matt Houser
http://www.insidercoding.com

From: AliR on
I don't understand what you are doing.

Why are you duplicating code from DoModal?

You know that you can have a layered modal dialog box, but simply inheriting
from a CDialog, and in the OnInitDialog call SetWindowLong to add the
layered style to it, and the call SetLayeredWindowAttributes

BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();

SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd, GWL_EXSTYLE) |
WS_EX_LAYERED);
SetLayeredWindowAttributes(0,255,LWA_ALPHA);

return TRUE;
}

No need to write your own modal loop.


But if you insist on writing your own modal loop then when the dialog feels
like it is time to close the application you will need to send a WM_QUIT
message to your loop.

AliR.

"Matt Houser" <matt(a)houser.ca> wrote in message
news:040EDF48-F1EB-4013-9A9F-027B6CF1F99A(a)microsoft.com...
> I've created modeless layered windows successfully before, now I am trying
> to create a modal layered window. I am deriving from CWnd and duplicating
> much of CDialog::DoModal() to accomplish this.
>
> It seems to be working, except that pressing Alt+F4 destroys my window,
> but does not exit from RunModalLoop().
>
> How do I resolve this? Is there a style that's missing from my window?
> Or is there an easier way to accomplish what I am trying to do?
>
> Thanks
> Matt Houser
> http://www.insidercoding.com


From: Matt Houser on
I am unable to use SetLayeredWindowAttributes because I need per-pixel alpha
blending for the window.

However, I did get it working using CDialog as you suggested. This saves me
rewriting DoModal().

However, a minor issue:

When I was using CWnd, I was able to override PreCreateWindow() so that I
can call AfxRegisterWndClass() to use a window class that has no default
cursor set (I set it during WM_MOUSEMOVE events). This does not get called
for CDialog. Is there a way to remove the default cursor for dialogs (my
cursor is currently flashing as the mouse is moved).

Thanks,
....Matt

From: Joseph M. Newcomer on
I suspect that Alt+F4 sends a WM_CLOSE to the active window, so if you do an OnClose
handler that does nothing, this will override it. You will probably have to intercept the
System Menu SC_CLOSE notification to handle the [x] button in the caption bar, and
SendMessage/PostMessage a user-defined message that will call EndDialog.
joe


On Tue, 9 Feb 2010 14:40:06 -0500, "Matt Houser" <matt(a)houser.ca> wrote:

>I've created modeless layered windows successfully before, now I am trying
>to create a modal layered window. I am deriving from CWnd and duplicating
>much of CDialog::DoModal() to accomplish this.
>
>It seems to be working, except that pressing Alt+F4 destroys my window, but
>does not exit from RunModalLoop().
>
>How do I resolve this? Is there a style that's missing from my window?
>Or is there an easier way to accomplish what I am trying to do?
>
>Thanks
>Matt Houser
>http://www.insidercoding.com
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm