Sign in to follow this  
user88

[SlimDX] SimpleFramework, Windows Api

Recommended Posts

Hi All! That post is pertains to Win Api forums more than DirectX and Xna, but please have a look. I'm trying to integrate a SimpleFramework for SlimDX SDK as core to my 3d application. The application is a huge project and it consists from multiple modules and that modules divides the one by some logical levels. So, there are two things that SimpleFramework which is non compatible with application: - GameWindow and SimpleFramework is a "single 3d view" framework but application is "multiple 3d views" and has its own main window. - There are no any connection between 3d module and module where is main window of application. That means that main window can't derives from GameWindow. As i see the way is to handle messages of main window in 3d module and effects on them correspondingly. But have no any skills in Windows API. I googled a more and tried to do something, but with no success. all messages i need to handle is in overrided WndProc method of GameWindow:
if (m.Msg == WindowConstants.WM_SIZE)
            {
                if (m.WParam == WindowConstants.SIZE_MINIMIZED)
                {
                    minimized = true;
                    maximized = false;

                    OnSuspend(EventArgs.Empty);
                }
                else
                {
                    Rectangle client = NativeMethods.GetClientRectangle(m.HWnd);
                    if (client.Height == 0)
                    {
                        // rapidly clicking the task bar to minimize and restore a window
                        // can cause a WM_SIZE message with SIZE_RESTORED when 
                        // the window has actually become minimized due to rapid change
                        // so just ignore this message
                    }
                    else if (m.WParam == WindowConstants.SIZE_MAXIMIZED)
                    {
                        if (minimized)
                            OnResume(EventArgs.Empty);

                        minimized = false;
                        maximized = true;

                        OnUserResized(EventArgs.Empty);
                        UpdateScreen();
                    }
                    else if (m.WParam == WindowConstants.SIZE_RESTORED)
                    {
                        if (minimized)
                            OnResume(EventArgs.Empty);

                        minimized = false;
                        maximized = false;

                        if (!inSizeMove && Size != cachedSize)
                        {
                            OnUserResized(EventArgs.Empty);
                            UpdateScreen();
                            cachedSize = Size;
                        }
                    }
                }
            }
            else if (m.Msg == WindowConstants.WM_ACTIVATEAPP)
            {
                if (m.WParam != IntPtr.Zero)
                    OnApplicationActivated(EventArgs.Empty);
                else
                    OnApplicationDeactivated(EventArgs.Empty);
            }
            else if (m.Msg == WindowConstants.WM_POWERBROADCAST)
            {
                if (m.WParam == WindowConstants.PBT_APMQUERYSUSPEND)
                {
                    OnSystemSuspend(EventArgs.Empty);
                    m.Result = (IntPtr)1;
                    return;
                }
                else if (m.WParam == WindowConstants.PBT_APMRESUMESUSPEND)
                {
                    OnSystemResume(EventArgs.Empty);
                    m.Result = (IntPtr)1;
                    return;
                }
            }
            else if (m.Msg == WindowConstants.WM_SYSCOMMAND)
            {
                long wparam = m.WParam.ToInt64() & 0xFFF0;
                if (wparam == WindowConstants.SC_MONITORPOWER || wparam == WindowConstants.SC_SCREENSAVE)
                {
                    CancelEventArgs e = new CancelEventArgs();
                    OnScreensaver(e);
                    if (e.Cancel)
                    {
                        m.Result = IntPtr.Zero;
                        return;
                    }
                }
            }

I tried to make some test application which handles the messages. It application realy handles some messages. But there was no any important messages comes to procedure. Code sniped from test app:
// define the api function
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);

// install the procedure
...
HookProcedure = MyHookProc;
hHook = SetWindowsHookEx((int)HookId.WH_CBT, HookProcedure, Handle, AppDomain.GetCurrentThreadId());
...

/// hooking messages
...

        public int MyHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
                Message m = Message.Create(Handle, nCode, wParam, lParam);

                if (nCode > 0)
                {
                    if (m.Msg == WindowConstants.WM_SIZE)
                    {
                        if (m.WParam == WindowConstants.SIZE_MINIMIZED)
                        {
                            textBox1.AppendText("\r\n " + WindowConstants.SIZE_MINIMIZED);
                        }
                        else
                        {
                            if (m.WParam == WindowConstants.SIZE_MAXIMIZED)
                            {
                                textBox1.AppendText("\r\n " + WindowConstants.SIZE_MAXIMIZED);
                            }
                            else if (m.WParam == WindowConstants.SIZE_RESTORED)
                            {
                                textBox1.AppendText("\r\n " + WindowConstants.SIZE_RESTORED);
                            }
                        }
                    }
                    else if (m.Msg == WindowConstants.WM_ACTIVATEAPP)
                    {
                        textBox1.AppendText("\r\n " + WindowConstants.WM_ACTIVATEAPP);
                    }
                    else if (m.Msg == WindowConstants.WM_POWERBROADCAST)
                    {
                        if (m.WParam == WindowConstants.PBT_APMQUERYSUSPEND)
                        {
                            textBox1.AppendText("\r\n " + WindowConstants.PBT_APMQUERYSUSPEND);
                        }

                        if (m.WParam == WindowConstants.PBT_APMRESUMESUSPEND)
                        {
                            textBox1.AppendText("\r\n " + WindowConstants.PBT_APMRESUMESUSPEND);
                        }
                    }
                    else if (m.Msg == WindowConstants.WM_SYSCOMMAND)
                    {
                        long wparam = m.WParam.ToInt64() & 0xFFF0;
                        if (wparam == WindowConstants.SC_MONITORPOWER || wparam == WindowConstants.SC_SCREENSAVE)
                        {
                            textBox1.AppendText(
                                "\r\n WindowConstants.SC_MONITORPOWER || wparam == WindowConstants.SC_SCREENSAVE");
                        }
                    }
                    //else textBox1.AppendText("\r\n" + m);
                }
      }

Please help me if someone know what is the problem and why i can't get such messages as WindowConstants.SIZE_MINIMIZED..

Share this post


Link to post
Share on other sites
The SampleFramework really isn't designed for production use. It has some rather glaring and large holes in its capabilities and handling of various functionality that prevent it from being a robust base for an application (it was intended simply for use in building samples to demonstrate functionality).

Your best bet is to actually write a real framework for your application to live in, you can copy code from the sample framework as needed, but using the framework as a whole is A Bad Idea™

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this