|
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 |
|
|
Shinya Kitaoka |
120a6e |
static HWND CreateDummyWindow(void) {
|
|
Shinya Kitaoka |
120a6e |
HWND hwnd;
|
|
Shinya Kitaoka |
120a6e |
hwnd = CreateWindow("STATIC", // class
|
|
Shinya Kitaoka |
120a6e |
"Acquire Dummy", // title
|
|
Shinya Kitaoka |
120a6e |
WS_POPUPWINDOW, // style
|
|
Shinya Kitaoka |
120a6e |
CW_USEDEFAULT, CW_USEDEFAULT, // x, y
|
|
Shinya Kitaoka |
120a6e |
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
|
|
Shinya Kitaoka |
120a6e |
HWND_DESKTOP, // parent window
|
|
Shinya Kitaoka |
120a6e |
NULL, // hmenu
|
|
Shinya Kitaoka |
120a6e |
HINSTLIB0, // hinst
|
|
Shinya Kitaoka |
120a6e |
NULL); // lpvparam
|
|
Shinya Kitaoka |
120a6e |
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 |
{
|
|
Shinya Kitaoka |
120a6e |
HWND hwnd = (HWND)_hwnd;
|
|
Shinya Kitaoka |
120a6e |
if (!IsWindow(hwnd)) {
|
|
Shinya Kitaoka |
120a6e |
if (hwnd != NULL) {
|
|
Shinya Kitaoka |
120a6e |
assert(!"Window handle is invalid");
|
|
Shinya Kitaoka |
120a6e |
hwnd = NULL;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (!Dummy) {
|
|
Shinya Kitaoka |
120a6e |
Dummy = CreateDummyWindow();
|
|
Shinya Kitaoka |
120a6e |
if (!IsWindow(Dummy)) {
|
|
Shinya Kitaoka |
120a6e |
assert(!"Unable to create Dummy window");
|
|
Shinya Kitaoka |
120a6e |
Dummy = NULL;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
hwnd = Dummy;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return (void *)hwnd;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Shinya Kitaoka |
120a6e |
void TTWAIN_EmptyMessageQueuePD(void) {
|
|
Shinya Kitaoka |
120a6e |
MSG msg;
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Shinya Kitaoka |
120a6e |
OutputDebugString("EmptyMsgQ<");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
while (PeekMessage((LPMSG)&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
Shinya Kitaoka |
120a6e |
if (!TTWAIN_MessageHook((LPMSG)&msg)) {
|
|
Shinya Kitaoka |
120a6e |
TranslateMessage((LPMSG)&msg);
|
|
Shinya Kitaoka |
120a6e |
DispatchMessage((LPMSG)&msg);
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Shinya Kitaoka |
120a6e |
OutputDebugString("-");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Shinya Kitaoka |
120a6e |
OutputDebugString("T");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _DEBUG
|
|
Shinya Kitaoka |
120a6e |
OutputDebugString(">\n");
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TTWAIN_ModalEventLoopPD(void) {
|
|
Shinya Kitaoka |
120a6e |
MSG msg;
|
|
Shinya Kitaoka |
120a6e |
// Clear global breakout flag
|
|
Shinya Kitaoka |
120a6e |
TTwainData.breakModalLoop = FALSE;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
while ((TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED) &&
|
|
Shinya Kitaoka |
120a6e |
!TTwainData.breakModalLoop && GetMessage((LPMSG)&msg, NULL, 0, 0)) {
|
|
Shinya Kitaoka |
120a6e |
if (!TTWAIN_MessageHook((LPMSG)&msg)) {
|
|
Shinya Kitaoka |
120a6e |
TranslateMessage((LPMSG)&msg);
|
|
Shinya Kitaoka |
120a6e |
DispatchMessage((LPMSG)&msg);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} // while
|
|
Shinya Kitaoka |
120a6e |
TTwainData.breakModalLoop = FALSE;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
int TTWAIN_EnableWindowPD(void *hwnd, int flag) {
|
|
Shinya Kitaoka |
120a6e |
return EnableWindow(hwnd, flag);
|
|
Toshihiro Shimizu |
890ddd |
}
|