Thread: Can't get wordwrap to work

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    Can't get wordwrap to work

    hey, i have a problem..which you can tell by the title, is that I can't get word wrap to work i'm using an MDI for my program and i'm pretty sure thats whats f*ing me over lol this is my current wordwrap code:
    Code:
    case ID_OPTIONS_WORDWRAP:
    {
         //HWND hChild = (HWND)SendMessage(g_hMDIClient, WM_MDIGETACTIVE, 0, 0);
         HWND hChild = GetWindow(g_hMDIClient, GW_CHILD);
    
         if (wordwrap == 0)
         {
             SetWindowLong(hChild, GWL_STYLE, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL);
    	 SetWindowPos(hChild, HWND_BOTTOM, 0, 0, 320, 240, SWP_NOMOVE | SWP_NOSIZE);
    	 wordwrap = 1;
         }
         else if (wordwrap == 1)
         {
         	SetWindowLong(hChild, GWL_STYLE, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL);
         	SetWindowPos(hChild, HWND_BOTTOM, 0, 0, 320, 240, SWP_NOMOVE | SWP_NOSIZE);
         	wordwrap = 0;
         }
    }
    break;
    i tried two ways of getting the current child window, they both produce the same results. am i using something wrong? i took some screenshots of what happens: Before | After
    i have wordwrap declared as an integer so that i can tell if its on or off. better way to do this? g_hMDIClient is assigned in WndProc as such:
    Code:
    g_hMDIClient = CreateWindowEx(WS_EX_CLIENTEDGE, "mdiclient", NULL,
                    WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, 
                    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, 
                    (HMENU)IDC_MAIN_MDI, GetModuleHandle(NULL), (LPVOID)&ccs);
    thanks in advance
    Last edited by willc0de4food; 06-27-2005 at 03:58 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    After it is created, an edit control can not turn on or off word wrap. What Notepad and other applications do is save the current text, destroy the current control, create the new control with correct styles, restore saved text. Here is some old code I found from a text editor:
    Code:
    	case M_EDIT_WORD:
    
    		/* There are two ways of doing this. One is to define a wordBreakProc
    		and use that. The other is to just recreate the window (with or without)
    		the AUTOHSCROLL and HSCROLL styles depending on whether one wants word
    		wrap or not. This is the method that notepad uses so I'll use it here.
    		It's a bit silly that one has to recreate the window to set/disable
    		wordwrap but that's Windows for you. */
    
    		//lock window so we don't see flicker.
    		LockWindowUpdate(hDlg);
    
    		//get size of parent window so we can
    		//use it to size new edit control.
    		GetClientRect(hDlg,&dlgRect);
    
    		//save text into temporary buffer
    		tSize = GetWindowTextLength(hEdit) + 1;
    		text = malloc(tSize + 1);
    		GetWindowText( hEdit, text, tSize );
    
    		//hide and destroy old edit window
    		ShowWindow(hEdit,SW_HIDE);
    		DestroyWindow(hEdit);
    
    		//create new edit window
    		hEdit = CreateWindow("EDIT","",
    		ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN |
    	    WS_VSCROLL | ES_NOHIDESEL | WS_VISIBLE | WS_CHILD |
    		//if menu is checked use ES_AUTO and WS_HSCROLL (turn wordwrap off)
    		//other wise leave these styles out (turn wordwrap on)
    		( GetMenuState( GetMenu(hDlg),M_EDIT_WORD,MF_CHECKED ) ? ES_AUTOHSCROLL | WS_HSCROLL : 0 ),
    		0,toolBottom + 5,dlgRect.right - dlgRect.left,dlgRect.bottom - dlgRect.top - toolBottom - 5,
    		hDlg,NULL,hInst,NULL);
    
    		//set max limit for edit control. Zero means default largest.
    		//ie. small in Win95 and large in NT.
    		SendMessage(hEdit,EM_SETLIMITTEXT,0,0);
    
    		//show new window
    		ShowWindow(hEdit,SW_SHOW);
    
    		//sets the font of edit control
    		SendMessage(hEdit, WM_SETFONT, (WPARAM) editFont, 0);
    
    		//copy text from temp buffer into new edit control
    		SetWindowText(hEdit,text);
    
    		//free temp buffer
    		free(text);
    
    		//sets focus on new edit control
    		SetFocus(hEdit);
    
    		//unlock window update
    		LockWindowUpdate(NULL);
    
    		//checks menu if not or vice versa
    		CheckMenuItem( GetMenu(hDlg),M_EDIT_WORD,GetMenuState( GetMenu(hDlg),M_EDIT_WORD,MF_CHECKED ) ^ MF_CHECKED);
    
    		break;

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    do you have the rest of the code? if so, could you email it to me? my email is my name @ yahoo
    Registered Linux User #380033. Be counted: http://counter.li.org

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I'll temporarilty attach it here. Let me know when you have downloaded it so that I can delete it. Rename the file from npsub.txt to npsub..zip, as the board doesn't allow .zip files to be uploaded.

    Disclaimer: This was one of my early C projects. Although the end result works quite well, the style is poor, some of the comments are wrong, error checking is limited and there are several obvious bugs. There are a couple of other C notepad clones here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM