Code:
//UserInterface.h
#include "Main.h"
struct UserInterface_str
{
char * szClassName;
char * chTitle;
};
UserInterface_str * CreateUserInterface(char * szClassName, char * chTitle)
{
UserInterface_str * strUserInterface;
strUserInterface = new UserInterface_str;
strUserInterface->szClassName = new char[strlen(szClassName)];
strcpy(strUserInterface->szClassName, szClassName);
strUserInterface->chTitle = new char[strlen(chTitle)];
strcpy(strUserInterface->chTitle, chTitle);
return strUserInterface;
}
class UserInterface_c;
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
unsigned __stdcall UserInterfaceThread_1(void* pArg );
unsigned __stdcall UserInterfaceThread_2(void* pArg );
class UserInterface_c
{ protected:
InputQueue_c InputQueue;
HANDLE hThread_1, hThread_2;
unsigned ThreadID_1, ThreadID_2;
public:
HANDLE mInput;
char * szClassName;
char * chTitle;
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
HINSTANCE hInstance;
HWND hwndReceiveEditBox;
UserInterface_c()
{
chTitle=new char[7];
szClassName=new char[11];
strcpy(chTitle,"Default");
strcpy(szClassName,"WindowsApp");
hInstance = (HINSTANCE)GetModuleHandle(NULL);
}
~UserInterface_c() {}
void Input(Data_str* strData)
{
InputQueue.Input(strData);
}
void Start(void * pArg)
{
UserInterface_str * strUserInterface = (UserInterface_str *) pArg;
if(strUserInterface != NULL)
{
delete(chTitle);
chTitle = new char [strlen(strUserInterface->chTitle)];
strcpy(chTitle, strUserInterface->chTitle);
delete(szClassName);
szClassName = new char [strlen(strUserInterface->szClassName)];
strcpy(szClassName, strUserInterface->szClassName);
}
hThread_1 =(HANDLE) _beginthreadex(NULL,0, &UserInterfaceThread_1, (LPVOID) this, 0, &ThreadID_1);
hThread_2 =(HANDLE) _beginthreadex(NULL,0, &UserInterfaceThread_2, (LPVOID) this, 0, &ThreadID_2);
}
};
unsigned __stdcall UserInterfaceThread_1(void* pArg )
{
UserInterface_c * pUserInterface = reinterpret_cast<UserInterface_c *>(pArg);
/* The Window structure */
pUserInterface->wincl.hInstance = pUserInterface->hInstance;
pUserInterface->wincl.lpszClassName = pUserInterface->szClassName;
pUserInterface->wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
pUserInterface->wincl.style = CS_DBLCLKS; /* Catch double-clicks */
pUserInterface->wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
pUserInterface->wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
pUserInterface->wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
pUserInterface->wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
pUserInterface->wincl.lpszMenuName = NULL; /* No menu */
pUserInterface->wincl.cbClsExtra = 0; /* No extra bytes after the window class */
pUserInterface->wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
pUserInterface->wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if ( !RegisterClassEx (&pUserInterface->wincl) ) cout<<"Failed";
pUserInterface->hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
pUserInterface->szClassName, /* Classname */
pUserInterface->chTitle, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
pUserInterface->hInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
ShowWindow (pUserInterface->hwnd, 1);
DWORD dwReceiveMessage;
HANDLE hReceiveMessage;
while (GetMessage (&pUserInterface->messages, NULL, 0, 0))
{
TranslateMessage(&pUserInterface->messages);
DispatchMessage(&pUserInterface->messages);
}
return 0;
}
unsigned __stdcall UserInterfaceThread_2(void* pArg )
{
UserInterface_c * pUserInterface = reinterpret_cast<UserInterface_c *>(pArg);
return 0;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
//hwndReceiveEditBox=NULL;
/* hwndReceiveEditBox = CreateWindow( "edit",
"",
WS_VISIBLE|WS_CHILD|WS_BORDER|WS_VSCROLL|ES_READONLY|ES_MULTILINE|ES_WANTRETURN|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
0,
0, xReceiveEditBox,
yReceiveEditBox,
hwnd,
(HMENU)2,
((LPCREATESTRUCT) lParam)->hInstance,
NULL);
ReleaseDC (hwnd, hdc); */
}
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
int main()
{
UserInterface_c cModuleUserInterface;
cModuleUserInterface.Start(CreateUserInterface("UserInterface","UserInterface 1"));
cin.get();
return 0;
}