problem bei eigenem GUI framework
-
Hi,
hab grad angefanden mein eigenes GUI framework zu basteln (zum Spass).
und ich hab das problem das wenn die BN_CLICK message kommt, weiß ich
nicht wie ich sie an die WinGUI_Button class die den button erzeigt hat
weiterleite.wer`s testen will, ein win32 projekt erstellen den ganzen template code
löschen und den main.cpp einfügen...
hier mal ein wenig code:main.cpp -------------------------------------------------------------
#include "WinGUI.h"
int WinGUI_Main(HINSTANCE hInstance, LPSTR lpArg) {
WinGUI_Window mywin;
mywin.Register(hInstance, "myClass");
mywin.Create("WinGUI Window", 100,100,600,600, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0);WinGUI_Button mybutton;
mybutton.Create(&mywin, "Test", 20,100,70,70, WS_CHILD|WS_VISIBLE,0);WinGUI_Button myradio;
myradio.Create(&mywin, "Radio", 100,100,70,70, WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON,0);WinGUI_Run();
return 0;
}WinGUI.h ----------------------------------------------------------------
#include <windows.h>
// WinGUI main function
int WinGUI_Main(HINSTANCE hInstance, LPSTR lpArg);
// start the application
int WinGUI_Run();// call the WinGUI_Main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WinGUI_Main(hInstance, lpCmdLine);
return 0;
}// main window class
class WinGUI_Window {
HINSTANCE hInstance;
char szClassName[2000];
HWND hwnd;public:
int WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK InitialWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);int Register(HINSTANCE, const char *);
int Create(const char *, int, int, int, int, DWORD, DWORD);HWND GetHwnd();
};int WinGUI_Window::WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {case WM_COMMAND: {
if(HIWORD(wParam)==BN_CLICKED) {
// was soll ich hier machen???
break;
}
break;break;
}case WM_CLOSE: {
DestroyWindow(hwnd);
break;
}case WM_DESTROY: {
PostQuitMessage(0);
break;
}default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}LRESULT CALLBACK WinGUI_Window::InitialWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
if (Msg == WM_NCCREATE) {
LPCREATESTRUCT create_struct = reinterpret_cast<LPCREATESTRUCT>(lParam);
void * lpCreateParam = create_struct->lpCreateParams;
WinGUI_Window * this_window = reinterpret_cast<WinGUI_Window *>(lpCreateParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this_window));
SetWindowLongPtr(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&WinGUI_Window::StaticWndProc));
return this_window->WndProc(hWnd, Msg, wParam, lParam);
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}LRESULT CALLBACK WinGUI_Window::StaticWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
LONG_PTR user_data = GetWindowLongPtr(hWnd, GWLP_USERDATA);
WinGUI_Window * this_window = reinterpret_cast<WinGUI_Window *>(user_data);
return this_window->WndProc(hWnd, Msg, wParam, lParam);
}int WinGUI_Window::Register(HINSTANCE hInst, const char *strClassName) {
hInstance=hInst;
wsprintf(szClassName,"%s",strClassName);WNDCLASSEX wc;
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = &WinGUI_Window::InitialWndProc;
wc.hInstance = GetModuleHandle(NULL);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = strClassName;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);if(!RegisterClassEx(&wc)) {
return 0;
}return 1;
}int WinGUI_Window::Create(const char *strTitle, int a, int b, int x, int y, DWORD iStyle, DWORD iExStyle) {
hwnd = CreateWindowEx(iExStyle,szClassName,strTitle,iStyle,
a, b, x, y, NULL,NULL,hInstance,NULL);if(hwnd == NULL) {
return 0;
}return 1;
}HWND WinGUI_Window::GetHwnd() {
return hwnd;
}// run the application
int WinGUI_Run() {
MSG Msg;while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}return 0;
}#include "WinGUI_Button.h"
WinGUI_Button.h -------------------------------------------------
class WinGUI_Button {
HWND hwnd;public:
int Create(WinGUI_Window *, const char *, int, int, int, int, DWORD, DWORD);
int SetText(const char *);
HWND GetHwnd();
int Show(BOOL);
int OnClicked();
};int WinGUI_Button::Create(WinGUI_Window *parent, const char *strTitle, int a, int b, int x, int y, DWORD iStyle, DWORD iExStyle) {
hwnd=parent->GetHwnd();
hwnd=CreateWindowEx(iExStyle,"button",strTitle,iStyle,a,b,x,y,hwnd,NULL,GetModuleHandle(NULL),NULL);if(hwnd==NULL) {
return 0;
}return 1;
}int WinGUI_Button::SetText(const char *strTitle) {
if(!SetWindowText(hwnd,strTitle)) {
return 0;
}return 1;
}HWND WinGUI_Button::GetHwnd() {
return hwnd;
}int WinGUI_Button::Show(BOOL show) {
if(show==TRUE)
if(!ShowWindow(hwnd,SW_SHOW))
return 0;
else
return 1;
else
if(!ShowWindow(hwnd,SW_HIDE))
return 0;
else
return 1;return 1;
}int WinGUI_Button::OnClicked() {
}