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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. a small problem with windows messages (SDK)

a small problem with windows messages (SDK)

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 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.
  • R Offline
    R Offline
    r i s h a b h s
    wrote on last edited by
    #1

    dear all, i've written a small piece of code ( a hidden window) which detects windows shutdown and then logs the timestamp in a file. i'm using the following code in the message loop- while(GetMessage(&Msg, hwnd, 0, 0) > 0) { if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } TranslateMessage(&Msg); DispatchMessage(&Msg); } now my wm_queryendsession handler is as follows case WM_QUERYENDSESSION: { if (lParam & ENDSESSION_LOGOFF) flg_type = 1; //logoff else flg_type = 2; //shut down flg_shutdown = 1; return false; // don't shutdown now. shutdown after Run() is executed } break; the problem is that when i logoff/shutdown nothing happens until i do something with the window (move cursor over it or click on it or resize it). when i do so, everything works fine. what could be the problem. i even tried the following message loop while(GetMessage(&Msg, hwnd, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } } but same problem. can someone help me out. Thanx and Regards

    O 1 Reply Last reply
    0
    • R r i s h a b h s

      dear all, i've written a small piece of code ( a hidden window) which detects windows shutdown and then logs the timestamp in a file. i'm using the following code in the message loop- while(GetMessage(&Msg, hwnd, 0, 0) > 0) { if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } TranslateMessage(&Msg); DispatchMessage(&Msg); } now my wm_queryendsession handler is as follows case WM_QUERYENDSESSION: { if (lParam & ENDSESSION_LOGOFF) flg_type = 1; //logoff else flg_type = 2; //shut down flg_shutdown = 1; return false; // don't shutdown now. shutdown after Run() is executed } break; the problem is that when i logoff/shutdown nothing happens until i do something with the window (move cursor over it or click on it or resize it). when i do so, everything works fine. what could be the problem. i even tried the following message loop while(GetMessage(&Msg, hwnd, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } } but same problem. can someone help me out. Thanx and Regards

      O Offline
      O Offline
      Oliver Anhuth
      wrote on last edited by
      #2

      WM_QUERYENDSESSION is sent which means that it is not seen by the message loop. The code in the message loop will be executed the next time a message is posted to your window. Maybe you should move your code to the message handler. regards Oliver

      R 1 Reply Last reply
      0
      • O Oliver Anhuth

        WM_QUERYENDSESSION is sent which means that it is not seen by the message loop. The code in the message loop will be executed the next time a message is posted to your window. Maybe you should move your code to the message handler. regards Oliver

        R Offline
        R Offline
        r i s h a b h s
        wrote on last edited by
        #3

        thanx for ur concern. i am executing the code when wm_queryendsession returns 0 (i.e. logoff or shutdown is aborted) if i try to run the code (starting an application for file write operation) in the messagehandler itself, i cannot execute the application because windows is shutting down. i also tried to send a message(wm_lbuttonup) in the loop, but still i can't make it work

        O 1 Reply Last reply
        0
        • R r i s h a b h s

          thanx for ur concern. i am executing the code when wm_queryendsession returns 0 (i.e. logoff or shutdown is aborted) if i try to run the code (starting an application for file write operation) in the messagehandler itself, i cannot execute the application because windows is shutting down. i also tried to send a message(wm_lbuttonup) in the loop, but still i can't make it work

          O Offline
          O Offline
          Oliver Anhuth
          wrote on last edited by
          #4

          The problem is that the message loop does not get called when a message is sent to your handler. If you cannot perform your task in the message handler you have to make sure that the message loop is triggered without any user interaction. Maybe you coud post a message to your window, e.g. PostMessage(hYourWindow, WM_NULL, NULL, NULL); This will trigger the message loop some time after your handler has finished. regards Oliver

          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