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. SetWindowSubclass is killing my app!

SetWindowSubclass is killing my app!

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
4 Posts 3 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.
  • K Offline
    K Offline
    KellyR
    wrote on last edited by
    #1

    Hi, This app is in C++ without MFC, and I'm using SetWindowSubclass to subclass two of my windows controls so that I can manually catch the messages that are sent to their message pumps and process them accordingly. The app is dialog-based and uses a GetMessage loop, so it does not usually take much CPU power... however, the problem is this: when I call SetWindowSubclass to subclass either of the controls, suddenly my CPU usage jumps to 99% on the task manager. Does SetWindowSubclass branch a new thread for each control that will just run on its own regardless of my GetMessage loop? If so, how do I stop it from doing that? If not, what the heck is it doing and how can I use SetWindowSubclass without using 99% of my darned CPU? Thanks!

    KR

    N 1 Reply Last reply
    0
    • K KellyR

      Hi, This app is in C++ without MFC, and I'm using SetWindowSubclass to subclass two of my windows controls so that I can manually catch the messages that are sent to their message pumps and process them accordingly. The app is dialog-based and uses a GetMessage loop, so it does not usually take much CPU power... however, the problem is this: when I call SetWindowSubclass to subclass either of the controls, suddenly my CPU usage jumps to 99% on the task manager. Does SetWindowSubclass branch a new thread for each control that will just run on its own regardless of my GetMessage loop? If so, how do I stop it from doing that? If not, what the heck is it doing and how can I use SetWindowSubclass without using 99% of my darned CPU? Thanks!

      KR

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      KellyR wrote:

      Does SetWindowSubclass branch a new thread for each control that will just run on its own regardless of my GetMessage loop?

      No it wont start any new thread. If possible show the code that calls the SetWindowSubclass() fucntion and also the claabck function that you passed to SetWindowSubclass.

      nave [OpenedFileFinder] [My Blog]

      K 1 Reply Last reply
      0
      • N Naveen

        KellyR wrote:

        Does SetWindowSubclass branch a new thread for each control that will just run on its own regardless of my GetMessage loop?

        No it wont start any new thread. If possible show the code that calls the SetWindowSubclass() fucntion and also the claabck function that you passed to SetWindowSubclass.

        nave [OpenedFileFinder] [My Blog]

        K Offline
        K Offline
        KellyR
        wrote on last edited by
        #3

        I see what happened, I was returning in my WM_PAINT messages which was causing the huge CPU usage. I guess the DefSubclassProc must do something with WM_PAINT that causes the message not to be sent again; maybe by returning and not setting this parameter, the WM_PAINT was getting sent continuously. Thanks for help!

        KR

        M 1 Reply Last reply
        0
        • K KellyR

          I see what happened, I was returning in my WM_PAINT messages which was causing the huge CPU usage. I guess the DefSubclassProc must do something with WM_PAINT that causes the message not to be sent again; maybe by returning and not setting this parameter, the WM_PAINT was getting sent continuously. Thanks for help!

          KR

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          KellyR wrote:

          ...maybe by returning and not setting...

          "Maybe"? When working with window messages, you will have much better results if you are sure about how to handle the messages, including proper return values. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          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