forked from openlp/openlp
pptviewer mods
This commit is contained in:
parent
23b9884775
commit
e8de37f7b3
@ -140,8 +140,10 @@ class PptviewDocument(PresentationDocument):
|
||||
PPTviewLib creates large BMP's, but we want small PNG's for consistency.
|
||||
Convert them here.
|
||||
"""
|
||||
log.debug(u'create_thumbnails')
|
||||
if self.check_thumbnails():
|
||||
return
|
||||
log.debug(u'create_thumbnails proceeding')
|
||||
for idx in range(self.get_slide_count()):
|
||||
path = u'%s\\slide%s.bmp' % (self.get_temp_folder(),
|
||||
unicode(idx + 1))
|
||||
|
@ -48,30 +48,28 @@ BOOL debug = FALSE;
|
||||
|
||||
HINSTANCE hInstance = NULL;
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved)
|
||||
{
|
||||
hInstance = (HINSTANCE)hModule;
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
DEBUG("PROCESS_ATTACH\n");
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
DEBUG("THREAD_ATTACH\n");
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
DEBUG("THREAD_DETACH\n");
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
// Clean up... hopefully there is only the one process attached?
|
||||
// We'll find out soon enough during tests!
|
||||
DEBUG("PROCESS_DETACH\n");
|
||||
for(int i = 0; i<MAX_PPTOBJS; i++)
|
||||
ClosePPT(i);
|
||||
break;
|
||||
case DLL_PROCESS_ATTACH:
|
||||
DEBUG("PROCESS_ATTACH\n");
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
DEBUG("THREAD_ATTACH\n");
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
DEBUG("THREAD_DETACH\n");
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
// Clean up... hopefully there is only the one process attached?
|
||||
// We'll find out soon enough during tests!
|
||||
DEBUG("PROCESS_DETACH\n");
|
||||
for(int i = 0; i<MAX_PPTOBJS; i++)
|
||||
ClosePPT(i);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@ -96,34 +94,86 @@ DllExport BOOL CheckInstalled()
|
||||
// "<n>.bmp" will be appended to complete the path. E.g. "c:\temp\slide" would
|
||||
// create "c:\temp\slide1.bmp" slide2.bmp, slide3.bmp etc.
|
||||
// It will also create a *info.txt containing information about the ppt
|
||||
DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewpath)
|
||||
DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect,
|
||||
char *previewpath)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
char cmdline[MAX_PATH * 2];
|
||||
int id;
|
||||
|
||||
DEBUG("OpenPPT start: %s; %s\n", filename, previewpath);
|
||||
DEBUG("OpenPPT start: %u; %i, %i, %i, %i\n", hParentWnd, rect.top, rect.left, rect.bottom, rect.right);
|
||||
if(GetPPTViewerPath(cmdline, sizeof(cmdline))==FALSE)
|
||||
{
|
||||
DEBUG("OpenPPT: GetPPTViewerPath failed\n");
|
||||
return -1;
|
||||
}
|
||||
DEBUG("OpenPPT start: %u; %i, %i, %i, %i\n", hParentWnd, rect.top,
|
||||
rect.left, rect.bottom, rect.right);
|
||||
id = -1;
|
||||
for(int i = 0; i<MAX_PPTOBJS; i++)
|
||||
for(int i = 0; i < MAX_PPTOBJS; i++)
|
||||
{
|
||||
if(pptviewobj[i].state==PPT_CLOSED)
|
||||
if(pptviewobj[i].state == PPT_CLOSED)
|
||||
{
|
||||
id=i;
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(id<0)
|
||||
if(id < 0)
|
||||
{
|
||||
DEBUG("OpenPPT: Too many PPTs\n");
|
||||
return -1;
|
||||
}
|
||||
BOOL gotinfo = InitPPTObject(id, filename, hParentWnd, rect, previewpath);
|
||||
if(!StartPPTView(id))
|
||||
{
|
||||
ClosePPT(id);
|
||||
return -1;
|
||||
}
|
||||
if(!gotinfo)
|
||||
{
|
||||
DEBUG("OpenPPT: Get info\n");
|
||||
pptviewobj[id].steps = 0;
|
||||
int steps = 0;
|
||||
while(pptviewobj[id].state == PPT_OPENED)
|
||||
{
|
||||
if(steps <= pptviewobj[id].steps)
|
||||
{
|
||||
Sleep(20);
|
||||
DEBUG("OpenPPT: Step %d/%d\n",steps,pptviewobj[id].steps);
|
||||
steps++;
|
||||
NextStep(id);
|
||||
}
|
||||
Sleep(10);
|
||||
}
|
||||
DEBUG("OpenPPT: Steps %d, first slide steps %d\n",
|
||||
pptviewobj[id].steps,pptviewobj[id].firstSlideSteps);
|
||||
SavePPTInfo(id);
|
||||
if(pptviewobj[id].state == PPT_CLOSING || pptviewobj[id].slideCount <= 0)
|
||||
{
|
||||
// We've gone off the end and pptview is closing. We'll need to start again
|
||||
ClosePPT(id);
|
||||
gotinfo = InitPPTObject(id, filename, hParentWnd, rect, previewpath);
|
||||
if(gotinfo)
|
||||
gotinfo = StartPPTView(id);
|
||||
if(!gotinfo)
|
||||
{
|
||||
ClosePPT(id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
RestartShow(id);
|
||||
}
|
||||
if(gotinfo)
|
||||
{
|
||||
DEBUG("OpenPPT: Info loaded, no refresh\n");
|
||||
pptviewobj[id].state = PPT_LOADED;
|
||||
Resume(id);
|
||||
}
|
||||
if(pptviewobj[id].mhook != NULL)
|
||||
UnhookWindowsHookEx(pptviewobj[id].mhook);
|
||||
pptviewobj[id].mhook = NULL;
|
||||
DEBUG("OpenPPT: Exit: id=%i\n", id);
|
||||
return id;
|
||||
}
|
||||
|
||||
BOOL InitPPTObject(int id, char *filename, HWND hParentWnd,
|
||||
RECT rect, char *previewpath)
|
||||
{
|
||||
DEBUG("InitPPTObject\n");
|
||||
memset(&pptviewobj[id], 0, sizeof(PPTVIEWOBJ));
|
||||
strcpy_s(pptviewobj[id].filename, MAX_PATH, filename);
|
||||
strcpy_s(pptviewobj[id].previewpath, MAX_PATH, previewpath);
|
||||
@ -131,10 +181,14 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewp
|
||||
pptviewobj[id].slideCount = 0;
|
||||
pptviewobj[id].currentSlide = 0;
|
||||
pptviewobj[id].firstSlideSteps = 0;
|
||||
pptviewobj[id].guess = 1;
|
||||
for(int i = 0; i < MAX_SLIDES; i++)
|
||||
pptviewobj[id].slideNo[i] = 0;
|
||||
pptviewobj[id].hParentWnd = hParentWnd;
|
||||
pptviewobj[id].hWnd = NULL;
|
||||
pptviewobj[id].hWnd2 = NULL;
|
||||
if(hParentWnd!=NULL&&rect.top==0&&rect.bottom==0&&rect.left==0&&rect.right==0)
|
||||
if(hParentWnd != NULL && rect.top == 0 && rect.bottom == 0
|
||||
&& rect.left == 0 && rect.right == 0)
|
||||
{
|
||||
LPRECT wndrect = NULL;
|
||||
GetWindowRect(hParentWnd, wndrect);
|
||||
@ -150,12 +204,11 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewp
|
||||
pptviewobj[id].rect.bottom = rect.bottom;
|
||||
pptviewobj[id].rect.right = rect.right;
|
||||
}
|
||||
strcat_s(cmdline, MAX_PATH * 2, "/F /S \"");
|
||||
strcat_s(cmdline, MAX_PATH * 2, filename);
|
||||
strcat_s(cmdline, MAX_PATH * 2, "\"");
|
||||
memset(&si, 0, sizeof(si));
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
BOOL gotinfo = GetPPTInfo(id);
|
||||
return gotinfo;
|
||||
}
|
||||
BOOL StartPPTView(int id)
|
||||
{
|
||||
/*
|
||||
* I'd really like to just hook on the new threadid. However this always gives
|
||||
* error 87. Perhaps I'm hooking to soon? No idea... however can't wait
|
||||
@ -164,69 +217,47 @@ DllExport int OpenPPT(char *filename, HWND hParentWnd, RECT rect, char *previewp
|
||||
*
|
||||
* hook = SetWindowsHookEx(WH_CBT,CbtProc,hInstance,pi.dwThreadId);
|
||||
*/
|
||||
if(globalhook!=NULL)
|
||||
DEBUG("StartPPTView\n");
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
char cmdline[MAX_PATH * 2];
|
||||
|
||||
if(globalhook != NULL)
|
||||
UnhookWindowsHookEx(globalhook);
|
||||
globalhook = SetWindowsHookEx(WH_CBT,CbtProc,hInstance,NULL);
|
||||
if(globalhook==0)
|
||||
globalhook = SetWindowsHookEx(WH_CBT, CbtProc, hInstance, NULL);
|
||||
if(globalhook == 0)
|
||||
{
|
||||
DEBUG("OpenPPT: SetWindowsHookEx failed\n");
|
||||
ClosePPT(id);
|
||||
return -1;
|
||||
return FALSE;
|
||||
}
|
||||
if(GetPPTViewerPath(cmdline, sizeof(cmdline)) == FALSE)
|
||||
{
|
||||
DEBUG("OpenPPT: GetPPTViewerPath failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
pptviewobj[id].state = PPT_STARTED;
|
||||
Sleep(10);
|
||||
strcat_s(cmdline, MAX_PATH * 2, "/F /S \"");
|
||||
strcat_s(cmdline, MAX_PATH * 2, pptviewobj[id].filename);
|
||||
strcat_s(cmdline, MAX_PATH * 2, "\"");
|
||||
memset(&si, 0, sizeof(si));
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
if(!CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, 0, NULL, &si, &pi))
|
||||
{
|
||||
DEBUG("OpenPPT: CreateProcess failed\n");
|
||||
ClosePPT(id);
|
||||
return -1;
|
||||
return FALSE;
|
||||
}
|
||||
pptviewobj[id].dwProcessId = pi.dwProcessId;
|
||||
pptviewobj[id].dwThreadId = pi.dwThreadId;
|
||||
pptviewobj[id].hThread = pi.hThread;
|
||||
pptviewobj[id].hProcess = pi.hProcess;
|
||||
while(pptviewobj[id].state==PPT_STARTED)
|
||||
while(pptviewobj[id].state == PPT_STARTED)
|
||||
Sleep(10);
|
||||
if(gotinfo)
|
||||
{
|
||||
DEBUG("OpenPPT: Info loaded, no refresh\n");
|
||||
pptviewobj[id].state = PPT_LOADED;
|
||||
Resume(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG("OpenPPT: Get info\n");
|
||||
pptviewobj[id].steps = 0;
|
||||
int steps = 0;
|
||||
while(pptviewobj[id].state==PPT_OPENED)
|
||||
{
|
||||
if(steps<=pptviewobj[id].steps)
|
||||
{
|
||||
Sleep(20);
|
||||
DEBUG("OpenPPT: Step %d/%d\n",steps,pptviewobj[id].steps);
|
||||
steps++;
|
||||
NextStep(id);
|
||||
}
|
||||
Sleep(10);
|
||||
}
|
||||
DEBUG("OpenPPT: Steps %d, first slide steps %d\n",pptviewobj[id].steps,pptviewobj[id].firstSlideSteps);
|
||||
SavePPTInfo(id);
|
||||
if(pptviewobj[id].state==PPT_CLOSING||pptviewobj[id].slideCount<=0){
|
||||
ClosePPT(id);
|
||||
id=-1;
|
||||
}
|
||||
else
|
||||
RestartShow(id);
|
||||
}
|
||||
if(id>=0)
|
||||
{
|
||||
if(pptviewobj[id].mhook!=NULL)
|
||||
UnhookWindowsHookEx(pptviewobj[id].mhook);
|
||||
pptviewobj[id].mhook = NULL;
|
||||
}
|
||||
DEBUG("OpenPPT: Exit: id=%i\n", id);
|
||||
return id;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Load information about the ppt from an info.txt file.
|
||||
// Format:
|
||||
// version
|
||||
@ -242,26 +273,26 @@ BOOL GetPPTInfo(int id)
|
||||
char buf[100];
|
||||
|
||||
DEBUG("GetPPTInfo: start\n");
|
||||
if(_stat(pptviewobj[id].filename, &filestats)!=0)
|
||||
if(_stat(pptviewobj[id].filename, &filestats) != 0)
|
||||
return FALSE;
|
||||
sprintf_s(info, MAX_PATH, "%sinfo.txt", pptviewobj[id].previewpath);
|
||||
int err = fopen_s(&pFile, info, "r");
|
||||
if(err!=0)
|
||||
if(err != 0)
|
||||
{
|
||||
DEBUG("GetPPTInfo: file open failed - %d\n", err);
|
||||
return FALSE;
|
||||
}
|
||||
fgets(buf, 100, pFile); // version == 1
|
||||
fgets(buf, 100, pFile);
|
||||
if(filestats.st_mtime!=atoi(buf))
|
||||
if(filestats.st_mtime != atoi(buf))
|
||||
{
|
||||
fclose (pFile);
|
||||
return FALSE;
|
||||
}
|
||||
fgets(buf, 100, pFile);
|
||||
if(filestats.st_size!=atoi(buf))
|
||||
if(filestats.st_size != atoi(buf))
|
||||
{
|
||||
fclose (pFile);
|
||||
fclose(pFile);
|
||||
return FALSE;
|
||||
}
|
||||
fgets(buf, 100, pFile); // slidecount
|
||||
@ -269,10 +300,11 @@ BOOL GetPPTInfo(int id)
|
||||
fgets(buf, 100, pFile); // first slide steps
|
||||
int firstslidesteps = atoi(buf);
|
||||
// check all the preview images still exist
|
||||
for(int i = 1; i<=slidecount; i++)
|
||||
for(int i = 1; i <= slidecount; i++)
|
||||
{
|
||||
sprintf_s(info, MAX_PATH, "%s%i.bmp", pptviewobj[id].previewpath, i);
|
||||
if(GetFileAttributes(info)==INVALID_FILE_ATTRIBUTES)
|
||||
sprintf_s(info, MAX_PATH, "%s%i.bmp",
|
||||
pptviewobj[id].previewpath, i);
|
||||
if(GetFileAttributes(info) == INVALID_FILE_ATTRIBUTES)
|
||||
return FALSE;
|
||||
}
|
||||
fclose(pFile);
|
||||
@ -289,18 +321,22 @@ BOOL SavePPTInfo(int id)
|
||||
FILE* pFile;
|
||||
|
||||
DEBUG("SavePPTInfo: start\n");
|
||||
if(_stat(pptviewobj[id].filename, &filestats)!=0)
|
||||
if(_stat(pptviewobj[id].filename, &filestats) != 0)
|
||||
{
|
||||
DEBUG("SavePPTInfo: stat of %s failed\n", pptviewobj[id].filename);
|
||||
return FALSE;
|
||||
}
|
||||
sprintf_s(info, MAX_PATH, "%sinfo.txt", pptviewobj[id].previewpath);
|
||||
int err = fopen_s(&pFile, info, "w");
|
||||
if(err!=0)
|
||||
if(err != 0)
|
||||
{
|
||||
DEBUG("SavePPTInfo: fopen of %s failed%i\n", info, err);
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG("SavePPTInfo: fopen of %s succeeded\n", info);
|
||||
}
|
||||
fprintf(pFile, "1\n");
|
||||
fprintf(pFile, "%u\n", filestats.st_mtime);
|
||||
fprintf(pFile, "%u\n", filestats.st_size);
|
||||
@ -319,15 +355,28 @@ BOOL GetPPTViewerPath(char *pptviewerpath, int strsize)
|
||||
LRESULT lresult;
|
||||
|
||||
DEBUG("GetPPTViewerPath: start\n");
|
||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "PowerPointViewer.Show.12\\shell\\Show\\command", 0, KEY_READ, &hkey)!=ERROR_SUCCESS)
|
||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "Applications\\PPTVIEW.EXE\\shell\\open\\command", 0, KEY_READ, &hkey)!=ERROR_SUCCESS)
|
||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "Applications\\PPTVIEW.EXE\\shell\\Show\\command", 0, KEY_READ, &hkey)!=ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT,
|
||||
"PowerPointViewer.Show.12\\shell\\Show\\command",
|
||||
0, KEY_READ, &hkey)!=ERROR_SUCCESS)
|
||||
{
|
||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT,
|
||||
"Applications\\PPTVIEW.EXE\\shell\\open\\command",
|
||||
0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
{
|
||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT,
|
||||
"Applications\\PPTVIEW.EXE\\shell\\Show\\command",
|
||||
0, KEY_READ, &hkey) != ERROR_SUCCESS)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
dwtype = REG_SZ;
|
||||
dwsize = (DWORD)strsize;
|
||||
lresult = RegQueryValueEx(hkey, NULL, NULL, &dwtype, (LPBYTE)pptviewerpath, &dwsize );
|
||||
lresult = RegQueryValueEx(hkey, NULL, NULL, &dwtype,
|
||||
(LPBYTE)pptviewerpath, &dwsize);
|
||||
RegCloseKey(hkey);
|
||||
if(lresult!=ERROR_SUCCESS)
|
||||
if(lresult != ERROR_SUCCESS)
|
||||
return FALSE;
|
||||
pptviewerpath[strlen(pptviewerpath)-4] = '\0'; // remove "%1" from end of key value
|
||||
DEBUG("GetPPTViewerPath: exit ok\n");
|
||||
@ -338,9 +387,9 @@ BOOL GetPPTViewerPath(char *pptviewerpath, int strsize)
|
||||
void Unhook(int id)
|
||||
{
|
||||
DEBUG("Unhook: start %d\n", id);
|
||||
if(pptviewobj[id].hook!=NULL)
|
||||
if(pptviewobj[id].hook != NULL)
|
||||
UnhookWindowsHookEx(pptviewobj[id].hook);
|
||||
if(pptviewobj[id].mhook!=NULL)
|
||||
if(pptviewobj[id].mhook != NULL)
|
||||
UnhookWindowsHookEx(pptviewobj[id].mhook);
|
||||
pptviewobj[id].hook = NULL;
|
||||
pptviewobj[id].mhook = NULL;
|
||||
@ -353,7 +402,7 @@ DllExport void ClosePPT(int id)
|
||||
DEBUG("ClosePPT: start%d\n", id);
|
||||
pptviewobj[id].state = PPT_CLOSED;
|
||||
Unhook(id);
|
||||
if(pptviewobj[id].hWnd==0)
|
||||
if(pptviewobj[id].hWnd == 0)
|
||||
TerminateThread(pptviewobj[id].hThread, 0);
|
||||
else
|
||||
PostMessage(pptviewobj[id].hWnd, WM_CLOSE, 0, 0);
|
||||
@ -367,9 +416,10 @@ DllExport void ClosePPT(int id)
|
||||
DllExport void Resume(int id)
|
||||
{
|
||||
DEBUG("Resume: %d\n", id);
|
||||
MoveWindow(pptviewobj[id].hWnd, pptviewobj[id].rect.left, pptviewobj[id].rect.top,
|
||||
pptviewobj[id].rect.right - pptviewobj[id].rect.left,
|
||||
pptviewobj[id].rect.bottom - pptviewobj[id].rect.top, TRUE);
|
||||
MoveWindow(pptviewobj[id].hWnd, pptviewobj[id].rect.left,
|
||||
pptviewobj[id].rect.top,
|
||||
pptviewobj[id].rect.right - pptviewobj[id].rect.left,
|
||||
pptviewobj[id].rect.bottom - pptviewobj[id].rect.top, TRUE);
|
||||
Unblank(id);
|
||||
}
|
||||
// Moves the show off the screen so it can't be seen
|
||||
@ -377,15 +427,15 @@ DllExport void Stop(int id)
|
||||
{
|
||||
DEBUG("Stop:%d\n", id);
|
||||
MoveWindow(pptviewobj[id].hWnd, -32000, -32000,
|
||||
pptviewobj[id].rect.right - pptviewobj[id].rect.left,
|
||||
pptviewobj[id].rect.bottom - pptviewobj[id].rect.top, TRUE);
|
||||
pptviewobj[id].rect.right - pptviewobj[id].rect.left,
|
||||
pptviewobj[id].rect.bottom - pptviewobj[id].rect.top, TRUE);
|
||||
}
|
||||
|
||||
// Return the total number of slides
|
||||
DllExport int GetSlideCount(int id)
|
||||
{
|
||||
DEBUG("GetSlideCount:%d\n", id);
|
||||
if(pptviewobj[id].state==0)
|
||||
if(pptviewobj[id].state == 0)
|
||||
return -1;
|
||||
else
|
||||
return pptviewobj[id].slideCount;
|
||||
@ -395,7 +445,7 @@ DllExport int GetSlideCount(int id)
|
||||
DllExport int GetCurrentSlide(int id)
|
||||
{
|
||||
DEBUG("GetCurrentSlide:%d\n", id);
|
||||
if(pptviewobj[id].state==0)
|
||||
if(pptviewobj[id].state == 0)
|
||||
return -1;
|
||||
else
|
||||
return pptviewobj[id].currentSlide;
|
||||
@ -407,13 +457,17 @@ DllExport void NextStep(int id)
|
||||
DEBUG("NextStep:%d (%d)\n", id, pptviewobj[id].currentSlide);
|
||||
if(pptviewobj[id].currentSlide>pptviewobj[id].slideCount)
|
||||
return;
|
||||
PostMessage(pptviewobj[id].hWnd2, WM_MOUSEWHEEL, MAKEWPARAM(0, -WHEEL_DELTA), 0);
|
||||
pptviewobj[id].guess = pptviewobj[id].currentSlide + 1;
|
||||
PostMessage(pptviewobj[id].hWnd2, WM_MOUSEWHEEL,
|
||||
MAKEWPARAM(0, -WHEEL_DELTA), 0);
|
||||
}
|
||||
|
||||
// Take a step backwards through the show
|
||||
DllExport void PrevStep(int id)
|
||||
{
|
||||
DEBUG("PrevStep:%d (%d)\n", id, pptviewobj[id].currentSlide);
|
||||
if(pptviewobj[id].currentSlide > 1)
|
||||
pptviewobj[id].guess = pptviewobj[id].currentSlide - 1;
|
||||
PostMessage(pptviewobj[id].hWnd2, WM_MOUSEWHEEL, MAKEWPARAM(0, WHEEL_DELTA), 0);
|
||||
}
|
||||
|
||||
@ -469,16 +523,19 @@ DllExport void GotoSlide(int id, int slideno)
|
||||
// the slideshow has focus first
|
||||
char ch[10];
|
||||
|
||||
if(slideno<0) return;
|
||||
if(slideno < 0)
|
||||
return;
|
||||
pptviewobj[id].guess = slideno;
|
||||
_itoa_s(slideno, ch, 10, 10);
|
||||
HWND h1 = GetForegroundWindow();
|
||||
HWND h2 = GetFocus();
|
||||
SetForegroundWindow(pptviewobj[id].hWnd);
|
||||
SetFocus(pptviewobj[id].hWnd);
|
||||
Sleep(50); // slight pause, otherwise event triggering this call may grab focus back!
|
||||
for(int i=0;i<10;i++)
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
if(ch[i]=='\0') break;
|
||||
if(ch[i] == '\0')
|
||||
break;
|
||||
keybd_event((BYTE)ch[i], 0, 0, 0);
|
||||
keybd_event((BYTE)ch[i], 0, KEYEVENTF_KEYUP, 0);
|
||||
}
|
||||
@ -511,12 +568,12 @@ DllExport void RestartShow(int id)
|
||||
DEBUG("RestartShow:%d\n", id);
|
||||
Stop(id);
|
||||
GotoSlide(id, pptviewobj[id].slideCount);
|
||||
while(pptviewobj[id].currentSlide>1)
|
||||
while(pptviewobj[id].currentSlide > 1)
|
||||
{
|
||||
PrevStep(id);
|
||||
Sleep(10);
|
||||
}
|
||||
for(int i=0;i<=pptviewobj[id].firstSlideSteps;i++)
|
||||
for(int i = 0; i <= pptviewobj[id].firstSlideSteps; i++)
|
||||
{
|
||||
PrevStep(id);
|
||||
Sleep(10);
|
||||
@ -531,53 +588,55 @@ DllExport void RestartShow(int id)
|
||||
LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
HHOOK hook = globalhook;
|
||||
if(nCode==HCBT_CREATEWND)
|
||||
if(nCode == HCBT_CREATEWND)
|
||||
{
|
||||
char csClassName[16];
|
||||
HWND hCurrWnd = (HWND)wParam;
|
||||
DWORD retProcId = NULL;
|
||||
GetClassName(hCurrWnd, csClassName, sizeof(csClassName));
|
||||
if((strcmp(csClassName, "paneClassDC")==0)
|
||||
||(strcmp(csClassName, "screenClass")==0))
|
||||
if((strcmp(csClassName, "paneClassDC") == 0)
|
||||
||(strcmp(csClassName, "screenClass") == 0))
|
||||
{
|
||||
int id=-1;
|
||||
int id = -1;
|
||||
DWORD windowthread = GetWindowThreadProcessId(hCurrWnd,NULL);
|
||||
for(int i=0; i<MAX_PPTOBJS; i++)
|
||||
for(int i = 0; i < MAX_PPTOBJS; i++)
|
||||
{
|
||||
if(pptviewobj[i].dwThreadId==windowthread)
|
||||
if(pptviewobj[i].dwThreadId == windowthread)
|
||||
{
|
||||
id=i;
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(id>=0)
|
||||
if(id >= 0)
|
||||
{
|
||||
if(strcmp(csClassName, "paneClassDC")==0)
|
||||
if(strcmp(csClassName, "paneClassDC") == 0)
|
||||
pptviewobj[id].hWnd2=hCurrWnd;
|
||||
else
|
||||
{
|
||||
pptviewobj[id].hWnd=hCurrWnd;
|
||||
pptviewobj[id].hWnd = hCurrWnd;
|
||||
CBT_CREATEWND* cw = (CBT_CREATEWND*)lParam;
|
||||
if(pptviewobj[id].hParentWnd!=NULL)
|
||||
if(pptviewobj[id].hParentWnd != NULL)
|
||||
cw->lpcs->hwndParent = pptviewobj[id].hParentWnd;
|
||||
cw->lpcs->cy=(pptviewobj[id].rect.bottom-pptviewobj[id].rect.top);
|
||||
cw->lpcs->cx=(pptviewobj[id].rect.right-pptviewobj[id].rect.left);
|
||||
cw->lpcs->y=-32000;
|
||||
cw->lpcs->x=-32000;
|
||||
cw->lpcs->cy = (pptviewobj[id].rect.bottom-pptviewobj[id].rect.top);
|
||||
cw->lpcs->cx = (pptviewobj[id].rect.right-pptviewobj[id].rect.left);
|
||||
cw->lpcs->y = -32000;
|
||||
cw->lpcs->x = -32000;
|
||||
}
|
||||
if((pptviewobj[id].hWnd!=NULL)&&(pptviewobj[id].hWnd2!=NULL))
|
||||
if((pptviewobj[id].hWnd != NULL) && (pptviewobj[id].hWnd2 != NULL))
|
||||
{
|
||||
UnhookWindowsHookEx(globalhook);
|
||||
globalhook=NULL;
|
||||
pptviewobj[id].hook = SetWindowsHookEx(WH_CALLWNDPROC,CwpProc,hInstance,pptviewobj[id].dwThreadId);
|
||||
pptviewobj[id].mhook = SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,hInstance,pptviewobj[id].dwThreadId);
|
||||
globalhook = NULL;
|
||||
pptviewobj[id].hook = SetWindowsHookEx(WH_CALLWNDPROC,
|
||||
CwpProc,hInstance, pptviewobj[id].dwThreadId);
|
||||
pptviewobj[id].mhook = SetWindowsHookEx(WH_GETMESSAGE,
|
||||
GetMsgProc, hInstance, pptviewobj[id].dwThreadId);
|
||||
Sleep(10);
|
||||
pptviewobj[id].state = PPT_OPENED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(hook,nCode,wParam,lParam);
|
||||
return CallNextHookEx(hook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
// This hook exists whilst the slideshow is loading but only listens on the
|
||||
@ -586,22 +645,23 @@ LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
HHOOK hook = NULL;
|
||||
MSG *pMSG = (MSG *)lParam;
|
||||
DWORD windowthread = GetWindowThreadProcessId(pMSG->hwnd,NULL);
|
||||
int id=-1;
|
||||
for(int i=0; i<MAX_PPTOBJS; i++)
|
||||
DWORD windowthread = GetWindowThreadProcessId(pMSG->hwnd, NULL);
|
||||
int id = -1;
|
||||
for(int i = 0; i < MAX_PPTOBJS; i++)
|
||||
{
|
||||
if(pptviewobj[i].dwThreadId==windowthread)
|
||||
if(pptviewobj[i].dwThreadId == windowthread)
|
||||
{
|
||||
id=i;
|
||||
id = i;
|
||||
hook = pptviewobj[id].mhook;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(id>=0&&nCode==HC_ACTION&&wParam==PM_REMOVE&&pMSG->message==WM_MOUSEWHEEL)
|
||||
if(id >= 0 && nCode == HC_ACTION && wParam == PM_REMOVE
|
||||
&& pMSG->message == WM_MOUSEWHEEL)
|
||||
{
|
||||
if(pptviewobj[id].state!=PPT_LOADED)
|
||||
if(pptviewobj[id].state != PPT_LOADED)
|
||||
{
|
||||
if(pptviewobj[id].currentSlide==1)
|
||||
if(pptviewobj[id].currentSlide == 1)
|
||||
pptviewobj[id].firstSlideSteps++;
|
||||
pptviewobj[id].steps++;
|
||||
}
|
||||
@ -610,60 +670,94 @@ LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
// This hook exists whilst the slideshow is running but only listens on the
|
||||
// slideshows thread. It listens out for slide changes, message WM_USER+22.
|
||||
LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam){
|
||||
LRESULT CALLBACK CwpProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
CWPSTRUCT *cwp;
|
||||
cwp = (CWPSTRUCT *)lParam;
|
||||
HHOOK hook = NULL;
|
||||
char filename[MAX_PATH];
|
||||
|
||||
DWORD windowthread = GetWindowThreadProcessId(cwp->hwnd,NULL);
|
||||
int id=-1;
|
||||
for(int i=0; i<MAX_PPTOBJS; i++)
|
||||
DWORD windowthread = GetWindowThreadProcessId(cwp->hwnd, NULL);
|
||||
int id = -1;
|
||||
for(int i = 0; i < MAX_PPTOBJS; i++)
|
||||
{
|
||||
if(pptviewobj[i].dwThreadId==windowthread)
|
||||
if(pptviewobj[i].dwThreadId == windowthread)
|
||||
{
|
||||
id=i;
|
||||
id = i;
|
||||
hook = pptviewobj[id].hook;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((id>=0)&&(nCode==HC_ACTION))
|
||||
if((id >= 0) && (nCode == HC_ACTION))
|
||||
{
|
||||
if(cwp->message==WM_USER+22)
|
||||
{
|
||||
if(cwp->message == WM_USER + 22)
|
||||
{
|
||||
if(pptviewobj[id].state != PPT_LOADED)
|
||||
{
|
||||
if((pptviewobj[id].currentSlide>0)
|
||||
&& (pptviewobj[id].previewpath!=NULL&&strlen(pptviewobj[id].previewpath)>0))
|
||||
if((pptviewobj[id].currentSlide > 0)
|
||||
&& (pptviewobj[id].previewpath != NULL
|
||||
&& strlen(pptviewobj[id].previewpath) > 0))
|
||||
{
|
||||
sprintf_s(filename, MAX_PATH, "%s%i.bmp", pptviewobj[id].previewpath, pptviewobj[id].currentSlide);
|
||||
sprintf_s(filename, MAX_PATH, "%s%i.bmp", pptviewobj[id].previewpath,
|
||||
pptviewobj[id].currentSlide);
|
||||
CaptureAndSaveWindow(cwp->hwnd, filename);
|
||||
}
|
||||
}
|
||||
if(cwp->wParam==0)
|
||||
if(cwp->wParam == 0)
|
||||
{
|
||||
if(pptviewobj[id].currentSlide>0)
|
||||
if(pptviewobj[id].currentSlide > 0)
|
||||
{
|
||||
pptviewobj[id].state = PPT_LOADED;
|
||||
pptviewobj[id].currentSlide = pptviewobj[id].slideCount+1;
|
||||
pptviewobj[id].currentSlide = pptviewobj[id].slideCount + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pptviewobj[id].currentSlide = cwp->wParam - 255;
|
||||
if(pptviewobj[id].state != PPT_LOADED)
|
||||
{
|
||||
if(pptviewobj[id].currentSlide<pptviewobj[id].slideCount)
|
||||
if((pptviewobj[id].currentSlide == 0)
|
||||
||(pptviewobj[id].slideNo[pptviewobj[id].currentSlide] != cwp->wParam))
|
||||
{
|
||||
pptviewobj[id].state = PPT_LOADED;
|
||||
if(pptviewobj[id].slideNo[1] == cwp->wParam)
|
||||
{
|
||||
pptviewobj[id].state = PPT_LOADED;
|
||||
}
|
||||
else
|
||||
{
|
||||
pptviewobj[id].currentSlide++;
|
||||
pptviewobj[id].slideCount = pptviewobj[id].currentSlide;
|
||||
pptviewobj[id].slideNo[pptviewobj[id].currentSlide] = cwp->wParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pptviewobj[id].guess > 0
|
||||
&& pptviewobj[id].slideNo[pptviewobj[id].guess] == 0)
|
||||
{
|
||||
pptviewobj[id].currentSlide = 0;
|
||||
}
|
||||
for(int i = 1; i < pptviewobj[id].slideCount; i++)
|
||||
{
|
||||
if(pptviewobj[id].slideNo[i] == cwp->wParam)
|
||||
{
|
||||
pptviewobj[id].currentSlide = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(pptviewobj[id].currentSlide == 0)
|
||||
{
|
||||
pptviewobj[id].slideNo[pptviewobj[id].guess] = cwp->wParam;
|
||||
pptviewobj[id].currentSlide = pptviewobj[id].guess;
|
||||
}
|
||||
}
|
||||
if(pptviewobj[id].currentSlide>pptviewobj[id].slideCount)
|
||||
pptviewobj[id].slideCount = pptviewobj[id].currentSlide;
|
||||
}
|
||||
}
|
||||
if((pptviewobj[id].state != PPT_CLOSED)&&(cwp->message==WM_CLOSE||cwp->message==WM_QUIT))
|
||||
if((pptviewobj[id].state != PPT_CLOSED)
|
||||
&& (cwp->message == WM_CLOSE || cwp->message == WM_QUIT))
|
||||
{
|
||||
pptviewobj[id].state = PPT_CLOSING;
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(hook,nCode,wParam,lParam);
|
||||
}
|
||||
@ -685,26 +779,26 @@ VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename)
|
||||
UINT uiBytesPerAllRows = uiBytesPerRow * client.bottom;
|
||||
PBYTE pDataBits;
|
||||
|
||||
if ((pDataBits = new BYTE [uiBytesPerAllRows]) != NULL)
|
||||
if ((pDataBits = new BYTE[uiBytesPerAllRows]) != NULL)
|
||||
{
|
||||
BITMAPINFOHEADER bmi = {0};
|
||||
BITMAPFILEHEADER bmf = {0};
|
||||
|
||||
// Prepare to get the data out of HBITMAP:
|
||||
bmi.biSize = sizeof (bmi);
|
||||
bmi.biSize = sizeof(bmi);
|
||||
bmi.biPlanes = 1;
|
||||
bmi.biBitCount = 24;
|
||||
bmi.biHeight = client.bottom;
|
||||
bmi.biWidth = client.right;
|
||||
|
||||
// Get it:
|
||||
HDC hDC = GetDC (hWnd);
|
||||
GetDIBits (hDC, hBmp, 0, client.bottom, pDataBits,
|
||||
(BITMAPINFO*) &bmi, DIB_RGB_COLORS);
|
||||
ReleaseDC (hWnd, hDC);
|
||||
HDC hDC = GetDC(hWnd);
|
||||
GetDIBits(hDC, hBmp, 0, client.bottom, pDataBits,
|
||||
(BITMAPINFO*) &bmi, DIB_RGB_COLORS);
|
||||
ReleaseDC(hWnd, hDC);
|
||||
|
||||
// Fill the file header:
|
||||
bmf.bfOffBits = sizeof (bmf) + sizeof (bmi);
|
||||
bmf.bfOffBits = sizeof(bmf) + sizeof(bmi);
|
||||
bmf.bfSize = bmf.bfOffBits + uiBytesPerAllRows;
|
||||
bmf.bfType = 0x4D42;
|
||||
|
||||
@ -713,31 +807,33 @@ VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename)
|
||||
int err = fopen_s(&pFile, filename, "wb");
|
||||
if (err == 0)
|
||||
{
|
||||
fwrite (&bmf, sizeof (bmf), 1, pFile);
|
||||
fwrite (&bmi, sizeof (bmi), 1, pFile);
|
||||
fwrite (pDataBits, sizeof (BYTE), uiBytesPerAllRows, pFile);
|
||||
fclose (pFile);
|
||||
fwrite(&bmf, sizeof(bmf), 1, pFile);
|
||||
fwrite(&bmi, sizeof(bmi), 1, pFile);
|
||||
fwrite(pDataBits, sizeof(BYTE), uiBytesPerAllRows, pFile);
|
||||
fclose(pFile);
|
||||
}
|
||||
delete [] pDataBits;
|
||||
}
|
||||
DeleteObject (hBmp);
|
||||
DeleteObject(hBmp);
|
||||
}
|
||||
HBITMAP CaptureWindow (HWND hWnd) {
|
||||
HBITMAP CaptureWindow(HWND hWnd)
|
||||
{
|
||||
HDC hDC;
|
||||
BOOL bOk = FALSE;
|
||||
HBITMAP hImage = NULL;
|
||||
|
||||
hDC = GetDC (hWnd);
|
||||
hDC = GetDC(hWnd);
|
||||
RECT rcClient;
|
||||
GetClientRect (hWnd, &rcClient);
|
||||
if ((hImage = CreateCompatibleBitmap (hDC, rcClient.right, rcClient.bottom)) != NULL)
|
||||
GetClientRect(hWnd, &rcClient);
|
||||
if((hImage = CreateCompatibleBitmap(hDC, rcClient.right, rcClient.bottom))
|
||||
!= NULL)
|
||||
{
|
||||
HDC hMemDC;
|
||||
HBITMAP hDCBmp;
|
||||
|
||||
if ((hMemDC = CreateCompatibleDC (hDC)) != NULL)
|
||||
if((hMemDC = CreateCompatibleDC (hDC)) != NULL)
|
||||
{
|
||||
hDCBmp = (HBITMAP) SelectObject (hMemDC, hImage);
|
||||
hDCBmp = (HBITMAP)SelectObject(hMemDC, hImage);
|
||||
HMODULE hLib = LoadLibrary("User32");
|
||||
// PrintWindow works for windows outside displayable area
|
||||
// but was only introduced in WinXP. BitBlt requires the window to be topmost
|
||||
@ -757,14 +853,14 @@ HBITMAP CaptureWindow (HWND hWnd) {
|
||||
bOk = TRUE;
|
||||
}
|
||||
}
|
||||
ReleaseDC (hWnd, hDC);
|
||||
if (! bOk)
|
||||
ReleaseDC(hWnd, hDC);
|
||||
if(!bOk)
|
||||
{
|
||||
if (hImage)
|
||||
{
|
||||
DeleteObject (hImage);
|
||||
DeleteObject(hImage);
|
||||
hImage = NULL;
|
||||
}
|
||||
}
|
||||
return hImage;
|
||||
}
|
||||
}
|
Binary file not shown.
@ -27,11 +27,14 @@ VOID SaveBitmap (CHAR* filename, HBITMAP hBmp) ;
|
||||
VOID CaptureAndSaveWindow(HWND hWnd, CHAR* filename);
|
||||
BOOL GetPPTInfo(int id);
|
||||
BOOL SavePPTInfo(int id);
|
||||
|
||||
BOOL InitPPTObject(int id, char *filename, HWND hParentWnd,
|
||||
RECT rect, char *previewpath);
|
||||
BOOL StartPPTView(int id);
|
||||
|
||||
void Unhook(int id);
|
||||
|
||||
#define MAX_PPTOBJS 50
|
||||
#define MAX_PPTOBJS 16
|
||||
#define MAX_SLIDES 256
|
||||
|
||||
struct PPTVIEWOBJ
|
||||
{
|
||||
@ -49,7 +52,9 @@ struct PPTVIEWOBJ
|
||||
int currentSlide;
|
||||
int firstSlideSteps;
|
||||
int steps;
|
||||
int guess;
|
||||
char filename[MAX_PATH];
|
||||
char previewpath[MAX_PATH];
|
||||
int slideNo[MAX_SLIDES];
|
||||
PPTVIEWSTATE state;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user