Ich bin total verblödet
-
ich find der Aufwand des Fenster selber zu machen ist für mich geringer, als mir jetzt des was unter dem link stand abzuschreiben und dann stundenlang über den fehlern zu brüten, die daraus entstehen, dass ich nicht wirklich verstanden hab wies eigentlich geht

-
MSDN schrieb:
Finding Text
This topic describes sample code that displays and manages a Find dialog box so the user can specify the parameters of a search operation. The dialog box sends messages to your window procedure so you can perform the search operation.The code for displaying and managing a Replace dialog box is similar, except that it uses the ReplaceText function to display the dialog box. The Replace dialog box also sends messages in response to user clicks on the Replace and Replace All buttons.
To use the Find or Replace dialog box, you must perform three separate tasks:
1. Get a message identifier for the FINDMSGSTRING registered message.
2. Display the dialog box.
3. Process FINDMSGSTRING messages when the dialog box is open.When you initialize your application, call the RegisterWindowMessage function to get a message identifier for the FINDMSGSTRING registered message.
UINT uFindReplaceMsg; // message identifier for FINDMSGSTRING uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);To display a Find dialog box, first initialize a FINDREPLACE structure and then call the FindText function. Note that the FINDREPLACE structure and the buffer for the search string should be a global or static variable so it does not go out of scope before the dialog box closes. You must set the hwndOwner member to specify the window that receives the registered messages. After you create the dialog box, you can move or manipulate it by using the returned handle.
FINDREPLACE fr; // common dialog box structure HWND hwnd; // owner window CHAR szFindWhat[80]; // buffer receiving string HWND hdlg = NULL; // handle to Find dialog box // Initialize FINDREPLACE ZeroMemory(&fr, sizeof(fr)); fr.lStructSize = sizeof(fr); fr.hwndOwner = hwnd; fr.lpstrFindWhat = szFindWhat; fr.wFindWhatLen = 80; fr.Flags = 0; hdlg = FindText(&fr);When the dialog box is open, your main message loop must include a call to the IsDialogMessage function. Pass a handle to the dialog box as a parameter in the IsDialogMessage call. This ensures that the dialog box correctly processes keyboard messages.
To monitor messages sent from the dialog box, your window procedure must check for the FINDMSGSTRING registered message and process the values passed in the FINDREPLACE structure as in the following example:
LPFINDREPLACE lpfr; if (message == uFindReplaceMsg){ // Get pointer to FINDREPLACE structure from lParam. lpfr = (LPFINDREPLACE)lParam; // If the FR_DIALOGTERM flag is set, // invalidate the handle identifying the dialog box. if (lpfr->Flags & FR_DIALOGTERM){ hdlg = NULL; return 0; } // If the FR_FINDNEXT flag is set, // call the application-defined search routine // to search for the requested string. if (lpfr->Flags & FR_FINDNEXT) SearchFile(lpfr->lpstrFindWhat, (BOOL) (lpfr->Flags & FR_DOWN), (BOOL) (lpfr->Flags & FR_MATCHCASE)); return 0; }Was ist jetzt daran so schlimm?
-
das das bei mir net funzt, vielleicht liegts daran:
while (GetMessage (&messages, NULL, 0, 0)) { /* Send messages for dialoge boxes to correct destination */ if (IsDialogMessage (hSearch, &messages) == 0) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } }
-
Was ist hSearch???
-
Das müsste wohl das Handle zu dem Dialog sein - also der Rückgabewert von FindText. Aber den merkt er sich ja komischer Weise gar nicht

-
// in header: HWND hSearch = NULL; CHAR szFindWhat[80]; // buffer receiving string // main message loop while (GetMessage (&messages, NULL, 0, 0)) { /* Send messages for dialoge boxes to correct destination */ if (IsDialogMessage (hSearch, &messages) == 0) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } } // WindowProcedure: case mSEARCH: /* Suchfenster öffnen */ { FINDREPLACE fr; // common dialog box structure // Initialize FINDREPLACE ZeroMemory(&fr, sizeof(fr)); fr.lStructSize = sizeof(fr); fr.hwndOwner = hWnd; fr.lpstrFindWhat = szFindWhat; fr.wFindWhatLen = 80; hSearch = FindText(&fr); break; }so, ich hoff ich hab nix vergessen. des mSEARCH is n unterpunkt von WM_COMMAND
-
Wie sieht denn das NIcht-Funktionieren aus?!
-
ich klick auf den Button, das Fenster kommt und dann kommt folgender Fehler (WIN2000):
Fehler in Anwendung [...] Der Vorgang "read" konnte nicht auf dem Speicher durchgeführt werden.
-
ich frag mich gerade:
CHAR szFindWhat[80]; // buffer receiving string
...war die 80 jetzt die Größe des Char-Arrays oder das letzte Element ? - Vergess das immer wieder...
-
Bin mir gerade nicht ganz sicher, aber wird szFindWhat nicht nur deklariert (also nicht definiert - Speicher belegt), wenn das nur im Header steht?!
Setzt das doch mal direkt in die Quellcode-Datei
@geeky: Afaik bezeichnet 80 die Größe - daran sollte formell eigentlich auch nichts falsch sein - steht ja so in der MSDN-Library.
@N00Bie: Mit dieser Information rückst du aber reichlich früh raus

-
dann aber static, oder?
-
nee, funzt net. ich hab folgendes an den anfang der WindowProcedure gestellt:
static CHAR szFindWhat[80];aber is trotzdem nix
außerdem kommt des problem ja, wenn die box da is, und dann messages verarbeiten muss (fällt mir grad auf). wenn man die maus drüberbewegt, is noch ok, aber button oder edit anklicken is tödlich...
-
ne, ich meinte eher global

-
sorry, flenders, funzt auch global in der Quellcodedatei nicht. Ich glaub immer noch, dass es an der Nachrichtenverarbeitung liegt, da der Buffer ja vor dem Starten des Suchfensters mit ZeroMemory (...) mit lauter nullen beschrieben wird, also ja der speicher schon definiert sein sollte. soll ich den ganzen quellcode posten? es is schließlich nur ein einfacher editor... (oje, ich hab schon angst vor der kritik)
-
Bist du das Programm mal mit dem Debugger schrittweise durchgegangen, damit du mal weißt, wo genau der Fehler steckt / welche Stelle die Schutzverletzung auslöst?!
-
ich hab dev-cpp und der debugger funzt net recht, er zeigt zwar einen segmention fault an, aber er sagt net wo (leider)
-
ich habs nu:
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LPFINDREPLACE fr; switch (message) /* handle the messages */ { case WM_CREATE: { ... break; } case WM_COMMAND: { switch (LOWORD (wParam)) { case mSEARCH: /* Suchfenster öffnen */ { if (fr != NULL) delete fr; try { fr = new FINDREPLACE; } catch (...) {} if (fr == NULL) MessageBox (hWnd, "Fehler", "", MB_OK); // Initialize FINDREPLACE fr->lStructSize = sizeof(FINDREPLACE); fr->hwndOwner = hWnd; fr->lpstrFindWhat = szFindWhat; fr->wFindWhatLen = 80; fr->Flags = 0; hSearch = FindText(fr); break; } case mSEARCHAGAIN: /* Suchen */ { break; } default: break; } break; } case WM_DESTROY: { PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; } default: /* for messages that we don't deal with */ return DefWindowProc (hWnd, message, wParam, lParam); } return 0; }