edit box ganzes fenster -20



  • soory für die topic....wusste net wie ich s schreiben soll.. 😉

    ich will nen edit feld was das ganze fenster bedeckt wobei noch an jeder seite 20 Px platz sein sollen....mein bisheriger code

    hEditMain = CreateWindowEx(WS_EX_CLIENTEDGE,"edit","",WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |ES_AUTOVSCROLL,20, 20, LOWORD(lParam), (LOWORD(lParam)),hwnd,NULL,((LPCREATESTRUCT) lParam) -> hInstance,NULL);
    


  • Bin ihc blind oder hast du tatsächlich die Frage vergessen?
    Da du aber Glück hast und meine Kristallkugel momentan funktioniert würde ich jetzt aber einfach mal schätzen, dass du
    bei den beiden Parametern, welche die Breite und die Höhe angeben ein wenig scheiss gebaut hast ...
    zweimal LOWORD(lParam) scheint mir schonmal sehr komisch. Ausserdem:
    Nehmen wir an, dein Dialog ist 100 Pixel breit und du startest erst bei Pixel 20, dann darfst du doch net einfach die Breite des Dialogs für die Breite des Editfeldes verwenden, sondern musst 40 Pixel abziehen!



  • int platzzuallenseiten=20;
    // in der window proc
    ...
    case WM_CREATE:
    hEditMain = CreateWindowEx(WS_EX_CLIENTEDGE,"edit","",WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |ES_AUTOVSCROLL,0, 0, 0, 0,hwnd,NULL,((LPCREATESTRUCT) lParam) -> hInstance,NULL);
    break;
    case WM_SIZE:
    MoveWindow(hEditMain,platzzuallenseiten,platzzuallenseiten,LOWORD(lParam)-2*platzzuallenseiten,HIWORD(lParam)-2*platzzuallenseiten,1);
    ...
    

    ich hoffe das hilft dir 🙂



  • thx an euch beiden....es geht nun...

    mit dem doppelten LOWORD war warscheinlich das böse copy & paste dran schuld 😉 😃



  • ich hab gleich noch nen problem bzw 2.... und schriebs gelich hier rein...
    es geht um öffnen / speichern von datein...ich hab auch schon die suchmashciene und alles benutzt auch msdn....

    zum öffnen der code:

    OPENFILENAME ofn;       // common dialog box structure
    	char szFile[260];       // buffer for file name
    	HANDLE hf;              // file handle
    
    	// Initialize OPENFILENAME
    	ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFile = szFile;
    	//
    	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
    	// use the contents of szFile to initialize itself.
    	//
    	ofn.lpstrFile[0] = '\0';
    	ofn.nMaxFile = sizeof(szFile);
    	ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = NULL;
    	ofn.nMaxFileTitle = 0;
    	ofn.lpstrInitialDir = NULL;
    	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    
    	// Display the Open dialog box.
    if (GetOpenFileName(&ofn)==TRUE)
    					hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
    					0, (LPSECURITY_ATTRIBUTES) NULL,
    					OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
    					(HANDLE) NULL);
    

    so stehts in der msdn
    ich bin nun so weit das sich der öfnnen dialog öffnet nun will ich aber das er den inhalt der txt datei auch in ne editbox schreibt....
    und das gleiche andersrum das er den inhalt der editbox in ne datei speichert...

    sorry das ich euch mit noob fragen "nerve" aber jeder war mal anfänger 😉



  • Mit ReadFile aus der Datei lesen und mit WriteFile in die Datei schreiben. Näheres siehe MSDN.



  • WM_SETTEXT bzw. SetDlgItemText



  • danke nun zeigt er auch schon as in der edit box an nur das problem ist das er immer gewisse zeichen hinten drann hängt kleines bsp:

    folgender TExt steht in der Datei:

    Das ist ein Test Text in einer Datei.

    das Problem ist nun das er aber folgendes ausgibt:

    DAs ist ein Test Text in einer Datei.ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ$

    zu letzt mein SC..

    LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    
    	OPENFILENAME ofn;       
    	char szFile[260];       /
    	HANDLE hf;             
    
    	ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFile = szFile;
    	ofn.lpstrFile[0] = '\0';
    	ofn.nMaxFile = sizeof(szFile);
    	ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = NULL;
    	ofn.nMaxFileTitle = 0;
    	ofn.lpstrInitialDir = NULL;
    	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    
    	HDC hdc;
    	PAINTSTRUCT ps;
    	static HINSTANCE hInstance;
    	static HWND hEditMain;
    	int platzzuallenseiten=0;
    	static char filename[] = "";  
        DWORD filesize;
    
    	switch (iMsg)
    	{
    		case WM_PAINT:
    		{
    			hdc = BeginPaint (hwnd, &ps);
    			EndPaint (hwnd, &ps);
    			break;
    		}
    		case WM_CREATE:
    		{
    			hEditMain = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","",WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE |ES_AUTOVSCROLL,0, 0, 0, 0,hwnd,NULL,((LPCREATESTRUCT) lParam) -> hInstance,NULL);
    			break;
    		}
    		case WM_SIZE:
    		{
    			MoveWindow(hEditMain,platzzuallenseiten,platzzuallenseiten,LOWORD(lParam)-2*platzzuallenseiten,HIWORD(lParam)-2*platzzuallenseiten,1);
    
    		}
    		case WM_COMMAND:
    		{
    			switch(wParam)
    			{
    
    				case ID_DATEI_OEFFNEN:
    				{
    					if (GetOpenFileName(&ofn)==TRUE)
    					{
    					hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
    					0, (LPSECURITY_ATTRIBUTES) NULL,
    					OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
    					(HANDLE) NULL);
    					}
    					if (hf == INVALID_HANDLE_VALUE)
    					{
    						break;
    					}  
    					else { 
    					  DWORD bytesRead = 0; 
                      filesize = GetFileSize(hf, NULL); 
    				  char textdaten[255];
    
                      ReadFile(hf, &textdaten, filesize, &bytesRead, NULL); 
    				  CloseHandle(hf); 
                      SetWindowText(hEditMain, textdaten); 
    					}
    		break;
    				}
    
    			}return 0;
    
    			break;
    		}
    		case WM_DESTROY :
    		{
    			PostQuitMessage (0) ;
    			return 0 ;
    		}
    	}
    	return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
    }
    

    hoffe das ihr mir noch ein weiteres mal helfen könnt danke



  • Du solltest deinen textdaten-Buffer initialisieren (= {0} - ZeroMemory - etc.)



  • sorry kannst du das bitte nochmal etwas genauer erklären...:(



  • Falls du eine cpp Datei hast (dem Quelltext nach ist dem so):

    char textdaten[255] = {0};
    // ZeroMemory(textdaten,sizeof(textdaten)); sollte auch gehen
    

Anmelden zum Antworten