waldiw Temat założony przez niniejszego użytkownika |
[c++][winapi]Jak wywołać MessageBox z pliku z funkcjami? » 2011-04-20 11:46:13 Mam projekt składający się z plików:
plik Main.cpp
#include <windows.h> #include <commctrl.h> #include "klasy_funkcje.hpp" using namespace std;
HWND hEdit, hEdit2, hButton, hStatic1, hStatic2, hWnd; CHAR szClassName[] = "OknoRodzica"; HINSTANCE * hInst;
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lStart, INT nShow ) { hInst =& hInstance; WNDCLASSEX wc; wc.hInstance =* hInst; wc.lpszClassName = szClassName; wc.lpfnWndProc = WndProc; wc.style = 0; wc.cbSize = sizeof( WNDCLASSEX ); wc.hIcon = LoadIcon( 0, IDI_APPLICATION ); wc.hIconSm = LoadIcon( 0, IDI_APPLICATION ); wc.hCursor = LoadCursor( 0, IDC_ARROW ); wc.lpszMenuName = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground =( HBRUSH ) COLOR_BACKGROUND; if( !RegisterClassEx( & wc ) ) return 0; hWnd = CreateWindowEx( 0, szClassName, "Test", WS_OVERLAPPEDWINDOW, 20, 20, 600, 300, 0, 0, * hInst, 0 ); ShowWindow( hWnd, nShow ); MSG msgs; while( GetMessage( & msgs, 0, 0, 0 ) ) { TranslateMessage( & msgs ); DispatchMessage( & msgs ); } return msgs.wParam; }
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wPar, LPARAM lPar ) { switch( msg ) { case WM_CREATE: hButton = CreateWindowEx( 0, WC_BUTTON, "Przycisk", WS_CHILD | WS_VISIBLE, 10, 10, 170, 40, hwnd,( HMENU ) 1, * hInst, 0 ); break; case WM_COMMAND: if( wPar == 1 ) { wypelnij(); } break; case WM_DESTROY: DestroyWindow( hButton ); PostQuitMessage( 0 ); break; default: return DefWindowProc( hwnd, msg, wPar, lPar ); } return 0; }
Plik klasy_funkcje.hpp
#include <windows.h> #include <commctrl.h> #ifndef klasy_funkcje_hpp #define klasy_funkcje_hpp
void wypelnij(); #endif
i plik kalsy_funkcje.cpp
#include "klasy_funkcje.hpp" #include <windows.h> #include <commctrl.h>
using namespace std;
void wypelnij() { MessageBox( hwnd, "Nacisnąłeś przycisk!", "Info", MB_ICONINFORMATION ); }
Co i gdzie w kodzie muszę dodać, aby wyświetlić MessageBox? Przy obecnym układzie otrzymuję z kompilatora Dev-C++ następujący błąd:
klasy_funkcje.cpp `hwnd' undeclared (first use this function)
Wstawiając MessageBox bezpośrednio w obsługę przycisku zamiast w funkcję wszysto działą.
Z góry dzięki za odpowiedź. |