Rosumad Temat założony przez niniejszego użytkownika |
winAPI - problem z subclassingiem » 2014-03-23 16:39:00 Otóż mam sobie taki kod: #include <windows.h>
LRESULT CALLBACK WindowProcedure( HWND, UINT, WPARAM, LPARAM );
char szClassName[] = "WinBasket";
HWND hText; HMENU hMenu; WNDCLASS edit2; WNDPROC OldWndProc = WindowProcedure; void ScreenResolution( int & poziom, int & pion ) { RECT desktop; const HWND hDesktop = GetDesktopWindow(); GetWindowRect( hDesktop, & desktop ); poziom = desktop.right; pion = desktop.bottom; }
void AppResolution( int & szerap, int & wysap, HWND hwnd ) { RECT app; GetWindowRect( hwnd, & app ); szerap = app.right - app.left - 14; wysap = app.bottom - app.top - 56; }
int WINAPI WinMain( HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil ) { HWND hwnd; MSG messages; WNDCLASSEX wincl; int poziom, pion, lewaap, goraap, szerap, wysap; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof( WNDCLASSEX ); wincl.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wincl.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); wincl.hCursor = LoadCursor( NULL, IDC_ARROW ); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground =( HBRUSH ) COLOR_BACKGROUND; GetClassInfo( hThisInstance, "EDIT", & edit2 ); edit2.lpszMenuName = NULL; edit2.lpszClassName = "EDIT2"; edit2.hInstance = hThisInstance; edit2.lpfnWndProc = NowyProcesFunkcja; if( !RegisterClassEx( & wincl ) ) return 0; if( !RegisterClass( & edit2 ) ) return 0; hMenu = LoadMenu( hThisInstance, MAKEINTRESOURCE( 1000 ) ); hwnd = CreateWindowEx( 0, szClassName, "WinBasket", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 700, 700, HWND_DESKTOP, hMenu, hThisInstance, NULL ); hText = CreateWindowEx( WS_EX_DLGMODALFRAME, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 0, 0, 700, 700, hwnd, NULL, hThisInstance, NULL ); ShowWindow( hwnd, nFunsterStil ); while( GetMessage( & messages, NULL, 0, 0 ) ) { AppResolution( szerap, wysap, hwnd ); SetWindowPos( hText, HWND_TOP, 0, 0, szerap, wysap, SWP_SHOWWINDOW ); TranslateMessage( & messages ); DispatchMessage( & messages ); } return messages.wParam; }
LRESULT CALLBACK WindowProcedure( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_DESTROY: { PostQuitMessage( 0 ); break; } case WM_COMMAND: { if( LOWORD( wParam ) == 999 ) PostQuitMessage( 0 ); break; } default: return DefWindowProc( hwnd, message, wParam, lParam ); } return 0; }
LRESULT CALLBACK NowyProcesFunkcja( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_RBUTTONDOWN: { POINT point; point.x = LOWORD( lParam ); point.y = HIWORD( lParam ); ClientToScreen( hText, & point ); TrackPopupMenu( GetSubMenu( hMenu, 1 ), 0, point.x, point.y, 0, hText, NULL ); } default: return WindowProcedure( hwnd, message, wParam, lParam ); } return WindowProcedure( hwnd, message, wParam, lParam ); }
I problem jest taki, że gdy próbuję to skompilować, to mój kochany Dev-C++ twierdzi, że NowyProcesFunkcja nie jest w zasięgu WinMain, a dokładniej miejsca edit2.lpfnWndProc = NowyProcesFunkcja;, w którym to chcę przypisać klasie "edit2" obsługującą ją funkcję "NowyProcesFunkcja"... Proszę o pomoc, nie mam pojęcia dlaczego tak się dzieje. Pozdrawiam @edit Dorzucam log próby kompilacji E:\C++\Programy\WinBasket\main.cpp In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': 62 E:\C++\Programy\WinBasket\main.cpp `NowyProcesFunkcja' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.) E:\C++\Programy\WinBasket\main.cpp In function `LRESULT NowyProcesFunkcja(HWND__*, UINT, WPARAM, LPARAM)': 130 E:\C++\Programy\WinBasket\main.cpp `LRESULT NowyProcesFunkcja(HWND__*, UINT, WPARAM, LPARAM)' used prior to declaration E:\C++\Programy\WinBasket\Makefile.win [Build Error] [main.o] Error 1 |