xordi Temat założony przez niniejszego użytkownika |
Wysyłanie komunikatów z własnej kontrolki. (z "superclassy") » 2014-01-28 18:30:47 Stworzyłem sobie superclass'ę zawierającą kilka przycisków: #include "kontrolki.h"
static HWND g_hPlayButton, g_hStopButton, g_hAddFile, g_hAddFiles, g_hDeleteFile; WNDPROC g_OldControlProc;
bool InitializeControls() { const wchar_t CLASS_NAME[] = L"Kontrolki"; WNDCLASS wc_kontrolki; GetClassInfo( NULL, L"STATIC", & wc_kontrolki ); wc_kontrolki.lpszMenuName = NULL; wc_kontrolki.lpszClassName = CLASS_NAME; wc_kontrolki.hInstance = GetModuleHandle( NULL ); g_OldControlProc = wc_kontrolki.lpfnWndProc; wc_kontrolki.lpfnWndProc = ControlProc; if( !RegisterClass( & wc_kontrolki ) ) { MessageBox( NULL, L"Nie udało się zarejestrować nowej klasy.", L"Yh...", MB_ICONSTOP ); return 0; } return 1; }
LRESULT CALLBACK ControlProc( HWND hwnd, UINT mesg, WPARAM wParam, LPARAM lParam ) { switch( mesg ) { case WM_CREATE: { RECT rcl; LONG l_buttHeight; GetClientRect( hwnd, & rcl ); l_buttHeight =( rcl.bottom -( 4 * 5 ) ) / 5; g_hPlayButton = CreateWindowEx( 0, L"BUTTON", L"Play", WS_CHILD | WS_VISIBLE, 0, 0, rcl.right, l_buttHeight, hwnd,( HMENU ) 1001, GetModuleHandle( NULL ), NULL ); g_hStopButton = CreateWindowEx( 0, L"BUTTON", L"Stop", WS_CHILD | WS_VISIBLE, 0, l_buttHeight + 5, rcl.right, l_buttHeight, hwnd,( HMENU ) 1002, GetModuleHandle( NULL ), NULL ); g_hAddFile = CreateWindowEx( 0, L"BUTTON", L"Add File", WS_CHILD | WS_VISIBLE, 0, 2 *( l_buttHeight + 5 ), rcl.right, l_buttHeight, hwnd,( HMENU ) 1003, GetModuleHandle( NULL ), NULL ); g_hAddFiles = CreateWindowEx( 0, L"BUTTON", L"Add Files", WS_CHILD | WS_VISIBLE, 0, 3 *( l_buttHeight + 5 ), rcl.right, l_buttHeight, hwnd,( HMENU ) 1004, GetModuleHandle( NULL ), NULL ); g_hDeleteFile = CreateWindowEx( 0, L"BUTTON", L"Delete", WS_CHILD | WS_VISIBLE, 0, 4 *( l_buttHeight + 5 ), rcl.right, l_buttHeight, hwnd,( HMENU ) 1005, GetModuleHandle( NULL ), NULL ); } break; } return CallWindowProc( g_OldControlProc, hwnd, mesg, wParam, lParam ); }
I problem teraz mam tego typu że chciałbym obsłużyć komunikaty o naciśnięciu któregoś z nich w głównym oknie i totalnie nie wiem jak się do tego zabrać... Byłbym wdzięczny bardzo za jakiś mały przykład albo snippet. Pozdrawiam. |
|
xordi Temat założony przez niniejszego użytkownika |
Rozwiązane » 2014-01-28 23:03:02 Problem raczej uważam za rozwiązany, jeśli ktoś zna bardziej skuteczny sposób na rozwiązanie tego to proszę o komentarz. Nadałem indentyfikatory dla przycisków: #define IDC_PLAY 1001 #define IDC_STOP 1002 #define IDC_ADDFILE 1003 #define IDC_ADDFILES 1004 #define IDC_DELETE 1005
..........
case WM_CREATE: { RECT rcl; LONG l_buttHeight; GetClientRect( hwnd, & rcl ); l_buttHeight =( rcl.bottom -( 4 * 5 ) ) / 5; g_hPlayButton = CreateWindowEx( 0, L"BUTTON", L"Play", WS_CHILD | WS_VISIBLE, 0, 0, rcl.right, l_buttHeight, hwnd,( HMENU ) IDC_PLAY, GetModuleHandle( NULL ), NULL ); g_hStopButton = CreateWindowEx( 0, L"BUTTON", L"Stop", WS_CHILD | WS_VISIBLE, 0, l_buttHeight + 5, rcl.right, l_buttHeight, hwnd,( HMENU ) IDC_STOP, GetModuleHandle( NULL ), NULL ); g_hAddFile = CreateWindowEx( 0, L"BUTTON", L"Add File", WS_CHILD | WS_VISIBLE, 0, 2 *( l_buttHeight + 5 ), rcl.right, l_buttHeight, hwnd,( HMENU ) IDC_ADDFILE, GetModuleHandle( NULL ), NULL ); g_hAddFiles = CreateWindowEx( 0, L"BUTTON", L"Add Files", WS_CHILD | WS_VISIBLE, 0, 3 *( l_buttHeight + 5 ), rcl.right, l_buttHeight, hwnd,( HMENU ) IDC_ADDFILES, GetModuleHandle( NULL ), NULL ); g_hDeleteFile = CreateWindowEx( 0, L"BUTTON", L"Delete", WS_CHILD | WS_VISIBLE, 0, 4 *( l_buttHeight + 5 ), rcl.right, l_buttHeight, hwnd,( HMENU ) IDC_DELETE, GetModuleHandle( NULL ), NULL ); } case WM_COMMAND: { SendMessage( GetParent( hwnd ), WM_COMMAND,( WPARAM ) MAKELONG( LOWORD( wParam ), BN_CLICKED ),( LPARAM ) hwnd ); }
A potem w procedurze głównego okna: case WM_COMMAND: { wmId = LOWORD( wParam ); wmEvent = HIWORD( wParam ); if((( HWND ) lParam ) == hControl ) { if( ControlMessagesHandler( wmId ) ) return 0; } return 0; }
bool ControlMessagesHandler( int wmId ) { switch( wmId ) { case IDC_PLAY: { return true; } case IDC_STOP: { return true; } case IDC_ADDFILE: { return true; } case IDC_ADDFILES: { return true; } case IDC_DELETE: { return true; } break; } }
Zaznaczam że jestem mocno początkujący więc proszę o wyrozumiałość :) |
|
« 1 » |