how to pass the arguments to procedure to close the window

Discussion in 'Win32' started by vidhya, May 30, 2007.

  1. vidhya

    vidhya New Member

    Joined:
    May 17, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    hi,this is part of my code.in this code when i execute the code first time it will create one borderless window in which the command line arguments will scroll.when i execute the same code second time in presence of the previous banner running it should close the previous banner and open the new window and the arguments whatever i pass will scroll in that newly created banner.
    i want single instance of banner. i also want to know how to pass the arguments to procedure.

    part of code:

    Code:
    using std::string;
    
    using namespace std;
    
    WNDCLASSEX  WndCls;
    
    HWND hwnd;
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
     
    CString string1,string2="",string3="";
    
    string pre_lines="";
    
    
    
    
    LPWSTR *szArglist;		//holds commandline arguments
       int nArgs;
       int i,j,k,l;
      
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow)
    {
    //string1.Format("%-0s",lpCmdLine);
    
        static char szAppName[] = "GDISuite";
        MSG         Msg;
    
        WndCls.cbSize        = sizeof(WndCls);
        WndCls.style         = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
        WndCls.lpfnWndProc   = WindProcedure;
        WndCls.cbClsExtra    = 0;
        WndCls.cbWndExtra    = 0;
        WndCls.hInstance     = hInstance;
        WndCls.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndCls.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        WndCls.lpszMenuName  = NULL;
        WndCls.lpszClassName = szAppName;
        WndCls.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
        RegisterClassEx(&WndCls);
    
    
    	//creates window
    
        CreateWindowEx(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST,
                              szAppName,
                              "GDI Accessories and Tools",
                              WS_POPUPWINDOW | WS_VISIBLE,
                              0,
                              0,
                              1500,
                              50,
    		NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        while( GetMessage(&Msg, NULL, 0, 0) )
        {
            TranslateMessage(&Msg);
            DispatchMessage( &Msg);
        }
    
        return static_cast<int>(Msg.wParam);
    }
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
    	HDC hDC;
             PAINTSTRUCT Ps;
    		 int a;
    
    	switch(Msg)
    	{
    	
    	case WM_PAINT:
    
    		szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
    
    		if( NULL == szArglist )
    		{
    			wprintf(L"CommandLineToArgvW failed\n");
    			return 0;
    		}
    
    		if( (CString)szArglist[1]=="a")
    		{
    	
    		/*if(FindWindow("szAppName","GDI Accessories and Tools")!=NULL)
    		{
    			DestroyWindow(hWnd);
    		}*/
    			
    			ifstream myfile7;
    
    			myfile7.open  ("C:\\cmd.txt"); 
    
    			//sText="EOD has not been started yet";
    
    			if(myfile7.is_open())
    
    			{
    
    		while (! myfile7.eof() )
    
    		{
    
    		       string pline="";
    
    		      getline (myfile7,pline);
    
    		       pre_lines+=(pline+"\n"); 
    
    						
    	            }
    
    	}
    
    			myfile7.close();
    
    			for( i=2; i<nArgs; i++)
    				{ 
    					string1=(CString)szArglist[i];
    
    					string2=string2+" "+string1;
    				}
    
    
    			CString str=pre_lines.c_str();
    			string3=str+" "+string2;
    
    			ofstream myfile4; 
    
    					myfile4.open("C:\\cmd.txt");
    
    					if (myfile4.is_open())
    
    					{
    
    
    				myfile4 << pre_lines << string(string2);
    
    					}
    
    					myfile4.close();
    
    			
    			do
    				{
    			hDC = BeginPaint(hWnd, &Ps);
    			TextOut(hDC, 10, 1,"Priority 1 Issues:",20);
    
    			for(a=1;a<1100;a++)
    			{
    					
    		TextOut(hDC, a+10, 18,string2,string2.GetLength());
    		EndPaint(hWnd, &Ps);
    		Sleep(10);
    						
    			}
    					
    		}while(!_kbhit());
    
    		}	
    
    		else if( (CString)szArglist[1]=="r")
    		{
    			ifstream myfile7;
    
    			myfile7.open  ("C:\\cmd.txt"); 
    
    			//sText="EOD has not been started yet";
    
    			if(myfile7.is_open())
    
    			{
    
    			while (! myfile7.eof() )
    
    			{
    
    			string pline="";
    
    			getline (myfile7,pline);
    
    			pre_lines+=(pline+"\n"); 						
    		}
    
    			}
    
    			myfile7.close();
    			
    				CString str1=pre_lines.c_str();
    
    			for( i=2; i<nArgs; i++)
    				{ 
    					string1=(CString)szArglist[i];
    					string2=string2+string1;
    					//char s[]=(string)str1;
    					//j=InStr(string1,str1)-1;
    					k = string2.GetLength();
    					j=str1.Find(string2);
    					if (j<k)
    					{
    
    					for(l=j ;l<k+1;l++)
    		
    					str1.SetAt(j,' ');
    					if(j!=0)
    					{
    								                                                      string1="";
    					}
    					string2=string1;
    					}
    					else if(j>k)
    					{
    						for(l=j ;l<j+k+1;l++)
    						str1.SetAt(l,' ');
    						if(j!=0)
    						{
    							string1="";
    						}
    						string2=string1;
    					}
    					else
    					{
    		AfxMessageBox("The entered String  do not match");
    					}
    		
    			}
    
    			CString str=pre_lines.c_str();
    			string3=str+" "+string2;
    
    			ofstream myfile4; 
    
    			myfile4.open("C:\\cmd.txt");
    
    		            if (myfile4.is_open())
    
    		          {
    
    
    		              //myfile4 << pre_lines << string(str1);
    			myfile4 << string(str1);
    
    		           }
    
    			myfile4.close();
    
    			
    			do
    				{
    				hDC = BeginPaint(hWnd, &Ps);
    			TextOut(hDC, 10, 1,"Priority 1 Issues:",20);
    
    			for(a=1;a<1100;a++)
    			{
    			TextOut(hDC, a+10, 18,str1,str1.GetLength());
    			EndPaint(hWnd, &Ps);
    			Sleep(10);	
    		             }	
    		}while(!_kbhit());
    
    		}
    
    
    		
    		else
    		{
    		 for( i=1; i<nArgs; i++)
    			{ 
    			string1=(CString)szArglist[i];
    			string2=string2+string1;
    			}
    
    			ofstream myfile4; 
    
    			myfile4.open("C:\\cmd.txt");
    
    			if (myfile4.is_open())
    
    			{
    
    
    			myfile4 << string(string2);
    
    			}
    
    			myfile4.close();
    					
    			do
    			{
    			hDC = BeginPaint(hWnd, &Ps);
    
    			for(a=1;a<1100;a++)
    			{
    		TextOut(hDC, a+10, 6,string2,string2.GetLength());
    				EndPaint(hWnd, &Ps);
    				Sleep(10);
    						
    			}
    					
    		}while(!_kbhit());
    			break;
    		}
    
    		case WM_DESTROY:
    		PostQuitMessage(WM_QUIT);
    		break;
    	default:
    		return DefWindowProc(hWnd, Msg, wParam, lParam);
    	}
    	return 0;
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice