PleaseWait plugin
Hi.
I am creating new plug-in called PleaseWait which shows small modeless window (see attachment) with label and gif animation.
The goal is to create popup message for user that some action is being performed in background so he needs to wait.
It is suitable especially for long run tasks like downloading files, writing/reading, database operations and so on when nothing is happening/refreshing in GUI.
Plug-in runs in a separate thread, it is top most window [above all other windows - see attachment] so there is possible to show it over several pages even in .onGUIInit!
Showing window is simple, but I have problem with closing it.
This is my source:
# Show dialog with gif file and caption, dimensions and label color
PleaseWait::ShowDialog /NOUNLOAD "D:\Projects\PleaseWait\loading.gif"
"Window title" 200 120 "Loading data..." "0x0000ff" 0
# This is important!
MessageBox MB_OK "After PleaseWait::ShowDialog"
And this is C++ code I use: [shortened]This is window procedure for window created above:__declspec
(dllexport) void ShowDialog(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop, extra_parameters *extra)
{
// get NSIS parameters
>.......
// Run main thread
unsigned uThreadID = 0;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadProc, &g_ThreadParam, 0, &uThreadID);
}
>// This is main Thread procedure
>unsigned __stdcall ThreadProc(void * param)
{
THREADPARAM * pThreadParam = (THREADPARAM *)param;
.......
RegisterClassEx(&wc) etc
// Create the Window
hwnd = CreateWindowEx(...)
// Show window and redraw it
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
// Start animation
PlayAnimation(hwnd, pThreadParam->szFilename, ....);
// The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return0;
}
I want anytime to close this window from NSIS script with PleaseWait::EndDialog which is:LRESULT CALLBACK WndProc
(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
.......
caseWM_PAINT:
// Draw image
pe->OnPaint();
.......
default:
returnDefWindowProc(hwnd, msg, wParam, lParam);
}
return0;
}
The problem is that immediately when I call PleaseWait::EndDialog I got Unhandled exception. I have breakpoint exactly on line EndDialog(...) also inside and this function is never called, the program crashes *before* entering into it.__declspec
(dllexport) void EndDialog(HWND hwndParent, int string_size,
char *variables, stack_t **stacktop, extra_parameters *extra)
{
g_bStopImmediately = true;
}
I am not sure - what is wrong there? Why cannot I call EndDialog directly?
NSIS advanced to next line because I can see "After PleaseWait::ShowDialog" message box but calling EndDialog later causes the installer to crash.
ThreadProc is still running - separated thread but I need some way how to interrupt it from NSIS as I do not know how long the dialog will be shown.
Thanks for any ideas :)