How to combine a GUI with a program

This is a discussion on How to combine a GUI with a program within the C++ Programming forums, part of the General Programming Boards category; I am trying to combine my GUI(work in proccess) with my main program "SecSuite" GUI | | | V Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    How to combine a GUI with a program

    I am trying to combine my GUI(work in proccess) with my main program "SecSuite"
    GUI
    |
    |
    |
    V
    Code:
    #include "..\header\SecSuite.h"
    
    int main()
    {
    	std::string Dir,File,Option,Restart;
    	DisplayOptions();
    	getline(std::cin,Option,'\n');
    	if(Option=="SDW")
    	{
    		std::cout<<"Sorry,This option is not yet available."<<std::endl;
    	}
    	if(Option=="SDC")
    	{
    		std::string Dir=GetObject("DiskName");
    		if(Dir.length()!=3)
    		{
    			CheckLength(Dir);
    		}
    		File=Dir+"SecureDiskCleanse.txt";
    		bool FileExist=true;/*NEED TO WRITE THIS FUNCTION...*/
    		if(FileExist==true)
    		{
    			std::cout<<"Do you want to start where you left off?(Y or N):";
    			getline(std::cin,Restart,'\n');
    			if(Option=="Y"||"y")
    			{
    				RestartMainFunction(Dir,File);
    			}
    			else
    			{
    				NoRestartMainFunction(Dir,File);
    			}
    		}
            else
    		{
    			MainFunction(Dir,File);
    		}
    		Delete(File);
    		std::cout<<"Disk Cleansed."<<std::endl;
    		std::cin.get();
    	}
    	if(Option=="SFD")
    	{
    		int Loops,SizeOfFile,OrigSizeOfFile;
    		File=GetObject("File location");
    		OrigSizeOfFile=GetFileSize(File.c_str());
    		std::ofstream a_file(File.c_str(), std::ios::trunc);
    		Loops=GetFileSize(File.c_str());
    		while(Loops>0,Loops--)
    		{
    			a_file<<"1";
    		}
    		Delete(File);
    		std::cin.get();
    	}
    	else
    	{
    		std::cin.get();
    	}
    	return 0;
    }
    And then GUI
    |
    |
    |
    V
    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    HINSTANCE g_hInst;
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    					LPSTR lpCmdLine,int nCmdShow)
    {
    	MSG Msg;
    	HWND hwnd;
    	WNDCLASSEX wincl;
    	g_hInst=hInstance;
    	TCHAR chClassName[]=TEXT("SecuritySuite");
    
    	wincl.cbClsExtra=0;
    	wincl.cbWndExtra=0;
    	wincl.style=CS_HREDRAW|CS_VREDRAW;
    	wincl.lpszMenuName=NULL;
    	wincl.hInstance=hInstance;
    	wincl.lpszClassName=chClassName;
    	wincl.cbSize=sizeof(WNDCLASSEX);
    	wincl.lpfnWndProc=(WNDPROC)WndProc;
    	wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
    	wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    	wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    	wincl.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    
    	if(!RegisterClassEx(&wincl))
    	{
    		MessageBox(0,"Window Registration Failed!","Error!",MB_ICONSTOP|MB_OK);
    		return 0;
    	}
    	hwnd=CreateWindowEx(0,chClassName,"Security Suite",WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,CW_USEDEFAULT,330,240,HWND_DESKTOP,NULL,
    						hInstance,NULL);
    	if(hwnd==NULL)
    	{
    		MessageBox(0,"Window Creation Failed!","Error",MB_ICONSTOP|MB_OK);
    		return 0;
    	}
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    	while(GetMessage(&Msg,NULL,0,0))
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	HDC hdc;
    	PAINTSTRUCT ps;
    	TCHAR chTxt[32];
    	HWND hButton,hCombo;
    	LPSTR Greeting,Question,Option;
    	Option="Option:";
    	Greeting="Welcome to C.J.'s SecuritySuite!";
    	Question="Please select what you want to do.";
    
    	switch(msg)
    	{
    		case WM_CREATE:
    			hCombo=CreateWindowEx(NULL,"COMBOBOX","Options",
    				WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
    				60,120,180,100,hwnd,NULL,g_hInst,NULL);
    				lstrcpy(chTxt,"Secure Disk Wipe");
    				SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)chTxt);
    				lstrcpy(chTxt,"Secure File Deletion");
    				SendMessage(hCombo,CB_ADDSTRING,1,(LPARAM)chTxt);
    				lstrcpy(chTxt,"Secure Disk Cleanse");
    				SendMessage(hCombo,CB_ADDSTRING,2,(LPARAM)chTxt);
    			hButton=CreateWindowEx(NULL,"Button","Submit",
    				WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    				250,120,60,25,hwnd,NULL,g_hInst,NULL);
    			break;
    		case WM_PAINT:
    			hdc=BeginPaint(hwnd,&ps);
    			TextOut(hdc,53,20,Greeting,strlen(Greeting));
    			TextOut(hdc,49,40,Question,strlen(Question));
    			TextOut(hdc,10,120,Option,strlen(Option));
    			EndPaint(hwnd,&ps);
    			break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage (0);
    			break;
    		default:
    			return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,161
    If you want the GUI program to be able to execute your SecSuite program, then look up the CreateProcess() function in the win32 API. That allows one program to execute another.

    If you want your GUI program to have some selected capabilities of your SecSuite program, you will need to restructure your SecSuite program as a set of functions, and call them in appropriate places from within your GUI program (eg within the WndProc() function in response to particular messages)

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Quote Originally Posted by grumpy
    If you want the GUI program to be able to execute your SecSuite program, then look up the CreateProcess() function in the win32 API. That allows one program to execute another.

    If you want your GUI program to have some selected capabilities of your SecSuite program, you will need to restructure your SecSuite program as a set of functions, and call them in appropriate places from within your GUI program (eg within the WndProc() function in response to particular messages)
    Alright, thanks, yeah I was thinking that was how, so I made the header file and function source file and now I guess is to intigrate it that way, thanks.
    Now off to msdn.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  2. calling an external program from within a windows GUI
    By korbitz in forum Game Programming
    Replies: 1
    Last Post: 03-16-2004, 09:39 PM
  3. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 07:03 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21