Hallo ich hab folgende Probleme:
1. in der GUI-Proc kommt es nichts bis MessageBox 1 (ins if)
2. Wenn ich gui[0] angebe klappt es, aber Windows sagt keine Rückmeldung, aber die proc wird ja aufgerufen!?
Wär schön wenn ihr mir helfen könnt, danke.
Spoiler anzeigen
Code
#include <windows.h>
class GUI
{
public:
HWND hwnd;
UINT msg; //Last Message
WPARAM wparam; //"
LPARAM lparam; //"
};
//Global
WNDCLASSEX wincl;
char clname[]="TheShadowAE's GUI-UDF";
int guis=0;
GUI *gui[50];
bool msgloop=true;
HANDLE thread;
//Functions
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
//official
void GUIStartup();
void GUIShutdown();
GUI* GUICreate(char* title="",int w=300,int h=200,int style=WS_OVERLAPPEDWINDOW,int exstyle=0,HWND parent=HWND_DESKTOP,int posx=CW_USEDEFAULT,int posy=CW_USEDEFAULT);
//inofficial
DWORD WINAPI _Handler(LPVOID);
GUI* GUICreate(char* title,int w,int h,int style,int exstyle,HWND parent,int posx,int posy)
{
GUI *ngui;
guis+=1;
if (guis>50)
{
guis=50;
MessageBox(0,"Nicht mehr als 50 GUIs erlaubt!","Achtung!",MB_OK|MB_ICONERROR);
}
for (int x=0; x<guis; x++) if (gui[x]->hwnd==NULL) {ngui=gui[x]; break;};
ngui->hwnd = CreateWindowEx (
exstyle, /* Extended possibilites for variation */
clname, /* Classname */
title, /* Title Text */
style, /* default window */
posx, /* Windows decides the position */
posy, /* where the window ends up on the screen */
w, /* The programs width */
h, /* and height in pixels */
parent, /* The window is a child-window to desktop */
NULL, /* No menu */
NULL, /* Program Instance handler */
NULL /* No Window Creation data */
);
return ngui;
}
void GUIStartup()
{//NULL_BRUSH, GRAY_BRUSH, GetStockObject, CreateSolidBrush(RGB(,,))
for(int x=0; x<50; x++)
{
static GUI *ngui=new GUI();
gui[x]=ngui;
}
wincl.hInstance = NULL;//?
wincl.lpszClassName = clname;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;//catch Doubleclicks
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;//no menu
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
RegisterClassEx(&wincl);
thread=CreateThread(NULL,0,_Handler,NULL,0,NULL);
}
void GUIShutdown()
{
for(int x=0; x<50; x++)
{
PostMessage(gui[x]->hwnd,WM_DESTROY,0,0);
delete gui[x];
}
msgloop=false;
WaitForSingleObject(thread,5000);
SuspendThread(thread);
TerminateThread(thread,1);
CloseHandle(thread);
}
DWORD WINAPI _Handler(LPVOID muell)
{
MSG messages;
while(msgloop)
{
if(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
return 0;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
GUI *ngui;
for (int x=0; x<guis; x++)
{
if(gui[x]->hwnd==hwnd)
{
ngui=gui[x];
MessageBox(0,"1","",0);
break;
}
MessageBox(0,"2","",0);
}
MessageBox(0,"3","",0);
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
guis-=1;
ngui->hwnd=NULL;
break;
default:
ngui->lparam=lParam;
ngui->wparam=wParam;
ngui->msg=message;
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
int main()
{
GUIStartup();
GUI *g=GUICreate();
ShowWindow(g->hwnd,1);
while(g->msg!=WM_QUIT) Sleep(10);
GUIShutdown();
}
Alles anzeigen