Menu

Little help with SendMesage please?

2003-01-08
2012-09-26
  • Nobody/Anonymous

    Hello everybody, im starting on C and i need some help :)

    Ive created a function receives the HWND of a Edit Control and some text as arguments.

    The thing is simple: It should send the Text to the HWND using SendMessage and WM_SETTEXT.
    The name of the HWND is stored in char hwndname[20];
    The text is stored in char thetext[50];

    I try to
    SendMessage(hwndname, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));

    and i get
    C:\FirstProject\sendtexttohwnd.c
    [Warning] passing arg 1 of `SendMessageA' from incompatible pointer type

    /John00 F.

     
    • Nobody/Anonymous

      A HWND is a HWND, WTF are you trying to do?

       
    • upcase

      upcase - 2003-01-08

      Just declare
      HWND hwnd;
      and then try
      SendMessage(hwnd, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
      Should work this way. HWND is a type, it's not a char or pointer to char or array of chars...

       
    • Nobody/Anonymous

      I know...i have all my H=hwnds declared as HWNDS, all my hinstances declared as HINSTANCES, i must have explained the problem very wrongly.

      int somefunction(char *NameOfTheHWNDiWantToSendTheMessageTo) {
      SendMessage(NameOfTheHWNDiWantToSendTheMessageTo, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
      return 0;
      }

      Is this possible? Thena what is the right way to do it? You can see the erros im having at my first msg.

       
    • Nobody/Anonymous

      Oh i got it, what you meant is thhat i have to set the arg to the functions as a HWND too, is that it?

       
    • upcase

      upcase - 2003-01-08

      Guess you got it now ;-)
      int somefunction(char * <-- what's a char* doing there if you want to pass the function a HWND? Nothing! ;-)
      Pass it the HWND and try again:
      int somefunction(HWND NameOfTheHWNDiWantToSendTheMessageTo) {....}
      Good luck! And a little tip: If you get a message saying something like "[Warning] passing arg 1 of `blabla' from incompatible blablabla type" it's best to check the API again and look at the functions prototype because most of the times you used the function wrong. And remember: Allways pass what you need the right way! ;-)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.