Author | Message | Time |
---|---|---|
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.. [code] 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; } [/code] 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? [code] 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; } [/code] That's my current setup. I didn't remove the old so people could compare. | June 26, 2004, 9:16 PM |
Moonshine | 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. [code] 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 } [/code] Hope this helps. | June 26, 2004, 10:11 PM |
UserLoser. | I'm no expert on this, but under WM_CLOSE, shouldn't you be doing DestroyWindow(hDlg); and under WM_DESTROY, return TRUE? | June 26, 2004, 10:34 PM |
Moonshine | [quote author=UserLoser. link=board=30;threadid=7457;start=0#msg67326 date=1088289271] I'm no expert on this, but under WM_CLOSE, shouldn't you be doing DestroyWindow(hDlg); and under WM_DESTROY, return TRUE? [/quote] 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). | June 27, 2004, 1:29 AM |
Skywing | I think you need to use DestroyWindow if the dialog is modeless. | June 27, 2004, 2:29 AM |