dzwigar Temat założony przez niniejszego użytkownika |
Pola statyczne w zakładkach » 2012-12-25 01:35:23 Witam wszystkich. Posiadam okno z dwoma zakładkami, na jednej z nich mam kilka pól tekstowych podpisane za pomocą pól statycznych. We switchu mam ustawione dla drugiej zakładki wszystko ukryte lecz pola statyczne z tekstem nie ukrywają sie reszta tak . Oto kod programu #include <windows.h> #include <cstdio> #include <commctrl.h> #define ID_przycisk 501 #define ID_TAB_ZW 0 #define ID_TAB_ST 1
LPSTR klasa = "Klasa1";
MSG Komunikat;
HWND hText; HWND hText1; HWND hText2; HWND hText3; HWND hText4; HWND hText5; HWND hText6; HWND hText7;
HWND hTab;
HWND hPrzycisk;
HWND hStatic; HWND hStatic1; HWND hStatic2; HWND hStatic3; HWND hStatic4;
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
void wynik();
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { WNDCLASS wc; wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = GetSysColorBrush( COLOR_3DFACE ); wc.lpszMenuName = NULL; wc.lpszClassName = klasa; RegisterClass( & wc ); HWND hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, klasa, "okienko", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1500, 500, NULL, NULL, hInstance, NULL ); typedef struct { UINT mask; #if (_WIN32_IE >= 0x0300) DWORD dwState; DWORD dwStateMask; #else UINT lpReserved1; UINT lpReserved2; #endif LPTSTR pszText; int cchTextMax; int iImage; LPARAM lParam; } TCITEM, * LPTCITEM; hTab = CreateWindowEx( 0, WC_TABCONTROL, 0, WS_CHILD | WS_VISIBLE | TCS_FIXEDWIDTH, 0, 0, 1500, 500, hWnd,( HMENU ) 10, hInstance, NULL ); TabCtrl_SetItemSize( hTab, 150, 20 ); TCITEM tci1, tci2; tci1.mask = TCIF_TEXT; tci2.mask = TCIF_TEXT; tci1.pszText = "Zaawansowane"; tci2.pszText = "Standardowe"; tci1.cchTextMax = sizeof( "Zaawansowane" ); tci2.cchTextMax = sizeof( "Standardowe" ); TabCtrl_InsertItem( hTab, ID_TAB_ZW, & tci1 ); TabCtrl_InsertItem( hTab, ID_TAB_ST, & tci2 ); hPrzycisk = CreateWindowEx( 0, "BUTTON", "Beregn", WS_CHILD | WS_VISIBLE, 170, 280, 400, 130, hWnd,( HMENU ) ID_przycisk, hInstance, NULL ); hText = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 230, 35, 40, 20, hWnd, NULL, hInstance, NULL ); hText1 = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 65, 65, 30, 20, hWnd, NULL, hInstance, NULL ); hText2 = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 65, 95, 30, 20, hWnd, NULL, hInstance, NULL ); hText3 = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 65, 125, 30, 20, hWnd, NULL, hInstance, NULL ); hText4 = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 400, 35, 30, 20, hWnd, NULL, hInstance, NULL ); HWND hStatic = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 170, 38, 55, 15, hWnd, NULL, hInstance, NULL ); SetWindowText( hStatic, "Klassa" ); HWND hStatic1 = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 68, 55, 15, hWnd, NULL, hInstance, NULL ); SetWindowText( hStatic1, "Lengde" ); HWND hStatic2 = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 98, 55, 15, hWnd, NULL, hInstance, NULL ); SetWindowText( hStatic2, "Brede" ); HWND hStatic3 = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 128, 55, 15, hWnd, NULL, hInstance, NULL ); SetWindowText( hStatic3, "Hoyde" ); HWND hStatic4 = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 320, 38, 75, 15, hWnd, NULL, hInstance, NULL ); SetWindowText( hStatic4, "Antall Fag" ); ShowWindow( hWnd, nCmdShow ); UpdateWindow( hWnd ); while( GetMessage( & Komunikat, NULL, 0, 0 ) ) { TranslateMessage( & Komunikat ); DispatchMessage( & Komunikat ); } return Komunikat.wParam; }
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_NOTIFY: LPNMHDR n; n =( LPNMHDR ) lParam; if( n->code == TCN_SELCHANGE && n->hwndFrom == hTab ) { int index = TabCtrl_GetCurSel( hTab ); switch( index ) { case ID_TAB_ZW: ShowWindow( hText, SW_SHOW ); ShowWindow( hText1, SW_SHOW ); ShowWindow( hText2, SW_SHOW ); ShowWindow( hText3, SW_SHOW ); ShowWindow( hText4, SW_SHOW ); ShowWindow( hPrzycisk, SW_SHOW ); ShowWindow( hStatic, SW_SHOW ); ShowWindow( hStatic1, SW_SHOW ); ShowWindow( hStatic2, SW_SHOW ); ShowWindow( hStatic3, SW_SHOW ); ShowWindow( hStatic4, SW_SHOW ); break; case ID_TAB_ST: ShowWindow( hStatic, SW_HIDE ); ShowWindow( hStatic1, SW_HIDE ); ShowWindow( hStatic2, SW_HIDE ); ShowWindow( hStatic3, SW_HIDE ); ShowWindow( hStatic4, SW_HIDE ); ShowWindow( hText, SW_HIDE ); ShowWindow( hText1, SW_HIDE ); ShowWindow( hText2, SW_HIDE ); ShowWindow( hText3, SW_HIDE ); ShowWindow( hText4, SW_HIDE ); ShowWindow( hPrzycisk, SW_HIDE ); break; } } break; case WM_CLOSE: DestroyWindow( hwnd ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; case WM_COMMAND: switch( wParam ) { case ID_przycisk: wynik(); } break; default: return DefWindowProc( hwnd, msg, wParam, lParam ); } return 0; }
void wynik() { SetWindowText( hStatic, "Klassa" ); double a, b, c, wyn; DWORD length = GetWindowTextLength( hText1 ); LPSTR buf1 =( LPSTR ) GlobalAlloc( GPTR, length + 3 ); GetWindowText( hText1, buf1, length + 3 ); for( size_t i = 0, j = strlen( buf1 ); i < j; ++i ) { if( buf1[ i ] == ',' ) buf1[ i ] = '.'; } DWORD length2 = GetWindowTextLength( hText2 ); LPSTR buf2 =( LPSTR ) GlobalAlloc( GPTR, length + 3 ); GetWindowText( hText2, buf2, length + 3 ); for( size_t i = 0, j = strlen( buf2 ); i < j; ++i ) { if( buf2[ i ] == ',' ) buf2[ i ] = '.'; } DWORD length3 = GetWindowTextLength( hText3 ); LPSTR buf3 =( LPSTR ) GlobalAlloc( GPTR, length + 3 ); GetWindowText( hText3, buf3, length + 3 ); for( size_t i = 0, j = strlen( buf3 ); i < j; ++i ) { if( buf3[ i ] == ',' ) buf3[ i ] = '.'; } GlobalFree( & buf1 ); GlobalFree( & buf2 ); GlobalFree( & buf3 ); sscanf( buf1, "%lf", & a ); sscanf( buf2, "%lf", & b ); sscanf( buf3, "%lf", & c ); wyn = a + b + c; char result[ 100 ]; sprintf( result, "%lf", wyn ); SetWindowText( hText, result ); }
Udało mi się kolejny raz zdąży prezd druzgocącą krytyką. Pola statyczne wyświetlały się na obu zakładkach ponieważ HWND hStatic1 = CreateWindowEx( 0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 68, 55, 15, hWnd, NULL, hInstance, NULL ); uchwyt był do okna głównego HWND Kolejny raz zrobiłem kilka kroków w przód ale ten jeden w tył był potrzebny. |