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. HWND / CWnd* - compile errors

HWND / CWnd* - compile errors

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

    Just for learning purposes, I'm trying to implement the code Mark Petrik Sosa put in a message at 6:47 14 Apr '05 in a reply to 'Send Messages to Other Windows' (4:34 14 Apr '05). HWND hNotepad = FindWindowEx(0, 0, "Notepad", 0); if(hNotepad) SendMessage(hNotepad, WM_SETTEXT, 0, (LPARAM) "Hah, I found you!"); else MessageBox(0, "Couldn't find notepad.", "Darn", MB_OK); When I compile, I get: error C2440: 'initializing' : cannot convert from 'CWnd*' to 'HWND' error C2660: 'CWnd::SendMessageA': function does not take 4 arguments If I change to CWnd* hNotepad = ... and then SendMessage(hNotePad->m_hWnd, ... I still get the C2660 error. I also get 'CWnd::MessageBoxA': function does not take 4 arguments I can see that SendMessage has 2 prototypes - one takes 3 arguments and looks like it's for the cases where you do not need to specify a handle. Would appreciate any direction on how to fix the code and/or explanations to help me understand the mechanisms involved here.

    D 1 Reply Last reply
    0
    • T theFrenchHornet

      Just for learning purposes, I'm trying to implement the code Mark Petrik Sosa put in a message at 6:47 14 Apr '05 in a reply to 'Send Messages to Other Windows' (4:34 14 Apr '05). HWND hNotepad = FindWindowEx(0, 0, "Notepad", 0); if(hNotepad) SendMessage(hNotepad, WM_SETTEXT, 0, (LPARAM) "Hah, I found you!"); else MessageBox(0, "Couldn't find notepad.", "Darn", MB_OK); When I compile, I get: error C2440: 'initializing' : cannot convert from 'CWnd*' to 'HWND' error C2660: 'CWnd::SendMessageA': function does not take 4 arguments If I change to CWnd* hNotepad = ... and then SendMessage(hNotePad->m_hWnd, ... I still get the C2660 error. I also get 'CWnd::MessageBoxA': function does not take 4 arguments I can see that SendMessage has 2 prototypes - one takes 3 arguments and looks like it's for the cases where you do not need to specify a handle. Would appreciate any direction on how to fix the code and/or explanations to help me understand the mechanisms involved here.

      D Offline
      D Offline
      dkarpezo_2
      wrote on last edited by
      #2

      ::SendMessage(hNotepad, WM_SETTEXT, 0, (LPARAM) "Hah, I found you!"); and ::MessageBox(0, "Couldn't find notepad.", "Darn", MB_OK); or MessageBox("Couldn't find notepad.", "Darn", MB_OK);

      T 1 Reply Last reply
      0
      • D dkarpezo_2

        ::SendMessage(hNotepad, WM_SETTEXT, 0, (LPARAM) "Hah, I found you!"); and ::MessageBox(0, "Couldn't find notepad.", "Darn", MB_OK); or MessageBox("Couldn't find notepad.", "Darn", MB_OK);

        T Offline
        T Offline
        theFrenchHornet
        wrote on last edited by
        #3

        Thanks. It now compiles and executes properly. If you have another minute though, I still get the error 'initializing': cannot convert from CWnd* to HWND unless I declare hNotepad as CWnd*. Then when I do that I have to use hNotepad->m_hWnd, which makes sense. Is there some include file I need such that I can declare hNotepad as HWND and then use it as you and Mark used it (i.e., without the ->m_hWnd)?

        C 1 Reply Last reply
        0
        • T theFrenchHornet

          Thanks. It now compiles and executes properly. If you have another minute though, I still get the error 'initializing': cannot convert from CWnd* to HWND unless I declare hNotepad as CWnd*. Then when I do that I have to use hNotepad->m_hWnd, which makes sense. Is there some include file I need such that I can declare hNotepad as HWND and then use it as you and Mark used it (i.e., without the ->m_hWnd)?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          If you dereference your pointer ( *hNotepad ), then operator HWND should come to the rescue. Christian Graus - Microsoft MVP - C++

          T 1 Reply Last reply
          0
          • C Christian Graus

            If you dereference your pointer ( *hNotepad ), then operator HWND should come to the rescue. Christian Graus - Microsoft MVP - C++

            T Offline
            T Offline
            theFrenchHornet
            wrote on last edited by
            #5

            I haven't found the secret yet. If I still declare with CWnd CWnd* hNotepad = FindWindowEx(... then I can use ::SendMessage(*hNotePad, ... But if I declare with HWND hNotepad = FindWindowEx(... or HWND *hNotepad = FindWindowEx(... I still get the error message 'initializing' cannot convert from CWnd to HWND Is it maybe because the 2003 compiler is more strict than compilers in the past? I don't have much experience/history with Visual C++.

            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