Home › Forums › TWAIN Classic › Using the same hWnd for MSG_ENABLEDS doesn't work
- This topic is empty.
- AuthorPosts
- Martin Walter Tan
I was able to get through States 1-5 thanks to the TWAIN examples and posts I read in this forum. I was able to open the DSM using my application’s window handle:
TW_UINT16 rc; // open source manager rc = (*DSM_Entry)(&AppID, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) hWnd); std::cout << "Open Source Manager: " << rc << std::endl; // open select source dialog rc = (*DSM_Entry)(&AppID, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, (TW_MEMREF) &SourceID); std::cout << "Open Select Source Dialog: " << rc << std::endl;
I get the hWnd from a char * casted to (HWND) which is passed from my original application which is not native C++.
User select source dialog works. But then when I try to send MSG_ENABLEDS it doesn’t work and fails with return code (rc) TWRC_FAILURE:TW_USERINTERFACE ui; ui.ShowUI = (TW_BOOL) TRUE; ui.ModalUI = (TW_BOOL) TRUE; ui.hParent = hWnd; rc = (*DSM_Entry)(&AppID, &SourceID, DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, (TW_MEMREF) &ui); std::cout << "Enable DS (Open Dialog): " << rc << std::endl;
However, I was able to make it work when I found another guy’s example, he made a new window using CreateWindow:
// http://twain.org/forums/topic/direct-acquire-without-ui HWND test = CreateWindow("STATIC", "", WS_POPUPWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, 0, hModule, 0); TW_USERINTERFACE ui; ui.ShowUI = (TW_BOOL) TRUE; ui.ModalUI = (TW_BOOL) TRUE; ui.hParent = test; rc = (*DSM_Entry)(&AppID, &SourceID, DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, (TW_MEMREF) &ui); std::cout << "Enable DS (Open Dialog): " << rc << std::endl;
I would like to ask why it doesn’t work when I use my original window handle (hWnd) and it works when I spawn a new window using win32 api?
markmThe most likely candidate is a threading issue. All operations on a window must occur within the same thread where the window was created.
MSG_ENABLEDS must occur in the same thread where CreateWindow was called. Adding the extra CreateWindow probably took care of that. - AuthorPosts