|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <windows.h></windows.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwain_win.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwain_winPD.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwain_state.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttwain_error.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define HINSTLIB0 0
|
|
Toshihiro Shimizu |
890ddd |
static HWND Dummy = 0; /* proxy window */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
extern int TTWAIN_MessageHook(void *lpmsg);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static HWND CreateDummyWindow(void)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
HWND hwnd;
|
|
Toshihiro Shimizu |
890ddd |
hwnd = CreateWindow("STATIC", // class
|
|
Toshihiro Shimizu |
890ddd |
"Acquire Dummy", // title
|
|
Toshihiro Shimizu |
890ddd |
WS_POPUPWINDOW, // style
|
|
Toshihiro Shimizu |
890ddd |
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
|
Toshihiro Shimizu |
890ddd |
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
|
Toshihiro Shimizu |
890ddd |
HWND_DESKTOP, // parent window
|
|
Toshihiro Shimizu |
890ddd |
NULL, // hmenu
|
|
Toshihiro Shimizu |
890ddd |
HINSTLIB0, // hinst
|
|
Toshihiro Shimizu |
890ddd |
NULL); // lpvparam
|
|
Toshihiro Shimizu |
890ddd |
return hwnd;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void *TTWAIN_GetValidHwndPD(void *_hwnd)
|
|
Toshihiro Shimizu |
890ddd |
// Returns a valid window handle as follows:
|
|
Toshihiro Shimizu |
890ddd |
// If hwnd is a valid window handle, hwnd is returned.
|
|
Toshihiro Shimizu |
890ddd |
// Otherwise a proxy window handle is created and returned.
|
|
Toshihiro Shimizu |
890ddd |
// Once created, a proxy window handle is destroyed when
|
|
Toshihiro Shimizu |
890ddd |
// the source manager is unloaded.
|
|
Toshihiro Shimizu |
890ddd |
// If hwnd is an invalid window handle (other than NULL)
|
|
Toshihiro Shimizu |
890ddd |
// an error box is displayed.
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
HWND hwnd = (HWND)_hwnd;
|
|
Toshihiro Shimizu |
890ddd |
if (!IsWindow(hwnd)) {
|
|
Toshihiro Shimizu |
890ddd |
if (hwnd != NULL) {
|
|
Toshihiro Shimizu |
890ddd |
assert(!"Window handle is invalid");
|
|
Toshihiro Shimizu |
890ddd |
hwnd = NULL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!Dummy) {
|
|
Toshihiro Shimizu |
890ddd |
Dummy = CreateDummyWindow();
|
|
Toshihiro Shimizu |
890ddd |
if (!IsWindow(Dummy)) {
|
|
Toshihiro Shimizu |
890ddd |
assert(!"Unable to create Dummy window");
|
|
Toshihiro Shimizu |
890ddd |
Dummy = NULL;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
hwnd = Dummy;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return (void *)hwnd;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
void TTWAIN_EmptyMessageQueuePD(void)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
MSG msg;
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
OutputDebugString("EmptyMsgQ<");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
while (PeekMessage((LPMSG)&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
Toshihiro Shimizu |
890ddd |
if (!TTWAIN_MessageHook((LPMSG)&msg)) {
|
|
Toshihiro Shimizu |
890ddd |
TranslateMessage((LPMSG)&msg);
|
|
Toshihiro Shimizu |
890ddd |
DispatchMessage((LPMSG)&msg);
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
OutputDebugString("-");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
OutputDebugString("T");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Toshihiro Shimizu |
890ddd |
OutputDebugString(">\n");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TTWAIN_ModalEventLoopPD(void)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
MSG msg;
|
|
Toshihiro Shimizu |
890ddd |
// Clear global breakout flag
|
|
Toshihiro Shimizu |
890ddd |
TTwainData.breakModalLoop = FALSE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
while ((TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED) && !TTwainData.breakModalLoop && GetMessage((LPMSG)&msg, NULL, 0, 0)) {
|
|
Toshihiro Shimizu |
890ddd |
if (!TTWAIN_MessageHook((LPMSG)&msg)) {
|
|
Toshihiro Shimizu |
890ddd |
TranslateMessage((LPMSG)&msg);
|
|
Toshihiro Shimizu |
890ddd |
DispatchMessage((LPMSG)&msg);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} // while
|
|
Toshihiro Shimizu |
890ddd |
TTwainData.breakModalLoop = FALSE;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
int TTWAIN_EnableWindowPD(void *hwnd, int flag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return EnableWindow(hwnd, flag);
|
|
Toshihiro Shimizu |
890ddd |
}
|