TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Using the same hWnd for MSG_ENABLEDS doesn't work

Forums › TWAIN Classic › Using the same hWnd for MSG_ENABLEDS doesn't work

  • This topic has 1 reply, 1 voice, and was last updated 1 year, 7 months ago by markm.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • July 25, 2019 at 3:43 am #51064 Reply
    Martin Walter Tan
    • Topics - 98
    • Replies - 191
    • Total Posts - 289

    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:

    
      // https://www.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?

    July 25, 2019 at 9:34 am #51066 Reply
    markm
    • Topics - 98
    • Replies - 191
    • Total Posts - 289

    The 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.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Using the same hWnd for MSG_ENABLEDS doesn't work
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • could not open the twain source. Make sure there is a valid source for your sca
  • Changing TWAIN driver defaults
  • Scanner starts transfer when console gets closed (CITRIX)
  • Kodak RFS 3600
  • Didn’t save enough file scan
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.