Trapping F_in_Box Window Close event.

DLL Edition of the F-IN-BOX
bpbuster
Posts: 2
Joined: Wed May 21, 2008 12:37 am

Trapping F_in_Box Window Close event.

Postby bpbuster » Wed May 21, 2008 4:23 am

I am currently evaluating f_in_box.h DLL and have hit a problem.

I am having difficulties trapping the WM_CLOSE so that I can display a prompt.

All flash events are trapped inside method FPCListener which is what I want.

but as soon as I

Code: Select all

RegisterClassEx(&wcx);


then all events are trapped inside method windowProc which would be ok but the flash does not load in the window(big problem).

Hope there is a solution.

Code: Select all

FlashCommunication::Load()
{
string m_Path = "https://jflash.dev.java.net/testdata/testpp.swf";
HFPC m_hFPC = FPC_LoadRegisteredOCX(); 

// Define the Window Class
WNDCLASSEX wcx;
wcx.cbSize = sizeof(wcx);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = windowProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;

wcx.hInstance = AfxGetInstanceHandle();

wcx.hIcon = LoadIcon(wcx.hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcx.hIconSm = LoadIcon(wcx.hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcx.hCursor = NULL;
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //NULL

wcx.lpszMenuName =  NULL;
wcx.lpszClassName = FPC_GetClassName(m_hFPC);

// Register Window Class
m_Atom = RegisterClassEx(&wcx);

HWND hwndFPC3 = CreateWindowEx(NULL, (LPCTSTR)FPC_GetClassAtom(m_hFPC), NULL, WS_POPUP | WS_OVERLAPPEDWINDOW |  WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, NULL, NULL);
FPC_LoadMovie(hwndFPC3, 0, m_Path.c_str() ); 
ShowWindow(hwndFPC3, SW_SHOWNORMAL);
FPCSetEventListener(hwndFPC3, FPCListener, 0);
}

void WINAPI FlashCommunication::FPCListener(HWND pHwnd, LPARAM lParam, NMHDR* pNMHDR)
{
FlashCommunication* pObj = theApp.GetFlashCommunicationInstance(pHwnd);
}

LRESULT CALLBACK FlashCommunication::windowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg==WM_CLOSE)
    {
        int result = MessageBox(hwnd,
                                           "Are you sure you want to close this application?",
                                           "Close...",
                                           MB_YESNO | MB_ICONQUESTION);
        if(result==IDYES)
        {
          theApp.RemoveFlashCommunicationInstance(hwnd);
          return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
        else
          return 0;
    }
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Wed May 21, 2008 11:08 am

Thank you for your question.

It would be better to override WindowProc of the created window (instead of creating a subclass), like this:

Code: Select all

FlashCommunication::Load()
{
string m_Path = "https://jflash.dev.java.net/testdata/testpp.swf";
HFPC m_hFPC = FPC_LoadRegisteredOCX(); 

// Commented
/*

// Define the Window Class
WNDCLASSEX wcx;
wcx.cbSize = sizeof(wcx);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = windowProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;

wcx.hInstance = AfxGetInstanceHandle();

wcx.hIcon = LoadIcon(wcx.hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcx.hIconSm = LoadIcon(wcx.hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcx.hCursor = NULL;
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //NULL

wcx.lpszMenuName =  NULL;
wcx.lpszClassName = FPC_GetClassName(m_hFPC);

// Register Window Class
m_Atom = RegisterClassEx(&wcx);

*/

HWND hwndFPC3 = CreateWindowEx(NULL, (LPCTSTR)FPC_GetClassAtom(m_hFPC), NULL, WS_POPUP | WS_OVERLAPPEDWINDOW |  WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, NULL, NULL);

// Added
m_OldWndProc = (WNDPROC)GetWindowLong(hwndFPC3, GWL_WNDPROC);
GetWindowLong(hwndFPC3, GWL_WNDPROC, &windowProc);

FPC_LoadMovie(hwndFPC3, 0, m_Path.c_str() ); 
ShowWindow(hwndFPC3, SW_SHOWNORMAL);
FPCSetEventListener(hwndFPC3, FPCListener, 0);
}

void WINAPI FlashCommunication::FPCListener(HWND pHwnd, LPARAM lParam, NMHDR* pNMHDR)
{
FlashCommunication* pObj = theApp.GetFlashCommunicationInstance(pHwnd);
}

LRESULT CALLBACK FlashCommunication::windowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
FlashCommunication* pObj = theApp.GetFlashCommunicationInstance(hwnd);


if (uMsg==WM_CLOSE)
    {
        int result = MessageBox(hwnd,
                                           "Are you sure you want to close this application?",
                                           "Close...",
                                           MB_YESNO | MB_ICONQUESTION);
        if(result==IDYES)
        {
          theApp.RemoveFlashCommunicationInstance(hwnd);
          return CallWindowProc(pObj->m_OldWndProc, hwnd, uMsg, wParam, lParam);
        }
        else
          return 0;
    }
return CallWindowProc(pObj->m_OldWndProc, hwnd, uMsg, wParam, lParam);
}
Best regards, Artem A. Razin,
F-IN-BOX support
Ask your question here: http://www.f-in-box.com/support.html

bpbuster
Posts: 2
Joined: Wed May 21, 2008 12:37 am

Postby bpbuster » Thu May 22, 2008 4:52 am

Thanks for the help.

I did have to move the

Code: Select all

SetWindowLong(hwndFPC3, GWL_WNDPROC, (long)windowProc);

to be called after:

Code: Select all

FPC_LoadMovie(hwndFPC3, 0, m_Path.c_str() ); 
ShowWindow(hwndFPC3, SW_SHOWNORMAL);
FPCSetEventListener(hwndFPC3, FPCListener, 0);

otherwise the flash movie would not load or the FPCListener would not be set correctly.

Softanics
Site Admin
Posts: 1402
Joined: Sat Sep 18, 2004 3:03 am
Location: Russia, St. Petersburg
Contact:

Postby Softanics » Fri May 23, 2008 7:56 am

Do you call previous window proc:

Code: Select all

CallWindowProc(pObj->m_OldWndProc, hwnd, uMsg, wParam, lParam);


?
Best regards, Artem A. Razin,

F-IN-BOX support

Ask your question here: http://www.f-in-box.com/support.html


Return to “DLL Edition”

Who is online

Users browsing this forum: No registered users and 15 guests

cron