Results 1 to 5 of 5

Thread: How to make a textbox?

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Exclamation How to make a textbox?

    I cannot create a multiline textbox on a parent window. I used the following code but it does not show any edit box on my window:

    Code:
    #include <windows.h>
    #include "resource.h"
    #define classname "myclass"
    HWND winhwnd;
    HWND EditBoxHwnd;
    HINSTANCE hinst;
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    {
    	switch(msg)
    	{
    	case WM_CREATE:
    	EditBoxHwnd = CreateWindow("EDIT", 
    				"df",
                                                 WS_CHILD | WS_VISIBLE
                                           |  ES_MULTILINE | ES_WANTRETURN |
                                                 WS_VSCROLL,
    		        CW_USEDEFAULT,
    		        CW_USEDEFAULT,
    		        CW_USEDEFAULT,
    		        CW_USEDEFAULT,
    			               hwnd,
    				NULL,
    				hinst,
    				NULL);
    		return 0;
    	case WM_DESTROY:
    	     PostQuitMessage(0);
    	   return 0;
    	}
    	return DefWindowProc(hwnd, msg, wparam, lparam);
    }
    
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	HMENU hmenu;
    	WNDCLASSEX wc;
    	MSG message;
    	// Fills in the class structure
    	wc.cbClsExtra = 0;
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.cbWndExtra = 0;
    	wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hInstance = hinst;
    	wc.lpfnWndProc = WndProc;
    	wc.lpszClassName = classname;
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpszMenuName = NULL;
    
    	//Registers the Class
    
    	if(!RegisterClassEx(&wc))
    		{
    		MessageBox(NULL, "Class failure","CLASS", MB_OK);
    		return 0;
    	}
    	//Create thw hwnd of our main window
    
    	winhwnd = CreateWindow( 
    		classname, 
    		"Welcome to my Dialog Program",
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		NULL,
    		NULL,
    		hinstance,
    		NULL);
    	
    	
    	if(winhwnd == NULL)
    	{
    		MessageBox(NULL, "Hwnd failure","HWND", MB_OK);
    		return 0;
    	}
    	ShowWindow(winhwnd, nShowCmd);
    	UpdateWindow(winhwnd);
    
    	//Messes up with the messages
    
    	while(GetMessage(&message, NULL,0,0))
    		{
    		TranslateMessage(&message);
    		DispatchMessage(&message);
    		}
    
    	return message.wParam;
    }

    Do you know why it does not show the edit box on my window?
    Last edited by abdul; Jul 3rd, 2001 at 08:42 AM.
    Baaaaaaaaah

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Change all the:
    CW_USEDEFAULT,
    to real values like 10,10,100,100
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I still does not show the edit box.
    Baaaaaaaaah

  4. #4
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Thats really strange your code works perfectly for me.

    Try adding

    ShowWindow(EditBoxHwnd,SW_NORMAL);
    UpdateWindow(winhwnd);

    after your CreateWindow and before return 0;
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  5. #5

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Never Mind!

    It works now. I just change the "Hinstance" to default hinstance and it works now.

    And also, I think that you suggestion(getting rid of CS_USEDEFAULT) was also right.
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width