Skip to main content
gamedev.net
🔒 Locked

Read-only edit box problem

Started by GuitarPlayer0912 Sep 24, 2006 at 10:29 AM 11 replies 800+ views
Original Post
GuitarPlayer0912
GuitarPlayer0912
I'm sure this question has been asked many times, but I can't find the exact answer I want anywhere. So... I'm making a read-only edit box in my program (for a log of what goes on in the program). Anyway, I want to be able to add text to the box when an event occurs. However, this does not mean that I want to be able to click on the box and type text into it. I simply want the program to add text to the box when an event takes place via SendMessage(); Here's what I try to do...

void createWindows(){

  // creating window code

  char test[] = "HI";

  SendMessage(m_hLogWnd, WM_SETTEXT, 0, (LPARAM)test);

}

this should add text to the edit box, correct? It doesn't work for me. Please tell me how to add text. Thanks.
ApochPiQ
ApochPiQ
That's the correct syntax; I personally prefer to use the SetWindowText function as it is a little bit more clear, but they both do exactly the same thing (SetWindowText sends a WM_SETTEXT message).

The only thing that looks potentially problematic is the HWND you're sending the message to - are you sure that's the valid HWND of the edit control? Also, can you post the code you're using to create the control itself?
GuitarPlayer0912
GuitarPlayer0912
Sure, this is how I create my edit control. I treat it as just creating another window.

void createWindows(){  m_hLogWnd = CreateWindowEx(    WS_EX_CLIENTEDGE,                 // For a 3D look    "EDIT",                           // An edit control    NULL,                             // No window title    WS_CHILD | WS_VISIBLE |     WS_HSCROLL | WS_VSCROLL |     ES_AUTOHSCROLL | ES_AUTOVSCROLL | // The style of the window    ES_LEFT | ES_MULTILINE |    ES_READONLY,     196,                              // X position    rcWnd.bottom - 128,               // Y position    rcWnd.right - 196,                // Width    128,                              // Height    m_hWnd,                           // Parent window is main window    NULL,                             // No menu    m_hInst,                          // Instance handle    NULL,                             // Not an MDI child window, unnecessary    );  // Then I try to add text  char test[] = "HI";  SendMessage(m_hLogWnd, WM_SETTEXT, 0, (LPARAM)test);}


Edit: Very interesting problem. The code to set the text works when it is right there, but when I put it in my message handler (a.k.a. LogProc), it doesn't work. LogProc is just a WndProc for my log window.
ApochPiQ
ApochPiQ
Please post the actual code you are using - as much of it as possible. The problem is someplace outside the scope of what you've shown so far.
Brocketino
Brocketino
Are u updating your window correctly. Perhaps u need to send a update message to the editbox window?
GuitarPlayer0912
GuitarPlayer0912
Ok, well here's the actual code. The only difference is that it is part of my cEditor class. I didn't use that in the examples for simplicity purposes.

void cEditor::fnCreateChildWindows(){  // Declare a RECT structure for retrieving window dimensions  RECT rcWnd;  // Get the dimensions of the main window  GetClientRect(m_hWnd, &rcWnd);  // Create the Log window  m_hLogWnd = CreateWindowEx(    WS_EX_CLIENTEDGE,             // For a 3D look    "EDIT",                       // Class name    NULL,                         // Name shown on title bar    WS_CHILD | WS_VISIBLE |       // Window is a visible child window. If child    WS_CLIPSIBLINGS | ES_LEFT |   // windows overlap, drawing is prevented.    ES_MULTILINE | ES_READONLY |  // Window is multilined, read-only, and left-aligned.    WS_VSCROLL | ES_AUTOVSCROLL | // Window also automattically scrolls vertically    WS_HSCROLL | ES_AUTOHSCROLL,  // and horizontally.    196,                          // X position (in pixels) relative to main window    rcWnd.bottom - 128,           // Y position relative to main window    rcWnd.right - 196,            // Width    128,                          // Height    m_hWnd,                       // Parent window is main window    NULL,                         // No menu    m_hInst,                      // Main instance handle    NULL                          // Not an MDI window, unneccesary    );  // If Log window could not be created, inform user  if(!m_hLogWnd)    MessageBox(m_hWnd, "Could not create Log window", "Error", MB_OK);  // fnLog() now works the same as SendMessage(), but without the extra parameters, it's kind of a wrapper function   fnLog("Log window created");}void cEditor::fnLog(char szLogText[128]){  SendMessage(m_hLogWnd, WM_SETTEXT, 0, (LPARAM)szLogText);}// My Log window message handler (basically the same thing as WndProc)LRESULT CALLBACK cEditor::prLogHandler(HWND hLogWnd, UINT msg, WPARAM wParam,  LPARAM lParam){  switch(msg){        // Called when the Log window is created    case WM_CREATE:            {        // This doesn't work        fnLog("HI");             }      return 0;    // Called when Log window needs to be closed    case WM_CLOSE:      // Destroy the Log window      DestroyWindow(hLogWnd);      // WM_CLOSE message handled, return 0      return 0;    default:      return DefWindowProc(hLogWnd, msg, wParam, lParam);  }}
Brocketino
Brocketino
Im not sure but i think your problem lies inside the processing of the WM_CREATE message, perhaps you are trying to populate the editbox with text before it actually has been created? Try to change send the WM_SETTEXT message on a message like WM_LBUTTONDOWN or similar...
Brocketino
Brocketino
Quote:
Original post by GuitarPlayer0912
Hmm, tried it. Still nothing. It was a good idea, though.


Post the code for creating the parent window + the actual message loop.
Brocketino
Brocketino
Do you set a new message handler for your editbox?
HWND hwndEdit = CreateWindowEx(...);
SetWindowLong(hwndEdit,GWL_WNDPROC,YourEditProc);
GuitarPlayer0912
GuitarPlayer0912
Here's the code for creating the main window

BOOL cEditor::Init(){  // Register class stuff  // Create the main window  m_hWnd = CreateWindowEx(    WS_EX_CLIENTEDGE,                       // For a 3D look    m_szAppName,                            // Class name    m_szAppName,                            // Name shown on title bar    WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | // Window is resizable, moveable, clips out childrens'      WS_TABSTOP,                           // drawing, and enables tab usage in dialog boxes    CW_USEDEFAULT,                          // Put window in default X position determined by windows    CW_USEDEFAULT,                          // Put window in default Y position determined by windows    sWndWidth,                              // Window width    sWndHeight,                             // Window height    NULL,                                   // No parent window    NULL,                                   // No menu name    hInstance,                              // Main instance handle    NULL                                    // Not an MDI window, unnecessary    );  if(!m_hWnd){    MessageBox(m_hWnd, "Could not create main window", "Error", MB_OK);    return FALSE;  }  // Show window stuff  return TRUE;}


And that was the actual message loop. I re-routed it from this

// Here's a window procedure I createdLRESULT CALLBACK LogProc(HWND, UINT, WPARAM, LPARAM);


And trust me, this works. It gets routed to the message handler I already posted
LRESULT CALLBACK LogProc(HWND hLogWnd, UINT msg, WPARAM wParam, LPARAM lParam){  return cEditor::prLogHandler(hLogWnd, msg, wParam, lParam);}
Brocketino
Brocketino
You could also respond to the WM_COMMAND message in the parent windows message handler. note --> Changed my previous post...
GuitarPlayer0912
GuitarPlayer0912
Yeah, don't worry about it. Seeing as how I won't need to log anything from inside the message handler, it's not a big deal. I'll probably work it out eventually anyway. Thanks for your help Brocketino and ApochPiQ.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.