problem with edit-window

This is a discussion on problem with edit-window within the Windows Programming forums, part of the Platform Specific Boards category; hi i'm just reading petzold and learning to programm the winapi. i'm doing this, by writing an ide (or gui ...

  1. #1
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90

    problem with edit-window

    hi

    i'm just reading petzold and learning to programm the winapi. i'm doing this, by writing an ide (or gui if you want like that) for a command line tool i once wrote. i am setting up a control pannel with several buttons and one editwin, in which later the output of the command-line tool will be shown and can be edited.
    to my problem: i read, that edit-windows do send messages of the type WM_COMMAND to the main window of the application. LOWORD(wParam) contains the ID and HIWORD(wParam) contains the action-code, lParam the handle of the child. But I don't receive messages like this in the main loop, which makes the check if the file needs to be safed sensless. why?

    Code:
    switch(message) {
    case WM_CREATE:
    	//define buttons
    	...
    	//Make Editwin
    	hwndEditWin=CreateWindow(TEXT("edit"),NULL,
    		WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
    		0,0,0,0,hwnd, (HMENU) ID_EDITWIN, ((LPCREATESTRUCT) lParam)->hInstance,NULL);
    		OldEditWin=(WNDPROC)SetWindowLong(hwndEditWin,GWL_WNDPROC,(LONG) EditWinProc);
    ...
    
    case WM_COMMAND:
    	//Reactions to the panel
    	if(lParam) {
    		switch(LOWORD(wParam)) {
    		case ID_START:
    				
    			if( (int)SendMessage(hwndPanel[ID_OUTPUTDETMIN],BM_GETCHECK,0,0L) )
    				strcat(szExternalProg,"-o- ");
    			else if( (int)SendMessage(hwndPanel[ID_OUTPUTDETMED],BM_GETCHECK,0,0L) )
    				strcat(szExternalProg,"-o ");
    			else if( (int)SendMessage(hwndPanel[ID_OUTPUTDETMAX],BM_GETCHECK,0,0L) )
    				strcat(szExternalProg,"-o+ ");
    			else
    				MessageBox(hwnd,TEXT("Fehler. Ausführlichkeit d. Ausgabe nicht bestimmt."),szAppName,MB_OK | MB_ICONSTOP);		
    				if( (int)SendMessage(hwndPanel[ID_OUTPUTFORMCSV],BM_GETCHECK,0,0L) )
    				strcat(szExternalProg,"-f csv ");
    			else if( (int)SendMessage(hwndPanel[ID_OUTPUTFORMHTML],BM_GETCHECK,0,0L) )
    				strcat(szExternalProg,"-f html ");
    			else
    				MessageBox(hwnd,TEXT("Fehler. Ausgabeformat nicht bestimmt."),szAppName,MB_OK | MB_ICONSTOP);
    
    			system(szExternalProg);
    				// Nachricht, dass die ausgabe des EditWin noch nicht implementiert ist direkt ins editwin schreiben
    			SetWindowText(hwndEditWin,TEXT("Die Ausgabe der Zusammenfassung befindet sich in smt_out.csv, resp .html, da das EditWindow noch nicht voll funktionsfähig ist."));
    				//Für erneutes drücken von start vorbereiten
    			strcpy(szExternalProg,"smt ");
    			return 0;
    			case ID_END:
    			if(HIWORD(wParam)==BN_CLICKED) 
    				SendMessage(hwnd,WM_CLOSE,0,0);
    			return 0;
    			case ID_EDITWIN:
    			MessageBox(hwnd,TEXT("Edit control is sending messages."),szAppName,MB_OK | MB_ICONSTOP);
    			switch(HIWORD(wParam)) {
    			
    			case EN_UPDATE:
    				bNeedSave = TRUE;
    				return 0;
    			
    			case EN_ERRSPACE:
    			case EN_MAXTEXT:
    				MessageBox(hwnd,TEXT("Edit control out of space."),szAppName,MB_OK | MB_ICONSTOP);
    				return 0;
    			}
    			case ID_OUTPUTFORMCSV:
    			SendMessage(hwndPanel[ID_OUTPUTFORMHTML],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTFORMCSV],BM_SETCHECK,1,0L);
    			return 0;
    			case ID_OUTPUTFORMHTML:
    			SendMessage(hwndPanel[ID_OUTPUTFORMCSV],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTFORMHTML],BM_SETCHECK,1,0L);
    			return 0;
    			case ID_OUTPUTDETMIN:
    			SendMessage(hwndPanel[ID_OUTPUTDETMAX],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTDETMED],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTDETMIN],BM_SETCHECK,1,0L);
    			return 0;
    			case ID_OUTPUTDETMED:
    			SendMessage(hwndPanel[ID_OUTPUTDETMIN],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTDETMAX],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTDETMED],BM_SETCHECK,1,0L);
    			return 0;
    	
    		case ID_OUTPUTDETMAX:
    			SendMessage(hwndPanel[ID_OUTPUTDETMIN],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTDETMED],BM_SETCHECK,0,0L);
    			SendMessage(hwndPanel[ID_OUTPUTDETMAX],BM_SETCHECK,1,0L);
    			return 0;
    		}
    	}
    	else switch(LOWORD(wParam)) {
    		//Reactions to the Menu
    
    		case ID_DATEI_NEU:
    			if(bNeedSave && (IDCANCEL == AskAboutSave(hwnd,szTitleName)))
    				return 0;
    				SetWindowText(hwndEditWin,TEXT("\0"));
    			szFileName[0] = '\0';
    			szTitleName[0] = '\0';
    			DoCaption(hwnd,szTitleName);
    			bNeedSave = FALSE;
    			return 0;
    			case ID_DATEI_FFNEN:
    		case ID_DATEI_SPEICHERN:
    		...
    		}
    return 0;
    
    .....
    .....
    is it because i'm giving the edit win another procedure to run for the keybord interface? (looking like the following)

    Code:
    LRESULT CALLBACK EditWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	
    	switch(message) {
    	
    	case WM_KEYDOWN: 
    		if(wParam==VK_TAB) {
    			if(GetKeyState(VK_SHIFT)<0)
    				SetFocus(GetDlgItem(GetParent(hwnd),ID_START));
    		}
    		break;
    
    	case WM_SETFOCUS:
    		idFocus = ID_EDITWIN;
    		break;
    	}
    	
    	if((wParam==VK_TAB) && (GetKeyState(VK_SHIFT) <0))
    		return 0;
    	else
    		return CallWindowProc(OldEditWin,hwnd,message,wParam, lParam);
    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>is it because i'm giving the edit win another procedure to run for the keybord interface? (looking like the following)

    Yes. All the controls messages are sent to the new wndproc.
    OldEditWin=(WNDPROC) SetWindowLong(hwndEditWin ,GWL_WNDPROC ,(LONG) EditWinProc );

    Hard to read the code as posted as it needs spaces or the lines are too long.

    Why not just use the

    Code:
    case WM_COMMAND:
    idControl = GET_WM_COMMAND_ID(wParam ,lParam );//from windowsX.h
    switch(idControl)
    {
         case ID_EDITWIN:
         if (EN_CHANGE == HIWORD(wParam))//text in the edit has changed
         //process the change in text
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    i'll post more proper formatet code next time. anyway, i found the error, which was a pretty simple one. i had ID_EDITWIN defined like that:

    #define NUMOFBUTTONS 14
    #define ID_EDITWIN NUMOFBUTTONS+1

    which causes somehow the edit window not sending messages to the main window. (what the problem was). however, writin it like this:

    #define NUMOFBUTTONS 14
    #define (ID_EDITWIN NUMOFBUTTONS+1)

    works perfectly good.

    thank you for helping

  4. #4
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    another question. i set the number of text in the dit window to unlimited (well, limited by memory) with:

    Code:
    SendMessage(hwndEditWin,EM_LIMITTEXT,-1,0L);
    lets say i open a 25meg text file in that window. it allocates 25megs all alone and cares about the input. when i ope a new file, this memory stays allocated, cause i simply open a new one with:

    Code:
    case ID_DATEI_NEU:
       if(bNeedSave && (IDCANCEL == AskAboutSave(hwnd,szTitleName)))
          return 0;
    
       SetWindowText(hwndEditWin,TEXT("\0"));
       szFileName[0] = '\0';
       szTitleName[0] = '\0';
       DoCaption(hwnd,szTitleName);
       bNeedSave = FALSE;
       return 0;
    My qustion: Is it possible to tell the edit window to free al unused space (means all the space behind the termination '\0'?

    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21