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. Trying to Display HWND as String

Trying to Display HWND as String

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutoriallearning
6 Posts 4 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
    redfish34
    wrote on last edited by
    #1

    I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?

    S J A R 5 Replies Last reply
    0
    • R redfish34

      I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?

      J Offline
      J Offline
      Justin Tay
      wrote on last edited by
      #2

      First thing you need to learn is that you do not cast things without knowing exactly what you are doing as you can shoot yourself in the foot, like what you have done here.

      m_foreHwnd1 = GetForegroundWindow();
      CString szMessage;
      szMessage.Format(_T("ForeHwnd1: 0x%08X\r\n"), m_foreHwnd1);
      OutputDebugString(szMessage);

      1 Reply Last reply
      0
      • R redfish34

        I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?

        S Offline
        S Offline
        see me
        wrote on last edited by
        #3

        Did you try Format function of CString else try this CString strHwnd; strHwnd.Format(_T("Handle is: %d\n"), m_foreHwnd1); OutputDebugString(strHwnd); "Dream bigger...Do bigger...Expect smaller" aji

        1 Reply Last reply
        0
        • R redfish34

          I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?

          A Offline
          A Offline
          Abhi Lahare
          wrote on last edited by
          #4

          GetForegroundWindow() API will return handle to active window with which user is interacting, so in debugging mode you constantly switch between your app and debug window. so its difficult to know window handle. Not sure what are you trying to do, but try this to display window handle in output window. CString str; str.Format("%x",m_foreHwnd1); OutputDebugString(str); Hope this helps

          1 Reply Last reply
          0
          • R redfish34

            I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?

            S Offline
            S Offline
            see me
            wrote on last edited by
            #5

            If u r able to solve ur problem with our answers then please tel it so that we get some confidence "Dream bigger...Do bigger...Expect smaller" aji

            1 Reply Last reply
            0
            • R redfish34

              I am a beginner. I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use MessageBox or OutputDebugString such as below... m_foreHwnd1 = GetForegroundWindow(); MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK); OutputDebugString("ForeHwnd1: "); OutputDebugString((LPCSTR)m_foreHwnd1); OutputDebugString("\n"); ... I get errors like the following: First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548. Can i display the HWND so i can see what the heck is going on in my code? What is the How To?

              R Offline
              R Offline
              redfish34
              wrote on last edited by
              #6

              I think i posted on the wrong forum. I now see that there is a forum that supports STL questions, which i think would help come up with a ANSI version of the solution you folks provided. Sorry. But thanks for the excellent response!

              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