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

EnumWindows

Scheduled Pinned Locked Moved C / C++ / MFC
comjsontutorial
5 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.
  • D Offline
    D Offline
    dsubrama
    wrote on last edited by
    #1

    Hi all, I am relatively new to api programming.I am trying to automate a process and am using EnumWindows to get all window handles. I am then using GetWindowText and strcmp to check which of the window handles corresponds to the relevent window. However it doesnt seem to work i.e., it doesnt simulate the push of the button.... I have pasted the code snippet below.. Any suggestions on how to resolve this will be terrific. In the main program i have EnumWindows((WNDENUMPROC) WinCallback, 0); My function is: BOOL CALLBACK WinCallback(HWND win, LPARAM nadda) { char temp[512]; GetWindowText(win, temp, 512); printf("%s",temp); if(!strcmp(temp,"RBNal_Optocomm")) { HWND hcomm = FindWindowEx((HWND) win,NULL,"BUTTON","COM 1"); LRESULT lResult2; lResult2 = SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0); return FALSE; } } Please let me know of any suggestions. D

    J 1 Reply Last reply
    0
    • D dsubrama

      Hi all, I am relatively new to api programming.I am trying to automate a process and am using EnumWindows to get all window handles. I am then using GetWindowText and strcmp to check which of the window handles corresponds to the relevent window. However it doesnt seem to work i.e., it doesnt simulate the push of the button.... I have pasted the code snippet below.. Any suggestions on how to resolve this will be terrific. In the main program i have EnumWindows((WNDENUMPROC) WinCallback, 0); My function is: BOOL CALLBACK WinCallback(HWND win, LPARAM nadda) { char temp[512]; GetWindowText(win, temp, 512); printf("%s",temp); if(!strcmp(temp,"RBNal_Optocomm")) { HWND hcomm = FindWindowEx((HWND) win,NULL,"BUTTON","COM 1"); LRESULT lResult2; lResult2 = SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0); return FALSE; } } Please let me know of any suggestions. D

      J Offline
      J Offline
      Jose Cezar S Ynion
      wrote on last edited by
      #2

      BM_CLICK message will fail if the window that will recieve the is not active. Try the code below. if(!strcmp(temp,"RBNal_Optocomm")) { HWND hcomm = ::FindWindowEx((HWND) win,NULL,"BUTTON","COM 1"); if (hcomm) { ::SetActiveWindow(hcomm); LRESULT lResult2; lResult2 = ::SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0); return FALSE; } }

      D 1 Reply Last reply
      0
      • J Jose Cezar S Ynion

        BM_CLICK message will fail if the window that will recieve the is not active. Try the code below. if(!strcmp(temp,"RBNal_Optocomm")) { HWND hcomm = ::FindWindowEx((HWND) win,NULL,"BUTTON","COM 1"); if (hcomm) { ::SetActiveWindow(hcomm); LRESULT lResult2; lResult2 = ::SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0); return FALSE; } }

        D Offline
        D Offline
        dsubrama
        wrote on last edited by
        #3

        Thanks.. It still isnt working though.. I have passed an LPARAM value of 0 into the function.. Would this matter?? D

        J 1 Reply Last reply
        0
        • D dsubrama

          Thanks.. It still isnt working though.. I have passed an LPARAM value of 0 into the function.. Would this matter?? D

          J Offline
          J Offline
          Jose Cezar S Ynion
          wrote on last edited by
          #4

          Hi, try calling SetActiveWindow(win) before the line SetActiveWindow(hcoom). It should look like this if (hcomm) { ::SetActiveWindow(win); ::SetActiveWindow(hcomm); LRESULT lResult2; lResult2 = ::SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0); return FALSE; } I had tested this and i had sent a sample applications (sender and receiver) in your email.

          D 1 Reply Last reply
          0
          • J Jose Cezar S Ynion

            Hi, try calling SetActiveWindow(win) before the line SetActiveWindow(hcoom). It should look like this if (hcomm) { ::SetActiveWindow(win); ::SetActiveWindow(hcomm); LRESULT lResult2; lResult2 = ::SendMessage((HWND) hcomm,(UINT) BM_CLICK,0,0); return FALSE; } I had tested this and i had sent a sample applications (sender and receiver) in your email.

            D Offline
            D Offline
            dsubrama
            wrote on last edited by
            #5

            Hi Thanks.. it worked.... Deepak

            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