Witam.
Stworzyłem okno potomne z polami tekstowymi i przyciskiem.
Chcę aby po naciśnięciu przycisku okno się wyłączało i dane z pól tekst. zapisywało do zmiennych.
Zapisywanie działa dopóki jest wypełnione co najmniej jedno pole. Gdy nie wypełnię nic tylko od razu zapisuję pojawia się błąd:
App.exe has triggered a breakpoint.
while( GetMessage( & msg1, NULL, 0, 0 ) )
{
TranslateMessage( & msg1 );
DispatchMessage( & msg1 ); // <- tutaj błąd: ((msg1).hwnd)->unused | <Unable to read memory>
}
EnableWindow( window_main, TRUE );
return msg1.wParam;
LRESULT CALLBACK WndProc( HWND window_main, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_CLOSE:
DestroyWindow( window_main );
if( new_Window != NULL ) DestroyWindow( new_Window );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
case WM_COMMAND:
{
switch( wParam ) {
case Add_something:
{
HWND hText7;
new_Window = CreateWindowEx( WS_EX_CLIENTEDGE, ClassName, "New Window", WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 550, 230, window_main, NULL, hInstance, NULL );
hText1 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 20, 90, 20, new_Window,( HMENU ) ID_TEXT_ADD_RESOURCES_1, hInstance, NULL );
hText2 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 350, 20, 90, 20, new_Window,( HMENU ) ID_TEXT_ADD_RESOURCES_2, hInstance, NULL );
hText3 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 60, 90, 20, new_Window,( HMENU ) ID_TEXT_ADD_RESOURCES_3, hInstance, NULL );
hText4 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 350, 60, 90, 20, new_Window,( HMENU ) ID_TEXT_ADD_RESOURCES_4, hInstance, NULL );
hText5 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 100, 90, 20, new_Window,( HMENU ) ID_TEXT_ADD_RESOURCES_5, hInstance, NULL );
hText6 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 350, 100, 90, 20, new_Window,( HMENU ) ID_TEXT_ADD_RESOURCES_6, hInstance, NULL );
hText7 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_READONLY, 30, 20, 60, 20, new_Window, NULL, hInstance, NULL );
hButton = CreateWindowEx( 0, "BUTTON", "Zapisz", WS_CHILD | WS_VISIBLE | WS_BORDER, 230, 140, 80, 20, new_Window,( HMENU ) ID_BUTTON_ADD_RESOURCES, hInstance, NULL );
SetWindowText( hText7, "Option 1" );
EnableWindow( window_main, FALSE );
while( GetMessage( & msg1, NULL, 0, 0 ) )
{
TranslateMessage( & msg1 );
DispatchMessage( & msg1 );
}
EnableWindow( window_main, TRUE );
return msg1.wParam;
} break;
case Print:
{
}
case ID_BUTTON_ADD_RESOURCES:
{
string temp;
DWORD dlugosc;
LPSTR Bufor;
bool Check_Bufor, Check_Status = TRUE;
int value;
dlugosc = GetWindowTextLength( hText1 );
if( dlugosc > 0 ) {
Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText1, Bufor, dlugosc + 1 );
Check_Bufor = Check( Bufor );
if( Check_Bufor == true ) {
value = boost::lexical_cast < int >( Bufor );
temp_class->a = value;
}
else {
Check_Status = FALSE;
}
};
dlugosc = GetWindowTextLength( hText2 );
if( dlugosc > 0 ) {
Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText2, Bufor, dlugosc + 1 );
Check_Bufor = Check( Bufor );
if( Check_Bufor == true ) {
value = boost::lexical_cast < int >( Bufor );
temp_class->b = value;
}
else {
Check_Status = FALSE;
}
};
dlugosc = GetWindowTextLength( hText3 );
if( dlugosc > 0 ) {
Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText3, Bufor, dlugosc + 1 );
Check_Bufor = Check( Bufor );
if( Check_Bufor == true ) {
value = boost::lexical_cast < int >( Bufor );
temp_class->c = value;
}
else {
Check_Status = FALSE;
}
};
dlugosc = GetWindowTextLength( hText4 );
if( dlugosc > 0 ) {
Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText4, Bufor, dlugosc + 1 );
Check_Bufor = Check( Bufor );
if( Check_Bufor == true ) {
value = boost::lexical_cast < int >( Bufor );
temp_class->d = value;
}
else {
Check_Status = FALSE;
}
};
dlugosc = GetWindowTextLength( hText5 );
if( dlugosc > 0 ) {
Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText5, Bufor, dlugosc + 1 );
Check_Bufor = Check( Bufor );
if( Check_Bufor == true ) {
value = boost::lexical_cast < int >( Bufor );
temp_class->e = value;
}
else {
Check_Status = FALSE;
}
};
dlugosc = GetWindowTextLength( hText6 );
if( dlugosc > 0 ) {
Bufor =( LPSTR ) GlobalAlloc( GPTR, dlugosc + 1 );
GetWindowText( hText6, Bufor, dlugosc + 1 );
Check_Bufor = Check( Bufor );
if( Check_Bufor == true ) {
value = boost::lexical_cast < int >( Bufor );
temp_class->f = value;
}
else {
Check_Status = FALSE;
}
};
if( Check_Status == TRUE ) {
GlobalFree( Bufor );
EnableWindow( window_main, TRUE );
DestroyWindow( new_Window );
}
else if( Check_Status == FALSE ) {
MessageBox( new_Window, "Błąd przy wpisywaniu. \nMożna wpisywać tylko cyfry.", "ERROR", MB_OK | MB_ICONWARNING );
};
} break;
}
} break;
default:
return DefWindowProc( window_main, msg, wParam, lParam );
}
return 0;
}
- Mógłby ktoś wytłumaczyć dlaczego jet błąd gdy wszystkie pola zostaną puste, a gdy chociaż jeden jest wypełniony to już nie?
- I jak można to naprawić?