[WinAPI] Dialog wyszukiwania tekstu

0

Cześć,

miałem zamiar się pobawić pre-definiowanym dialogiem wyszukiwania tekstu, jednak, gdy go wyświetlam to przy najechaniu na niego kursorem wywala błąd (te "Wyślij raport o błędach | Nie wysyłaj"):

a kod jest banalny, ale nie wiem czemu się tak sypie:

#include <windows.h>

HWND button, hWnd, find;
DWORD size;
char bufor[80];

LRESULT CALLBACK MainEventProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) {
	WNDCLASSEX wndClass;
	MSG msg;
	char class_name[] = "jakastamklasalfjlkasfas";

	ZeroMemory( &wndClass, sizeof( WNDCLASSEX ) );
	wndClass.cbSize = sizeof( WNDCLASSEX );
	wndClass.hbrBackground = ( HBRUSH ) COLOR_BTNSHADOW;
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
	wndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wndClass.lpszClassName = class_name;
	wndClass.lpfnWndProc = MainEventProc;
	wndClass.hInstance = hInstance;

	if( RegisterClassEx( &wndClass ) == 0 ) return false;

	hWnd = CreateWindowEx( NULL, class_name, "tytul sdf safsdfsad", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
						   800, 500, NULL, NULL, hInstance, NULL );

	button = CreateWindowEx( NULL, "BUTTON", "a", WS_CHILD | WS_VISIBLE, 0, 0, 100, 30, hWnd, NULL, hInstance, NULL );

	ShowWindow( hWnd, SW_SHOWNORMAL );
	UpdateWindow( hWnd );

	for(;;) {
		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
			if( msg.message == WM_QUIT ) break;

			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
	}

	return msg.wParam;
}

LRESULT CALLBACK MainEventProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
	switch( uMsg ) {
		case WM_COMMAND :
			if( ( HWND ) lParam == button ) {
				FINDREPLACE fr;
				ZeroMemory ( &fr, sizeof( FINDREPLACE ) );
				fr.lStructSize = sizeof( FINDREPLACE );
				fr.hwndOwner = hWnd;
				fr.lpstrFindWhat = bufor;
				fr.wFindWhatLen = 80;

				find = FindText( &fr );
			}
			break;
		case WM_DESTROY :
			PostQuitMessage( 0 );
			break;
	}
	return DefWindowProc( hWnd, uMsg, wParam, lParam );
}

Pozdrawiam i dzięki za pomoc.

0

Struktura FINDREPLACE musi istnieć przez zały czas istnienia tego dialogu - przesuń ją poza funkcję, lub poprzedź ją wyrazem static.

0

racja, dzięki.

Note that the FINDREPLACE structure and the buffer for the search string should be a global or static variable so that it does not go out of scope before the dialog box closes.

szkoda tylko, że znajduję takie rzeczy jak już ktoś mi wszystko podstawi pod nos :/ wcześniej oczywiście tego nie widziałem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1