hi..
I am developing an application that runs in the system tray and waits for the connection to server.when connected to server,it will open a directx application screen and display images received from server.When esc is pressed,directx screen has to be closed and application needs to sit back again in the system tray.When we right-click on tray icon pop-ups the exit button which will exit the application,
I was able to create system-tray with pop-up menu.But i am not able to make the tray-icon waiting for connection and opening the Directx screen,please help me in figuring out my problem.
Here is my code:
int APIENTRY WinMain(HINSTANCEhInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
SOCKET Socket;
sockaddr_in local;
long int num=0;
bool st=false;
int in_x=0;
int in_y=0;
int colors;
t = 0;
DWORD dwcolor=0;
dumpnpump transport;
WSADATA WsaDat;
int e;
{
//creating the tray icon with a popuup menu
LoadString(hInstance, IDC_TASKBARDEMO, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);// Perform application initialization
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TASKBARDEMO);
while(GetMessage(&msg,NULL, 0, 0))
{
if(!TranslateAccelerator(msg.hwnd, hAccelTable,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}return msg.wParam;
// Code begins here for accepting connection with server
if(WSAStartup(MAKEWORD(1, 1),&WsaDat)!= 0)
{
return(WSAGetLastError());
}else
{
}
Socket = socket(AF_INET, SOCK_STREAM,0);
if(Socket == INVALID_SOCKET)
{
// MessageBox(NULL, "Socket creation Failed!", "Error!", // MB_ICONEXCLAMATION | MB_OK); return(WSAGetLastError());
}
local.sin_family=AF_INET; //Address family local.sin_port=htons((u_short)20248); //port to use local.sin_addr.S_un.S_addr = INADDR_ANY;
if(bind(Socket,(sockaddr*)&local,sizeof(local))== SOCKET_ERROR)
{
//MessageBox(NULL, "Attempt to bind Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return WSAGetLastError();
}else
{
}
//We're only going to accept 1 incoming // connection.listen(Socket, 1);// We are still carrying through the Socket variable from before
SOCKET TempSock = SOCKET_ERROR;
while (TempSock == SOCKET_ERROR)
{
TempSock = accept(Socket, NULL, NULL);
}
Socket = TempSock;
MessageBox(NULL, "connectionsuccess ", "success!",MB_ICONEXCLAMATION | MB_OK);
//connection successful,so receive x and y resolution from server
XScreenDim=recieveIt(Socket);//Receive X-resolution
YScreenDim=recieveIt(Socket); //Receive Y-resolution
pixels=(XScreenDim)*(YScreenDim);
//Creating another window for Displaying images using Directx
WNDCLASSEX wc =(sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL,"NetMon Client", NULL};
RegisterClassEx(&wc);//Create the application's window
HWND hWnd1 = CreateWindow("NetMon Client", "NetMon Client 0.1b",WS__OVERLAPPEDWINDOW, 50, 50, XScreenDim, YScreenDim, GetDesktopWindow(), NULL,NULL, NULL);
//Initialize Direct3D
if(SUCCEEDED(InitialiseD3D(hWnd1))){ //Show our window
ShowWindow(hWnd1, SW_SHOWDEFAULT);
UpdateWindow(hWnd1);
//loop(flipping) begins here
MSG msg;
BOOL fMessage;
PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
//rendering process starts here
if(g_pD3DDevice == NULL)
{
cout << "Device NULL Error";
return 0;
}
//Clear the backbuffer to a white color
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0);
while (msg.message != WM_QUIT)
{
fMessage = PeekMessage(&msg, NULL, 0U, 0U, VE);
if(fMessage)
{
//Process message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Gets the x-coordinate of the incoming block in_x=transport.getIt(Socket);
if (in_x != 999)
{
while (in_x > 1000 || in_x < 0)
{
in_x = transport.getIt(Socket);
}
//cout<<"x: "<<in_x; //Gets the y-coordinate of the incoming block
in_y=transport.getIt(Socket);
//while (in_y > 1000 || in_x < 0)
{
in_y = transport.getIt(Socket);
} //cout<<" y: "<<in_y<<"\n";
g_pD3DDevice->BeginScene();
for (int n=0; n<64; n++)
{
colors = transport.getIt(Socket);//Gets the pixel color
// cout<<"colors value is"<<colors<<"\n"; DrawPixel2D((in_x*8 + n/8),(in_y*8 + n%8),(DWORD)RGB(GetBValue(colors), GetGValue(colors), GetRValue(colors)));
num++;
}
g_pD3DDevice>EndScene);
//the back and front buffers so that whatever has been rendered on the back buffer //will now be visible on screen (front buffer).
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
else
{
msg.message = WM_QUIT;
}
}
}
else
{
// cout << "Failed InitD3D" << endl;
}
sendIt(100,Socket,0);
CleanUp();
UnregisterClass("NetMon Client", wc.hInstance);
return TRUE;
}
// // Function call for creating the tray icon
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in ourglobal variable
hWnd = CreateWindow(szWindowClass, szTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
if (!TrayIcon.Create(hInstance, hWnd, // Parent window WM_ICON_NOTIFY, // Icon notify message to use _T("I am Client - Right click on me if u want to exit from the program"), // tooltip::LoadIcon(hInstance, (LPCTSTR)IDI_TASKBARDEMO), IDR_POPUP_MENU))
return FALSE;
ShowWindow(hWnd,SW_HIDE);
UpdateWindow(hWnd);
return TRUE;
}
I am developing an application that runs in the system tray and waits for the connection to server.when connected to server,it will open a directx application screen and display images received from server.When esc is pressed,directx screen has to be closed and application needs to sit back again in the system tray.When we right-click on tray icon pop-ups the exit button which will exit the application,
I was able to create system-tray with pop-up menu.But i am not able to make the tray-icon waiting for connection and opening the Directx screen,please help me in figuring out my problem.
Here is my code:
int APIENTRY WinMain(HINSTANCEhInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
SOCKET Socket;
sockaddr_in local;
long int num=0;
bool st=false;
int in_x=0;
int in_y=0;
int colors;
t = 0;
DWORD dwcolor=0;
dumpnpump transport;
WSADATA WsaDat;
int e;
{
//creating the tray icon with a popuup menu
LoadString(hInstance, IDC_TASKBARDEMO, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);// Perform application initialization
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TASKBARDEMO);
while(GetMessage(&msg,NULL, 0, 0))
{
if(!TranslateAccelerator(msg.hwnd, hAccelTable,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}return msg.wParam;
// Code begins here for accepting connection with server
if(WSAStartup(MAKEWORD(1, 1),&WsaDat)!= 0)
{
return(WSAGetLastError());
}else
{
}
Socket = socket(AF_INET, SOCK_STREAM,0);
if(Socket == INVALID_SOCKET)
{
// MessageBox(NULL, "Socket creation Failed!", "Error!", // MB_ICONEXCLAMATION | MB_OK); return(WSAGetLastError());
}
local.sin_family=AF_INET; //Address family local.sin_port=htons((u_short)20248); //port to use local.sin_addr.S_un.S_addr = INADDR_ANY;
if(bind(Socket,(sockaddr*)&local,sizeof(local))== SOCKET_ERROR)
{
//MessageBox(NULL, "Attempt to bind Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return WSAGetLastError();
}else
{
}
//We're only going to accept 1 incoming // connection.listen(Socket, 1);// We are still carrying through the Socket variable from before
SOCKET TempSock = SOCKET_ERROR;
while (TempSock == SOCKET_ERROR)
{
TempSock = accept(Socket, NULL, NULL);
}
Socket = TempSock;
MessageBox(NULL, "connectionsuccess ", "success!",MB_ICONEXCLAMATION | MB_OK);
//connection successful,so receive x and y resolution from server
XScreenDim=recieveIt(Socket);//Receive X-resolution
YScreenDim=recieveIt(Socket); //Receive Y-resolution
pixels=(XScreenDim)*(YScreenDim);
//Creating another window for Displaying images using Directx
WNDCLASSEX wc =(sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL,"NetMon Client", NULL};
RegisterClassEx(&wc);//Create the application's window
HWND hWnd1 = CreateWindow("NetMon Client", "NetMon Client 0.1b",WS__OVERLAPPEDWINDOW, 50, 50, XScreenDim, YScreenDim, GetDesktopWindow(), NULL,NULL, NULL);
//Initialize Direct3D
if(SUCCEEDED(InitialiseD3D(hWnd1))){ //Show our window
ShowWindow(hWnd1, SW_SHOWDEFAULT);
UpdateWindow(hWnd1);
//loop(flipping) begins here
MSG msg;
BOOL fMessage;
PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
//rendering process starts here
if(g_pD3DDevice == NULL)
{
cout << "Device NULL Error";
return 0;
}
//Clear the backbuffer to a white color
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0);
while (msg.message != WM_QUIT)
{
fMessage = PeekMessage(&msg, NULL, 0U, 0U, VE);
if(fMessage)
{
//Process message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Gets the x-coordinate of the incoming block in_x=transport.getIt(Socket);
if (in_x != 999)
{
while (in_x > 1000 || in_x < 0)
{
in_x = transport.getIt(Socket);
}
//cout<<"x: "<<in_x; //Gets the y-coordinate of the incoming block
in_y=transport.getIt(Socket);
//while (in_y > 1000 || in_x < 0)
{
in_y = transport.getIt(Socket);
} //cout<<" y: "<<in_y<<"\n";
g_pD3DDevice->BeginScene();
for (int n=0; n<64; n++)
{
colors = transport.getIt(Socket);//Gets the pixel color
// cout<<"colors value is"<<colors<<"\n"; DrawPixel2D((in_x*8 + n/8),(in_y*8 + n%8),(DWORD)RGB(GetBValue(colors), GetGValue(colors), GetRValue(colors)));
num++;
}
g_pD3DDevice>EndScene);
//the back and front buffers so that whatever has been rendered on the back buffer //will now be visible on screen (front buffer).
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
else
{
msg.message = WM_QUIT;
}
}
}
else
{
// cout << "Failed InitD3D" << endl;
}
sendIt(100,Socket,0);
CleanUp();
UnregisterClass("NetMon Client", wc.hInstance);
return TRUE;
}
// // Function call for creating the tray icon
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in ourglobal variable
hWnd = CreateWindow(szWindowClass, szTitle,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
if (!TrayIcon.Create(hInstance, hWnd, // Parent window WM_ICON_NOTIFY, // Icon notify message to use _T("I am Client - Right click on me if u want to exit from the program"), // tooltip::LoadIcon(hInstance, (LPCTSTR)IDI_TASKBARDEMO), IDR_POPUP_MENU))
return FALSE;
ShowWindow(hWnd,SW_HIDE);
UpdateWindow(hWnd);
return TRUE;
}