>.< ........ed about second window coming up first, my code may be horribly wrong

This is a discussion on >.< ........ed about second window coming up first, my code may be horribly wrong within the C++ Programming forums, part of the General Programming Boards category; This code may be extreamly inefficient and/or VERY POOR coding, because I don't know what to do :'( and like ...

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

    >.< ........ed about second window coming up first, my code may be horribly wrong

    This code may be extreamly inefficient and/or VERY POOR coding, because I don't know what to do :'( and like I want a Main window to come up and then a selection, button inputs that selection then a second window comes up and then a combobox and button (combobox to choose the drive) and then hit the button to input the selection, and then that selection is carried out... (NOTE: The 1==0 and 1==1 is just so it can run for now... yes... ghetto) SO any help?
    Code:
    #define WIN32_LEAN_AND_MEAN
    #include "..\Header\GUI.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[]="SecuritySuite";
    
    	wincl.cbClsExtra=0;
    	wincl.cbWndExtra=0;
    	wincl.style=CS_HREDRAW|CS_VREDRAW|BN_CLICKED;
    	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,"Error while registering window","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,"Error while creating window","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)
    {
    HINSTANCE g_hInst;
    HINSTANCE hInstance;
    //g_hInst=hInstance;
    	HDC hdc;
    	PAINTSTRUCT ps;
    	TCHAR chTxt[32];
    	HWND hButton1,hButton2,hCombo,hDrives,hNewWindow;
    	LPSTR Greeting,Question,Drive,Option,ChooseDrive;
    	Drive="Drive:";
    	Option="Option:";
    	Greeting="Welcome to C.J.'s SecuritySuite!";
    	Question="Please select what you want to do.";
    	ChooseDrive="Please choose drive.";
    
    	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,0,(LPARAM)chTxt);
    				lstrcpy(chTxt,"Secure Disk Cleanse");
    				SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)chTxt);
    			hButton1=CreateWindowEx(NULL,"Button","Submit",
    				WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    				250,120,60,25,hwnd,NULL,g_hInst,NULL);
    				/*Now to make a conditional in I guess another switch? ugh.*/
    				if(1==0/*Nothing is selected*/)
    				{
    					MessageBox(0,"Nothing is selected","Error",MB_ICONSTOP|MB_OK);
    					return 0;
    				}
    				if(1==0/*Button gets pressed and Secure Disk Wipe is seleted*/)
    				{
    					MessageBox(0,"Sorry, I didn't finish this yet :-p","SORRY!",
    					MB_ICONSTOP|MB_OK);
    					return 0;
    				}
    				if(1==1/*Button gets pressed and Secure Disk Cleanse is seleted*/)
    				{
    					TCHAR SecondchClassName[]="SecuritySuite2";
    					hNewWindow=CreateWindowEx(NULL,SecondchClassName,"Select Drive",
    						WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
    						330,240,HWND_DESKTOP,NULL,
    						hInstance,NULL);
    						hDrives=CreateWindowEx(NULL,"COMBOBOX","Drives",
    						WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
    						60,120,180,100,hNewWindow,NULL,g_hInst,NULL);
    						lstrcpy(chTxt,"A:\\");
    						SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)chTxt);
    						lstrcpy(chTxt,"C:\\");
    						SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)chTxt);
    						lstrcpy(chTxt,"D:\\");
    						SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)chTxt);
    					hButton2=CreateWindowEx(NULL,"Button","Submit",
    						WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    						250,120,60,25,hNewWindow,NULL,g_hInst,NULL);
    						std::string DriveChoice,File;
    						/* I HAVE TO FIGURE OUT HOW TO GET A LIST OF THE DRIVES USED
    						AND THEN PUT THEM IN THE COMBOBOX
    						AND THEN GET THE SELECTED ONE INTO A STRING NAMED DISKCHOICE
    						AND SUBMIT IT TO A STRING...UNDER THIS IS JUST TO GET THE
    						PROGRAM TO RUN*/
    						DriveChoice="C:\\"; /*Just to troubleshoot...
    
    						JUST TO GET IT TO RUN*/
    						File=DriveChoice+"SecureDiskCleanse.txt";
    									/*CHECKS TO SEE IF THE FILE EXISTS*/
    
    
    					if(1==0/*The file exists*/)
    					{
    						/*Ask if you want to start from where you left off*/
    						if(1==0/*The answer is yes*/)
    						{
    							RestartMainFunction(DriveChoice,File);
    							CleanseFinish();
    							return 0;
    						}
    						if(1==0/*The answer is no*/)
    						{
    							NoRestartMainFunction(DriveChoice,File);
    							CleanseFinish();
    							return 0;
    						}
    					}
    					else
    					{
    						MainFunction(DriveChoice,File);
    						MessageBox(0,"Cleanse complete","Finished",MB_ICONSTOP|MB_OK);
    						return 0;
    					}
    				}
    				if(1==0/*Button gets pressed and Secure File Deletion is seleted*/)
    				{
    					/*CODE HERE*/
    				}
    			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
    Aug 2005
    Posts
    1,267
    Here is a tutorial that may help you.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Thanks, I am going to go through that now

  4. #4
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Why why why are you using the WIN32 API?

    First, it's about as platform dependant as you can get.
    Second, it's a C interface, not a C++ interface.
    Third, even as C interfaces go, it's one of the ugliest.

    There are several nice OO GUI libraries out there. You could use wxwidgets or QT. Hell even MFC will protect you from some of the evil of the win32 api.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Yeah yeah I know, but the program itself is only able to be run on windows due to using system() and stuff

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 01:03 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

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