Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Processing messages

Processing messages

Scheduled Pinned Locked Moved C / C++ / MFC
databasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    ffazly
    wrote on last edited by
    #1

    Hi. I have a question with regards to processing windows messages. I have a block of pseudo code below: while (TRUE) { //play a tone // get user response (keyboard input) responded = get_response() ; // if no response, increase by 5 dB, go to "play tone" if (responded == FALSE) // else process the response else { //process response threshold_found = process_success(); //if threshold not found, decrease by 10 dB, go to "play tone" if (threshold_found == FALSE) // else record threshold and go to next frequency, // restore familiarization_level, go to "play tone" else { record_threshold() ; // restart the test at the next frequency restart = restartTest() ; // if finished with test get out of while loop if(restart == FALSE) break ; } } } I want to be able to receive keyboard messages while this while loop is executing and also to be able to detect any other messages like button clicks, etc... I've tried to use PeekMessage : while(iCheck == BST_CHECKED) { gen_sound(0, 0.02, 1, current_frequency, duration) ; // play tone while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; if(msg.message == WM_COMMAND) { if(msg.wParam == IDC_START) //check if start button has been pressed iCheck = (int) SendMessage(hCtrl, BM_GETCHECK, 0, 0) ; break ; } } } but I can't seem to get it to retrieve any messages. I've implemented this code in a callback function that is subclassed from the main window so that it can intercept the window messages. Any insight on what I maybe doing wrong or any kind of advice on the matter would be greatly appreciated. Fazly

    R 1 Reply Last reply
    0
    • F ffazly

      Hi. I have a question with regards to processing windows messages. I have a block of pseudo code below: while (TRUE) { //play a tone // get user response (keyboard input) responded = get_response() ; // if no response, increase by 5 dB, go to "play tone" if (responded == FALSE) // else process the response else { //process response threshold_found = process_success(); //if threshold not found, decrease by 10 dB, go to "play tone" if (threshold_found == FALSE) // else record threshold and go to next frequency, // restore familiarization_level, go to "play tone" else { record_threshold() ; // restart the test at the next frequency restart = restartTest() ; // if finished with test get out of while loop if(restart == FALSE) break ; } } } I want to be able to receive keyboard messages while this while loop is executing and also to be able to detect any other messages like button clicks, etc... I've tried to use PeekMessage : while(iCheck == BST_CHECKED) { gen_sound(0, 0.02, 1, current_frequency, duration) ; // play tone while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; if(msg.message == WM_COMMAND) { if(msg.wParam == IDC_START) //check if start button has been pressed iCheck = (int) SendMessage(hCtrl, BM_GETCHECK, 0, 0) ; break ; } } } but I can't seem to get it to retrieve any messages. I've implemented this code in a callback function that is subclassed from the main window so that it can intercept the window messages. Any insight on what I maybe doing wrong or any kind of advice on the matter would be greatly appreciated. Fazly

      R Offline
      R Offline
      rrrado
      wrote on last edited by
      #2

      I don't understand what your pseudocode is doing, but generally, you shoud use worker thread to do some work in loop while UI (original) thread is processing messages and controling the worker thread


      rrrado

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups