md37 Temat założony przez niniejszego użytkownika  | 
WinApi - ustawianie ikony statycznej kontrolki » 2018-06-26 13:21:41 Witam. Mam taki kod: #include <windows.h>
  MSG kom; HWND hwnd; HWND hStatic; LPCSTR nazwa { "Klasa" };
  LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
  int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {     WNDCLASSEX wc;     wc.cbSize = sizeof( WNDCLASSEX );     wc.style = 0;     wc.lpfnWndProc = & WndProc;     wc.cbClsExtra = 0;     wc.cbWndExtra = 0;     wc.hInstance = hInstance;     wc.hCursor = LoadCursor( nullptr, IDC_ARROW );     wc.hIcon = LoadIcon( nullptr, IDI_ERROR );     wc.hbrBackground = reinterpret_cast < HBRUSH >( COLOR_SCROLLBAR + 1 );     wc.lpszMenuName = nullptr;     wc.lpszClassName = nazwa;     wc.hIconSm = LoadIcon( nullptr, IDI_APPLICATION );          if( !RegisterClassEx( & wc ) )     {         MessageBox( nullptr, "Nie udało się zarejestrować klasy okna.", "Błąd",         MB_ICONERROR );         return 1;     }     hwnd = CreateWindowEx( 0, nazwa, "Moje okno",     WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,     400, 400, nullptr, nullptr, hInstance, nullptr );          if( !hwnd )     {         MessageBox( nullptr, "Nie udało się utworzyć okna.", "Błąd",         MB_ICONERROR );         return 1;     }          hStatic = CreateWindowEx( 0,     "STATIC",     NULL,     WS_VISIBLE | WS_CHILD,     5, 5,     145, 45,     hwnd,     nullptr,     hInstance,     nullptr );          SendMessage( hStatic, STM_SETICON,     reinterpret_cast < WPARAM >( LoadIcon( NULL, IDI_APPLICATION ) ), 0 );          ShowWindow( hwnd, nCmdShow );     UpdateWindow( hwnd );               while( GetMessage( & kom, nullptr, 0, 0 ) )     {         TranslateMessage( & kom );         DispatchMessage( & kom );     }     return kom.wParam; }
  LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) {     switch( msg )     {              case WM_CLOSE:         DestroyWindow( hwnd );         break;              case WM_DESTROY:         PostQuitMessage( 0 );         break;                  default:         return DefWindowProc( hwnd, msg, wParam, lParam );     }     return 0; }
  Chcę ustawić statycznej kontrolce ikonę. Wywołuję funkcję SendMessage, lecz ona zmienia ikonę programu, a nie kontrolki.  |