Thread: Windows 7 Machine: Convert Simple "C" Program to Windows "Threaded" Program

  1. #1
    Registered User
    Join Date
    Feb 2022
    Posts
    9

    Windows 7 Machine: Convert Simple "C" Program to Windows "Threaded" Program

    Had started this thread to create a simple "C" Program to emulate a (European) proprietary "graphics box" keyboard(s) that had either completely or partially failed (and nobody could fix them):

    Windows 7 Machine: Simple "C" Program to Read Keyboard Input and Write To Serial Port

    ... and it's working fine ... but it's a "Console Program". Is there a quick way to convert it to a Windows program so that I can read the Mouse input (instead of using the arrow keys)? Also found out the status of the SHIFT key apparently needs to be read via a Windows-type program because for many of the programmable keys on the LOGIC CONTROLS LK1800 keyboard I'm using, SHIFT-[KEY] produces the same keycode as just pressing [KEY] itself (example: SHIFT-[ARROWUP]) And even though the LK1800 claims you can program in your own keycodes ... it doesn't work! I ended up using either CTRL-[KEY] or ALT-[KEY] instead, but this deviates from the proprietary keyboard, which I'd rather not do (since another OPERATOR-ONLY/NO GRAPHICAL DESIGN emulator in the Plant implements SHIFT-[ARROWKEYS] the same way as the proprietary system did ... and we're used to it working that way).

    Can I just take the "C" code and cut/paste it into a Windows Template "program"? Is that the proper way to do it, or is that a kludge?
    Last edited by Colt Hero; 05-05-2022 at 12:47 PM.

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    985
    Let me understand this: You want to do a GUI application for a keyboard because you want to use the mouse instead of pressing keys?

  3. #3
    Registered User
    Join Date
    Feb 2022
    Posts
    9
    flp1969: No. I don't want to make a GUI keyboard on the screen so I can tap the keyboard buttons instead of pressing keys (if that's what you mean).

    I have a "C" Console Program that I wrote to emulate a proprietary, native keyboard, and now I just want to convert it to a Windows Program. The Console Program works fine, but it would be better as a Windows Program because I could move the Cursor to the graphical editing point on the screen much quicker (and maybe there would be other benefits like being able to select objects easier than even the Native System).

    The other thing is - the Console Program is running on a Windows 7 desktop which is also used for other Lab-Software Functions ... and when the Console Window loses focus (switching to another app), the Keyboard Emulator program stops working until you click the mouse back onto the Console Window. This is not a big deal, but again ... if it was a Windows Program it would work much better.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,211
    First off, a console program is already a windows program.
    Just making it a GUI program would not solve your focus problem for example.

    You should be able to ameliorate the focus problem with this information.
    How do you enable focus follows mouse in Windows 10 - Super User
    With this, you should be able to just move the mouse over your console and type, without the initial get focus click.

    Also, console programs can read the mouse.
    ReadConsoleInput function - Windows Console | Microsoft Docs
    INPUT_RECORD structure - Windows Console | Microsoft Docs
    MOUSE_EVENT_RECORD structure - Windows Console | Microsoft Docs

    > other Lab-Software Functions
    Do you have the source code for this?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2022
    Posts
    9
    Salem: Do I have the source code for the other Lab-Software Functions? No. And one of these other programs - which is already a windows program (XP) with a primitive GUI - is in desperate need of a re-write/upgrade because it's not compliant with audit trail requirements, which results in our having to maintain Log Books with paper signatures and monthly reviews, which sometimes result in further paperwork if the rules are broken .. it's just a royal PITA. That one needs to be something like 6 clients talking to any of 50 proprietary Controllers, and reporting every action taken to a central database, where all the auditing and reporting could be centralized and easily handled.

    But back to the Keyboard Emulator ... I didn't realize I could add Mouse control to a Console Program. OK.

    One other thing: the proprietary Graphics Box this Emulator talks to can sometimes send data back. AFAIK, it might only be the BEEP code "7" (to warn of improper input). Can my Console Program both write AND read at the same time ... or does that necessitate turning it into a GUI program? Doesn't it need to be an "Event Driven" program in order to not "block"? Earlier, when I was playing around with it, I had a separate Console Program that opened an Input Buffer to just read data from the Graphics Box during testing ... to capture what it might've been sending back. But the program would "sit" at the ReadData (input) instruction (blocking), so I left it out of Keyboard Emulator for now (so it would continuously read keyboard data, convert it, and send it out to the Graphics Box).

    Can I re-introduce the ReadData instruction, and if so ... how do you stop it from "blocking"?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,211
    Did you read the rest of the console API?

    PeekConsoleInput function - Windows Console | Microsoft Docs

    There's no need to block on console input with peek.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 03-20-2022, 12:20 PM
  2. Replies: 6
    Last Post: 04-20-2015, 12:29 PM
  3. Replies: 18
    Last Post: 05-26-2008, 11:23 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread