• Welcome to Valhalla Legends Archive.
 

VK_RETURN

Started by CoorsLight, June 26, 2004, 04:16 PM

Previous topic - Next topic

CoorsLight

I have an extent of knowledge of C++, but I've recently just started to dabble with Win32 apps. I'm trying to figure out how to catch the VK_RETURN message in my main dialog process callback function. This is how I have it setup..


BOOL CALLBACK MainDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch(uMsg){
   case WM_INITDIALOG:
      hRichEdit = GetDlgItem(hDlg, IDC_CHATWIN);
      hInput = GetDlgItem(hDlg, IDC_SENDBOX);
      hSendBut = GetDlgItem(hDlg, IDC_SENDBUT);
      SendMessage(hRichEdit, EM_SETBKGNDCOLOR, FALSE, CL_BLACK);
      return TRUE;

   case WM_CLOSE:
      EndDialog(hDlg, 0);
      return TRUE;

   case WM_COMMAND:
      switch(wParam)
      {
         case IDC_SENDBUT:
            if(HIWORD(wParam) == BN_CLICKED)
            {
               char cBuffer[BUFFER_SIZE] = { 0 };
               SetFocus(hInput);
               if(GetWindowText(hInput, cBuffer, sizeof(cBuffer) - 1) == 0) return(0);
               strcat(cBuffer, "\r\n");
               PrintMessage(IDC_CHATWIN, 0x00FFFFFF, "%s", cBuffer);
               SetWindowText(hInput, "");
            }
            break;
       case IDC_SENDBOX:
           break;
      }
      return TRUE;
   }
   return FALSE;
}


As you can see, I'm using a button ('case IDC_SENDBUT:') to place the text in my richtext box. I've debugged it quite a bit, and can't seem to get it to do anything when I hit return. Anyone know how to do this?

Edit: I did a dirty debug-style routine by printing the wParam values every time WM_COMMAND is fired. When I hit enter in my edit box, the value is "1", I'm not sure, but I saw no relationship between VK_RETURN and 1 anywhere. I'm also passing the KEYUP, and KEYDOWN messages.

I guess I'm no longer asking how to do what I need to originally do since I got that party dirtily working, but where can you find the message titles (VK_RETURN) and their corresponding wParam values?


BOOL CALLBACK MainDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch(uMsg){
   case WM_INITDIALOG:
      hRichEdit = GetDlgItem(hDlg, IDC_CHATWIN);
      hInput = GetDlgItem(hDlg, IDC_SENDBOX);
      hSendBut = GetDlgItem(hDlg, IDC_SENDBUT);
      SendMessage(hRichEdit, EM_SETBKGNDCOLOR, FALSE, CL_BLACK);
      return TRUE;

   case WM_CLOSE:
      //End the dialog
      EndDialog(hDlg, 0);
      return TRUE;

   case WM_COMMAND:
      switch(wParam)
      {
         case IDC_SENDBUT:
            if(HIWORD(wParam) == BN_CLICKED)
            {
               char cBuffer[BUFFER_SIZE] = { 0 };
               SetFocus(hInput);
               if(GetWindowText(hInput, cBuffer, sizeof(cBuffer) - 1) == 0) return(0);
               strcat(cBuffer, "\r\n");
               PrintMessage(IDC_CHATWIN, 0x00FFFFFF, "%s", cBuffer);
               SetWindowText(hInput, "");
            }
            break;
         case 1:
            char cBuffer[BUFFER_SIZE] = { 0 };
            SetFocus(hInput);
            if(GetWindowText(hInput, cBuffer, sizeof(cBuffer) - 1) == 0) return(0);
            strcat(cBuffer, "\r\n");
            PrintMessage(IDC_CHATWIN, 0x00FFFFFF, "%s", cBuffer);
            SetWindowText(hInput, "");
            break;
      }
      //PrintMessage(IDC_CHATWIN, CL_GREEN, "WM_COMMAND: wParam(%u)\r\n", wParam);
      return TRUE;
   }
   return FALSE;
}


That's my current setup. I didn't remove the old so people could compare.

Moonshine

#1
CoorsLight, I'm assuming you want it so your application's input edit-control will send text to the richedit when the user hits enter.  In this case, what you're going to need is something called subclassing.  Subclassing is a way for controls to get their own individual Procedure, which allows you to control/manipulate them with greater flexibility.



WNDPROC hOldProc = (WNDPROC)SetWindowLong(hInput, GWL_WNDPROC, (DWORD)MyInputProc); // Subclass edit control to have its own proc

// ... then in your edit box's proc:

LRESULT CALLBACK MyInputProc(HWND hDialog, UINT wMessage, WPARAM wParam, LPARAM lParam) {
  switch (wMessage) {
     case WM_CHAR: { // User hit a key inside of edit control
        if ((int)wParam == '\r') {
           // The user hit enter inside of the input, display chat text
           return (FALSE);
        }
     } break;

     default : break;
  }

  return (CallWindowProc(hOldProc, hDialog, wMessage, wParam, lParam)); // Dispatch msg to the old proc
}




Hope this helps.

UserLoser.

I'm no expert on this, but under WM_CLOSE, shouldn't you be doing DestroyWindow(hDlg); and under WM_DESTROY, return TRUE?

Moonshine

#3
Quote from: UserLoser. on June 26, 2004, 05:34 PM
I'm no expert on this, but under WM_CLOSE, shouldn't you be doing DestroyWindow(hDlg); and under WM_DESTROY, return TRUE?

I believe he's using a Dialog based app instead of a Window based app (implied by returning FALSE from his main win proc instead of DefWindowProc())

If that's the case, you need to use EndDialog() instead of DestroyWindow() and I'm pretty sure you can ignore WM_DESTROY and just handle WM_CLOSE (In the case of dialog-based apps).

Skywing

I think you need to use DestroyWindow if the dialog is modeless.