| |
| |
| #include <windows.h> |
| #include <assert.h> |
| #include "ttwain_win.h" |
| #include "ttwain_winPD.h" |
| #include "ttwain_state.h" |
| #include "ttwain_error.h" |
| |
| #define HINSTLIB0 0 |
| static HWND Dummy = 0; |
| |
| extern int TTWAIN_MessageHook(void *lpmsg); |
| |
| static HWND CreateDummyWindow(void) |
| { |
| HWND hwnd; |
| hwnd = CreateWindow("STATIC", |
| "Acquire Dummy", |
| WS_POPUPWINDOW, |
| CW_USEDEFAULT, CW_USEDEFAULT, |
| CW_USEDEFAULT, CW_USEDEFAULT, |
| HWND_DESKTOP, |
| NULL, |
| HINSTLIB0, |
| NULL); |
| return hwnd; |
| } |
| |
| void *TTWAIN_GetValidHwndPD(void *_hwnd) |
| |
| |
| |
| |
| |
| |
| |
| { |
| HWND hwnd = (HWND)_hwnd; |
| if (!IsWindow(hwnd)) { |
| if (hwnd != NULL) { |
| assert(!"Window handle is invalid"); |
| hwnd = NULL; |
| } |
| if (!Dummy) { |
| Dummy = CreateDummyWindow(); |
| if (!IsWindow(Dummy)) { |
| assert(!"Unable to create Dummy window"); |
| Dummy = NULL; |
| } |
| } |
| hwnd = Dummy; |
| } |
| return (void *)hwnd; |
| } |
| |
| void TTWAIN_EmptyMessageQueuePD(void) |
| { |
| MSG msg; |
| #ifdef _DEBUG |
| OutputDebugString("EmptyMsgQ<"); |
| #endif |
| while (PeekMessage((LPMSG)&msg, NULL, 0, 0, PM_REMOVE)) { |
| if (!TTWAIN_MessageHook((LPMSG)&msg)) { |
| TranslateMessage((LPMSG)&msg); |
| DispatchMessage((LPMSG)&msg); |
| #ifdef _DEBUG |
| OutputDebugString("-"); |
| #endif |
| } else { |
| #ifdef _DEBUG |
| OutputDebugString("T"); |
| #endif |
| } |
| } |
| #ifdef _DEBUG |
| OutputDebugString(">\n"); |
| #endif |
| } |
| |
| void TTWAIN_ModalEventLoopPD(void) |
| { |
| MSG msg; |
| |
| TTwainData.breakModalLoop = FALSE; |
| |
| while ((TTWAIN_GetState() >= TWAIN_SOURCE_ENABLED) && !TTwainData.breakModalLoop && GetMessage((LPMSG)&msg, NULL, 0, 0)) { |
| if (!TTWAIN_MessageHook((LPMSG)&msg)) { |
| TranslateMessage((LPMSG)&msg); |
| DispatchMessage((LPMSG)&msg); |
| } |
| } |
| TTwainData.breakModalLoop = FALSE; |
| } |
| int TTWAIN_EnableWindowPD(void *hwnd, int flag) |
| { |
| return EnableWindow(hwnd, flag); |
| } |
| |