Thread: How to make a button send a message

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

    How to make a button send a message

    How can I make a button submit a selected option in a combobox? Preferbly to branch off in a if statement I would think
    Like the options are A B C
    If chosen A and clicked button it would branch to if(A) if B and clicked button it would branch to if(B) and so on and so fourth.
    Also, where would I put the code???
    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|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,"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;
    }
    Is my GUI

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Is this what you're looking for?

    Code:
    #define WIN32_LEAN_AND_MEAN
    #define ID_COMBOBOX 1
    #define ID_BUTTON 2
    
    #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|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,"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;
        INT index;
        TCHAR chTxt[32];
        static TCHAR chOutTxt[32];
        HWND hButton = NULL;
        static HWND hCombo = NULL;
        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_COMMAND:
                if(LOWORD (wParam)  == ID_COMBOBOX  && HIWORD(wParam) == CBN_SELCHANGE)
                {
                    index = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
                    if (index == CB_ERR)
                    {
                        return TRUE;
                    }
                    SendMessage(hCombo, CB_GETLBTEXT, index, (LPARAM) chOutTxt);
                }
                if(LOWORD (wParam)  == ID_BUTTON)
                {
                    MessageBox(NULL,chOutTxt,"Combo Box Selection",MB_OK);   
                // Put your branching if statements here
                // based on what chOutTxt contains
    	}
                return 0;
    
            case WM_CREATE:
                hCombo=CreateWindowEx(NULL,"COMBOBOX","Options",
                    WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
                    60,120,180,100,hwnd,(HMENU) ID_COMBOBOX,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,(HMENU) ID_BUTTON,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;
    }

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Thanks, now when you say"Put branching if statements here based on what chOutTxt contains" do you mean to put like if(chOutTxt=="Secure Disk Wipe")??? I'm sorry if that's a real stupid guess... well, not a guess but what I think I should do... I am really sorry for wasting your time, I am very grateful for your help.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Code:
     if(LOWORD (wParam)  == ID_BUTTON)
                {
                    if (strcmp(chOutTxt,"Secure Disk Wipe" ) == 0)   
                        MessageBox(NULL,"Secure Disk Wipe option was selected","Combo Box Selection",MB_OK);
                    else
                        if (strcmp(chOutTxt,"Secure File Deletion" ) == 0)
                            MessageBox(NULL,"Secure File Deletion option was selected","Combo Box Selection",MB_OK);
                        else    
                            if (strcmp(chOutTxt,"Secure Disk Cleanse" ) == 0)
                                MessageBox(NULL,"Secure Disk Cleanse option was selected","Combo Box Selection",MB_OK);
                }

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Oh, I did it by making a C++string called Selection and then doing
    Code:
    Selection=chOutTxt;
    if(Selection="Secure File Deletion")
    {
    }
    ect.ect.ect...
    I am just trying to figure out how to pop up anothe window when they become selected and then for Secure Disk Wipe or Secure Disk Cleanse, having it have a combobox for the drives and a button to submit it... and for Secure File Deletion a combo box for the drives then an input box for the filepath and a button to submit it...

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Code:
    #include <windows.h>
    
    #define ID_COMBOBOX 1
    #define ID_BUTTON 2
    #define ID_COMBOBOX1 3
    
    void InitApp(HINSTANCE);
    LRESULT APIENTRY MainProc(HWND,UINT,WPARAM,LPARAM);
    LRESULT APIENTRY SecondComboBoxProc(HWND,UINT,WPARAM,LPARAM);
    
    HWND main;
    HWND secondary;
    
    HINSTANCE g_hInst;
    
    int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR line,int CmdShow)
    {
        MSG msg;
        g_hInst = hInst;
        InitApp(hInst);
    
        while(GetMessage(&msg,0,0,0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return msg.wParam;
    }
    
    void InitApp(HINSTANCE hInst)
    {
        WNDCLASS wc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.hInstance = hInst;
        wc.hCursor = LoadCursor(NULL,IDC_ARROW);
        wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
        wc.lpfnWndProc = (WNDPROC) MainProc;
        wc.lpszClassName = "Main";
        wc.lpszMenuName = NULL;
        wc.style = CS_HREDRAW | CS_VREDRAW;
    
        RegisterClass(&wc);
    
        wc.lpszClassName = "Secondary";
        wc.lpfnWndProc = (WNDPROC) SecondComboBoxProc;
    
        RegisterClass(&wc);
    
        main = CreateWindow("Main","Security Suite",WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,330,240,0,0,hInst,0);
        secondary = CreateWindow("Secondary","Secure Disk Wipe",WS_OVERLAPPEDWINDOW,200,200,400,400,0,0,hInst,0);
        ShowWindow(main,SW_SHOW);
        UpdateWindow(main);
    }
    
    LRESULT APIENTRY MainProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        INT index;
        HWND hButton = NULL;
        HDC hdc;
        PAINTSTRUCT ps;
        TCHAR chTxt[32];
        static TCHAR chOutTxt[32];
        static HWND hCombo = NULL;
        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_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_DESTROY:
                PostQuitMessage(0);
                break;
            case WM_CREATE:
                {
                    hCombo=CreateWindowEx(NULL,"COMBOBOX","Options",
                        WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
                        60,120,180,100,hwnd,(HMENU) ID_COMBOBOX,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,(HMENU) ID_BUTTON,g_hInst,NULL);
                }
                break;
            case WM_COMMAND:
                if(LOWORD (wParam)  == ID_COMBOBOX  && HIWORD(wParam) == CBN_SELCHANGE)
                {
                    index = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
                    if (index == CB_ERR)
                    {
                        return TRUE;
                    }
                    SendMessage(hCombo, CB_GETLBTEXT, index, (LPARAM) chOutTxt);
                }
                if(LOWORD (wParam)  == ID_BUTTON)
                {
                    if (strcmp(chOutTxt,"Secure Disk Wipe" ) == 0)
                    { 
                        MessageBox(NULL,"Secure Disk Wipe option was selected","Combo Box Selection",MB_OK);
                        ShowWindow(hwnd,SW_HIDE);
                        ShowWindow(secondary,SW_SHOW);
                    }
                    else
                        if (strcmp(chOutTxt,"Secure File Deletion" ) == 0)
                            MessageBox(NULL,"Secure File Deletion option was selected","Combo Box Selection",MB_OK);
                        else    
                            if (strcmp(chOutTxt,"Secure Disk Cleanse" ) == 0)
                                MessageBox(NULL,"Secure Disk Cleanse option was selected","Combo Box Selection",MB_OK);
                }
                return 0;
            default:
                return DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return 0;
    }
    
    LRESULT APIENTRY SecondComboBoxProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        static TCHAR chOutTxt[32];
        INT index;
        HWND hButton = NULL;
        TCHAR chTxt[32];
        static HWND hCombo1 = NULL;
        HDC hdc;
        PAINTSTRUCT ps;
        LPSTR Greeting,Question,Option;
        Option="Option:";
        Greeting="Secure Disk Wipe ";
        Question="Please select what you want to do.";
        switch(msg)
        {
            case WM_CREATE:
                hCombo1=CreateWindowEx(0,"COMBOBOX","Secure Disk Wipe",
                    WS_CHILD|WS_VISIBLE | CBS_DROPDOWNLIST,
                    60,120,180,100,hwnd,(HMENU) ID_COMBOBOX1,g_hInst,NULL);
                lstrcpy(chTxt,"AAAA");
                SendMessage(hCombo1,CB_ADDSTRING,0,(LPARAM)chTxt);
                lstrcpy(chTxt,"BBBB");
                SendMessage(hCombo1,CB_ADDSTRING,1,(LPARAM)chTxt);
                lstrcpy(chTxt,"CCCC");
                SendMessage(hCombo1,CB_ADDSTRING,2,(LPARAM)chTxt);  
    
                hButton=CreateWindowEx(NULL,"Button","Submit",
                    WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                    250,120,60,25,hwnd,(HMENU) ID_BUTTON,g_hInst,NULL);
                break;
            case WM_COMMAND:
                if(LOWORD (wParam)  == ID_COMBOBOX1  && HIWORD(wParam) == CBN_SELCHANGE)
                {
                    index = SendMessage(hCombo1, CB_GETCURSEL, 0, 0);
                    if (index == CB_ERR)
                    {
                        return TRUE;
                    }
                    SendMessage(hCombo1, CB_GETLBTEXT, index, (LPARAM) chOutTxt);
                }
                if(LOWORD (wParam)  == ID_BUTTON)
                {
                    if (strcmp(chOutTxt,"AAAA" ) == 0)
                        MessageBox(NULL,"AAAA was selected","Combo Box Selection",MB_OK);
                    else
                        if (strcmp(chOutTxt,"BBBB" ) == 0)
                            MessageBox(NULL,"BBBB was selected","Combo Box Selection",MB_OK);
                        else    
                            if (strcmp(chOutTxt,"CCCC" ) == 0)
                                MessageBox(NULL,"CCCC was selected","Combo Box Selection",MB_OK);
                }
                return 0;
            case WM_CLOSE:
                ShowWindow(secondary,SW_HIDE);
                ShowWindow(main,SW_SHOW);
                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;
            default: return DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Damn, it has alot of bugs, but I believe I can work them out...
    Here's the code with the GUI mapped out pretty
    Code:
    #include <windows.h>
    #include "..\Header\SecSuite.h"
    #define ID_COMBOBOX1 1
    #define ID_BUTTON 2
    #define ID_COMBOBOX2 3
    #define ID_COMBOBOX3 4
    
    void InitApp(HINSTANCE);
    //The prototypes
    LRESULT APIENTRY MainProc(HWND,UINT,WPARAM,LPARAM);
    LRESULT APIENTRY SDW_Proc(HWND,UINT,WPARAM,LPARAM);
    LRESULT APIENTRY SDC_Proc(HWND,UINT,WPARAM,LPARAM);
    LRESULT APIENTRY SFD_Proc(HWND,UINT,WPARAM,LPARAM);
    //The window names
    HWND Main;
    HWND SDW;
    HWND SDC;
    HWND SFD;
    //Our main application handler, I believe
    HINSTANCE g_hInst;
    //The main proccess
    int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR line,int CmdShow)
    {
    	MSG msg;
    	g_hInst=hInst;
    	InitApp(hInst);
    	while(GetMessage(&msg,0,0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    //Define the window class
    void InitApp(HINSTANCE hInst)
    {
    	WNDCLASS WinCl;
    	WinCl.cbClsExtra=0;
    	WinCl.cbWndExtra=0;
    	WinCl.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    	WinCl.hInstance=hInst;
    	WinCl.hCursor=LoadCursor(NULL,IDC_ARROW);
    	WinCl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    	WinCl.lpfnWndProc=(WNDPROC)MainProc;
    	WinCl.lpszClassName="Main";
    	WinCl.lpszMenuName=NULL;
    	WinCl.style=CS_HREDRAW|CS_VREDRAW;
    	RegisterClass(&WinCl);
    	//Redefine for the SDW window
    	WinCl.lpszClassName="SDW";
    	WinCl.lpfnWndProc=(WNDPROC)SDW_Proc;
    	RegisterClass(&WinCl);
    	//Redefine for the SDC window
    	WinCl.lpszClassName="SDC";
    	WinCl.lpfnWndProc=(WNDPROC)SDC_Proc;
    	RegisterClass(&WinCl);
    	//Redefine for the SFD window
    	WinCl.lpszClassName="SFD";
    	WinCl.lpfnWndProc=(WNDPROC)SFD_Proc;
    	RegisterClass(&WinCl);
    	//The windows
    	Main=CreateWindow("Main","Security Suite",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,330,240,0,0,hInst,0);
    	SDW=CreateWindow("SDW","Secure Disk Wipe",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,330,240,0,0,hInst,0);
    	SDC=CreateWindow("SDC","Secure Disk Cleanse",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,330,240,0,0,hInst,0);
    	SFD=CreateWindow("SFD","Secure File Deletion",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,330,240,0,0,hInst,0);
    	//Shows the window
    	ShowWindow(Main,SW_SHOW);
    	UpdateWindow(Main);
    }
    //The main window Proccess
    LRESULT APIENTRY MainProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	INT index;
    	HWND hButton=NULL;
    	HDC hdc;
    	PAINTSTRUCT ps;
    	TCHAR chTxt[32];
    	static TCHAR chOutTxt[32];
    	static HWND hCombo=NULL;
    	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,(HMENU)ID_COMBOBOX1,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,(HMENU)ID_BUTTON,g_hInst,NULL);
    			}
    		break;
    		case WM_COMMAND:
    			if(LOWORD(wParam)==ID_COMBOBOX1&&HIWORD(wParam)==CBN_SELCHANGE)
    			{
    				index=SendMessage(hCombo,CB_GETCURSEL,0,0);
    				if(index==CB_ERR)
    				{
    					return TRUE;
    				}
    				SendMessage(hCombo,CB_GETLBTEXT,index,(LPARAM)chOutTxt);
    			}
    			if(LOWORD(wParam)==ID_BUTTON)
    			{
    				if(strcmp(chOutTxt,"Secure Disk Wipe")==0)
    				{
    					MessageBox(NULL,"Secure Disk Wipe option was selected","Combo Box Selection",MB_OK);
    					ShowWindow(hwnd,SW_HIDE);
    					ShowWindow(SDW,SW_SHOW);
    				}
    				if(strcmp(chOutTxt,"Secure Disk Cleanse")==0)
    				{
    					MessageBox(NULL,"Secure Disk Cleanse option was selected","Combo Box Selection",MB_OK);
    					ShowWindow(hwnd,SW_HIDE);
    					ShowWindow(SDC,SW_SHOW);
    				}
    				if(strcmp(chOutTxt,"Secure File Deletion")==0)
    				{
    					MessageBox(NULL,"Secure File Deletion option was selected","Combo Box Selection",MB_OK);
    					ShowWindow(hwnd,SW_HIDE);
    					ShowWindow(SFD,SW_SHOW);
    				}
    			}
    			return 0;
    		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_DESTROY:
    			PostQuitMessage(0);
    		break;
    		default: return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    }
    //The Secure Disk Wipe window, needs to be fixed, I think
    LRESULT APIENTRY SDW_Proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	static TCHAR chOutTxt[32];
    	INT index;
    	HWND hButton=NULL;
    	TCHAR chTxt[32];
    	static HWND hCombo1=NULL;
    	HDC hdc;
    	PAINTSTRUCT ps;
    	LPSTR Greeting,Option;
    	Option="Drive:";
    	Greeting="Secure Disk Wipe ";
    	switch(msg)
    	{
    		case WM_CREATE:
    			hCombo1=CreateWindowEx(0,"COMBOBOX","Secure Disk Wipe",
    				WS_CHILD|WS_VISIBLE | CBS_DROPDOWNLIST,
    				75,120,180,100,hwnd,(HMENU) ID_COMBOBOX2,g_hInst,NULL);
    				lstrcpy(chTxt,"A:\\");
    					SendMessage(hCombo1,CB_ADDSTRING,0,(LPARAM)chTxt);
    				lstrcpy(chTxt,"C:\\");
    					SendMessage(hCombo1,CB_ADDSTRING,1,(LPARAM)chTxt);
    				lstrcpy(chTxt,"D:\\");
    					SendMessage(hCombo1,CB_ADDSTRING,2,(LPARAM)chTxt);
    			hButton=CreateWindowEx(NULL,"Button","Submit",
    				WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    				225,150,60,25,hwnd,(HMENU)ID_BUTTON,g_hInst,NULL);
    		break;
    		case WM_COMMAND:
    			if(LOWORD(wParam)==ID_COMBOBOX1&&HIWORD(wParam)==CBN_SELCHANGE)
    			{
    				index=SendMessage(hCombo1,CB_GETCURSEL,0,0);
    				if(index==CB_ERR)
    				{
    					return TRUE;
    				}
    				SendMessage(hCombo1,CB_GETLBTEXT,index,(LPARAM)chOutTxt);
    			}
    			if(LOWORD(wParam)==ID_BUTTON)
    			{
    				if(strcmp(chOutTxt,"A:\\")==0)
    				{
    					MessageBox(NULL,"A:\\ was selected","Combo Box Selection",MB_OK);
    				}
    				if(strcmp(chOutTxt,"C:\\")==0)
    				{
    					MessageBox(NULL,"C:\\ was selected","Combo Box Selection",MB_OK);
    				}
    				if(strcmp(chOutTxt,"D:\\")==0)
    				{
    					MessageBox(NULL,"D:\\ was selected","Combo Box Selection",MB_OK);
    				}
    				MessageBox(0,"This option is not yet complete","Not complete",MB_OK);
    			}
    		return 0;
    		break;
    		case WM_PAINT:
    			hdc=BeginPaint(hwnd,&ps);
    			TextOut(hdc,85,25,Greeting,strlen(Greeting));
    			TextOut(hdc,50,100,Option,strlen(Option));
    			EndPaint(hwnd,&ps);
    		break;
    		case WM_CLOSE:
    			ShowWindow(SDW,SW_HIDE);
    			ShowWindow(Main,SW_SHOW);
    		break;
    		default: return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }
    //The Secure Disk Cleanse window, It's not up yet
    LRESULT APIENTRY SDC_Proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	static TCHAR chOutTxt[32];
    	INT index;
    	HWND hButton=NULL;
    	TCHAR chTxt[32];
    	static HWND hCombo1=NULL;
    	HDC hdc;
    	PAINTSTRUCT ps;
    	LPSTR Greeting,Question,Option;
    	Option="Drive:";
    	Greeting="Secure Disk Cleanse";
    	switch(msg)
    	{
    		case WM_CREATE:
    			hCombo1=CreateWindowEx(0,"COMBOBOX","Secure Disk Cleanse",
    				WS_CHILD|WS_VISIBLE | CBS_DROPDOWNLIST,
    				75,120,180,100,hwnd,(HMENU) ID_COMBOBOX2,g_hInst,NULL);
    				lstrcpy(chTxt,"A:\\");
    					SendMessage(hCombo1,CB_ADDSTRING,0,(LPARAM)chTxt);
    				lstrcpy(chTxt,"C:\\");
    					SendMessage(hCombo1,CB_ADDSTRING,1,(LPARAM)chTxt);
    				lstrcpy(chTxt,"D:\\");
    					SendMessage(hCombo1,CB_ADDSTRING,2,(LPARAM)chTxt);
    			hButton=CreateWindowEx(NULL,"Button","Submit",
    				WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    				225,150,60,25,hwnd,(HMENU)ID_BUTTON,g_hInst,NULL);
    		case WM_COMMAND:
    		if(LOWORD(wParam)==ID_COMBOBOX1&&HIWORD(wParam)==CBN_SELCHANGE)
    		{
    			index=SendMessage(hCombo1, CB_GETCURSEL, 0, 0);
    			if (index==CB_ERR)
    			{
    				return TRUE;
    			}
    			SendMessage(hCombo1,CB_GETLBTEXT,index,(LPARAM)chOutTxt);
    		}
    		if(LOWORD(wParam)==ID_BUTTON)
    		{
    			if(strcmp(chOutTxt,"A:\\")==0)
    			{
    				MessageBox(NULL,"A:\\ was selected","Combo Box Selection",MB_OK);
    			}
    			if(strcmp(chOutTxt,"C:\\")==0)
    			{
    				MessageBox(NULL,"C:\\ was selected","Combo Box Selection",MB_OK);
    			}
    			if(strcmp(chOutTxt,"D:\\")==0)
    			{
    				MessageBox(NULL,"D:\\ was selected","Combo Box Selection",MB_OK);
    			}
    			std::string File,Drive;
    			Drive=chOutTxt;
    			File=Drive+"SecureDiskCleanse.txt";
    			int Exists;
    			Exists=0;
    			if(Exists==0)
    			{
    				int Loops=GetDiskSize(Drive.c_str());
    				OverWrite(Loops,File,0);
    				MessageBox(0,"Drive Cleanse Finished","Completed",MB_OK);
    			}
    			else
    			{
    				int Loops=GetDiskSize(Drive.c_str());
    				OverWrite(Loops,File.c_str(),2);
    				MessageBox(0,"Drive Cleanse Finished","Completed",MB_OK);
    			}
    		}
    		return 0;
    		case WM_PAINT:
    			hdc=BeginPaint(hwnd,&ps);
    			TextOut(hdc,85,25,Greeting,strlen(Greeting));
    			TextOut(hdc,50,100,Option,strlen(Option));
    			EndPaint(hwnd,&ps);
    		break;
    		case WM_CLOSE:
    			ShowWindow(SDC,SW_HIDE);
    			ShowWindow(Main,SW_SHOW);
    		break;
    		default: return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }
    //Pretty much a completed window for Secure File Deletion, should be working
    LRESULT APIENTRY SFD_Proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	static TCHAR chOutTxt[64];
    	static TCHAR chOutTxt2[64];
    	std::string Drives;
    	std::string File;
    	INT index;
    	HWND hButton=NULL;
    	TCHAR chTxt[32];
    	static HWND hCombo1=NULL;
    	static HWND hCombo2=NULL;
    	HDC hdc;
    	PAINTSTRUCT ps;
    	LPSTR Greeting,Drive,Path;
    	Drive="Drive:";
    	Path="Path:";
    	Greeting="Secure File Deletion";
    	switch(msg)
    	{
    		case WM_CREATE:
    			hCombo1=CreateWindowEx(0,"COMBOBOX","Secure File Deletion",
    				WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
    				125,75,100,100,hwnd,(HMENU)ID_COMBOBOX2,g_hInst,NULL);
    			lstrcpy(chTxt,"A:\\");
    				SendMessage(hCombo1,CB_ADDSTRING,0,(LPARAM)chTxt);
    			lstrcpy(chTxt,"C:\\");
    				SendMessage(hCombo1,CB_ADDSTRING,1,(LPARAM)chTxt);
    			lstrcpy(chTxt,"D:\\");
    				SendMessage(hCombo1,CB_ADDSTRING,2,(LPARAM)chTxt);
    			hCombo2=CreateWindowEx(0,"COMBOBOX","Secure File Deletion FilePath",
    				WS_CHILD|WS_VISIBLE|CBS_HASSTRINGS,
    				85,100,200,25,hwnd,(HMENU)ID_COMBOBOX3,g_hInst,NULL);
    			hButton=CreateWindowEx(NULL,"Button","Submit",
    				WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    				125,125,75,25,hwnd,(HMENU)ID_BUTTON,g_hInst,NULL);
    		break;
    		case WM_PAINT:
    			hdc=BeginPaint(hwnd,&ps);
    			TextOut(hdc,100,25,Greeting,strlen(Greeting));
    			TextOut(hdc,75,75,Drive,strlen(Drive));
    			TextOut(hdc,40,100,Path,strlen(Path));
    			EndPaint(hwnd,&ps);
    		break;
    		case WM_COMMAND:
    			if(LOWORD(wParam)==ID_COMBOBOX2&&HIWORD(wParam)==CBN_SELCHANGE)
    			{
    				index=SendMessage(hCombo1,CB_GETCURSEL,0,0);
    				if (index==CB_ERR)
    				{
    					return TRUE;
    				}
    				SendMessage(hCombo1,CB_GETLBTEXT,index,(LPARAM)chOutTxt);
    			}
    			if(LOWORD(wParam)==ID_COMBOBOX3&&HIWORD(wParam)==CBN_SELCHANGE)
    			{
    				index=SendMessage(hCombo2,CB_GETLBTEXTLEN,0,0);
    				if (index==CB_ERR)
    				{
    					return TRUE;
    				}
    				SendMessage(hCombo2,CB_GETLBTEXT,index,(LPARAM)chOutTxt2);
    			}
    			if(LOWORD(wParam)==ID_BUTTON)
    			{
    				if(strcmp(chOutTxt,"A:\\")==0)
    				{
    					MessageBox(NULL,"A:\\ was selected","Combo Box Selection",MB_OK);
    				}
    				if (strcmp(chOutTxt,"C:\\")==0)
    				{
    					MessageBox(NULL,"C:\\ was selected","Combo Box Selection",MB_OK);
    				}
    				if (strcmp(chOutTxt,"D:\\")==0)
    				{
    					MessageBox(NULL,"D:\\ was selected","Combo Box Selection",MB_OK);
    				}
    			}
    			Drives=chOutTxt;
    			File=chOutTxt2;
    			File=Drives+File;
    			int Loops;
    			Loops=GetFileSize(File);
    			OverWrite(Loops,File,1);
    			File="DEL "+File;
    			system(File.c_str());
    			MessageBox(0,"File was deleted","Completed",MB_ICONINFORMATION|MB_OK);
    			return 0;
    		break;
    		case WM_CLOSE:
    			ShowWindow(SFD,SW_HIDE);
    			ShowWindow(Main,SW_SHOW);
    		break;
    		default: return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }
    And here is the Header
    Code:
    #include <iostream>
    #include <fstream>
    void DisplayOptions();
    void Delete(std::string File);
    int GetDiskSize(std::string Dir);
    int GetFileSize(std::string File);
    void CheckLength(std::string Dir);
    std::string GetObject(std::string Object);
    void OverWrite(int Loops, std::string File,int A);
    void MainFunction(std::string Dir,std::string File);
    void RestartMainFunction(std::string Dir,std::string File);
    void Choice(std::string Dir,bool Restart,std::string File);
    void NoRestartMainFunction(std::string Dir,std::string File);
    And here are the prototypes (At least that's what I think they are called)
    Code:
    #include "..\Header\SecSuite.h"
    /*____________________________________________________________________________*/
    
    void DisplayOptions()
    {
    	std::cout<<"Welcome to C.J.'s Security 'suite'!\n";
    	std::cout<<"Please enter what you want to do.\n"<<std::endl;
    	std::cout<<"To select Secure Disk Wipe, input SDW.\n";
    	std::cout<<"To select Secure Disk Cleanse, input SDC.\n";
    	std::cout<<"To select Secure File Deletion, input SFD.\n";
    	std::cout<<"To select ---this option is not yet available---.\n";
    	std::cout<<"To select ---this option is not yet available---."<<std::endl;
    	std::cout<<"Option:";
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void Choice(std::string Dir,bool Restart, std::string File)
    {
    	if (Restart=true)
    	{
    		RestartMainFunction(Dir,File);
    	}
    	if(Restart==false)
    	{
    		NoRestartMainFunction(Dir,File);
    	}
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void Delete(std::string File)
    {
    	File="Del "+File;
    	system(File.c_str());
    	std::cout<<"File erased."<<std::endl;
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    int GetDiskSize(std::string Dir)
    {
    	__int64 i64FreeBytes;
    	typedef BOOL (WINAPI *PGETDISKFREESPACEEX)(LPCSTR,
    	PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
    	PGETDISKFREESPACEEX pGetDiskFreeSpaceEx;
    	pGetDiskFreeSpaceEx=(PGETDISKFREESPACEEX)GetProcAddress(GetModuleHandle
    	("kernel32.dll"),
    	"GetFreeDiskSpaceExA");
    
        GetDiskFreeSpaceExA(Dir.c_str(),
    					NULL,
    					NULL,
    					(PULARGE_INTEGER)&i64FreeBytes);
    	int SizeOfDisk=((i64FreeBytes/1024)/1024);
    	return SizeOfDisk;
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    int GetFileSize(std::string File)
    {
    	long end,begin;
    	int SizeOfFile;
    	std::ifstream a_File(File.c_str());
    	begin=a_File.tellg();
    	a_File.seekg(0,std::ios::end);
    	end=a_File.tellg();
    	a_File.close();
    	SizeOfFile=(end-begin);
    	return SizeOfFile;
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    bool ChoiceCheck(std::string Option)
    {
    	bool Choice;
    	if(Option=="Y")
    	{
    		Choice=true;
    	}
    	if(Option=="y")
    	{
    		Choice=true;
    	}
    	else
    	{
    		Choice=false;
    	}
    	return Choice;
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    std::string GetObject(std::string Option)
    {
    	std::string DirOrFileName;
    	std::cout<<"Please enter "<<Option;
    	getline(std::cin,DirOrFileName,'\n');
    	return DirOrFileName;
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void OverWrite(int Loops, std::string File, int A)
    {
    	if(A==2)
    	{
    		std::ofstream The_File(File.c_str(),std::ios::app);
    		while(Loops>0,Loops--)
    		{
    			The_File<<"1";
    		}
    		The_File.close();
    	}
    	if(A==1)
    	{
    		std::ofstream The_File(File.c_str(),std::ios::trunc);
    		while(Loops>0,Loops--)
    		{
    			The_File<<"1";
    		}
    		The_File.close();
    	}
    	if(A==0)
    	{
    		std::ofstream The_File(File.c_str());
    		while(Loops>0,Loops--)
    		{
    			The_File<<"1";
    		}
    		The_File.close();
    	}
    	File="Del "+File;
    	system(File.c_str());
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void CheckLength(std::string Disk)
    {
    	bool Loop;
    	while(Loop==true)
    	{
    		Disk="";
    		/*This is going to be a ComboBox that comes up
    		if the user Selects Cleanse disk or wipe disk*/
    		getline(std::cin,Disk,'\n');
    		if(Disk.length()==3)
    		{
    			Loop=false;
    		}
    	}
    	Loop=true;
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void MainFunction(std::string Dir,std::string File)
    {
    	std::ofstream a_file(File.c_str());
    	int Loops=GetDiskSize(Dir);
    	while(Loops>0,Loops--)
    	{
    		a_file<<"1";
    	}
    	a_file.close();
    	Delete(File);
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void RestartMainFunction(std::string Dir,std::string File)
    {
    	std::ofstream a_file(File.c_str(), std::ios::ate);
    	int Loops=GetDiskSize(Dir);
    	while(Loops>0,Loops--)
    	{
    		a_file<<"1";
    	}
    }
    
    
    
    /*____________________________________________________________________________*/
    
    
    
    void NoRestartMainFunction(std::string Dir,std::string File)
    {
    	std::ofstream a_file(File.c_str(), std::ios::trunc);
    	int Loops=GetDiskSize(Dir);
    	while(Loops>0,Loops--)
    	{
    		a_file<<"1";
    	}
    	Delete(File);
    }
    /*____________________________________________________________________________*/
    I use the header and prototypes also for the command-line version... which works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  2. socket message sending and receiving problem
    By black in forum C Programming
    Replies: 5
    Last Post: 01-15-2007, 04:46 AM
  3. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  4. button 'message'
    By psychopath in forum Windows Programming
    Replies: 12
    Last Post: 04-18-2004, 09:57 AM
  5. Who is using a file/How to send a message
    By leonel in forum Windows Programming
    Replies: 0
    Last Post: 01-31-2003, 01:54 PM