Someone help my pathetic excuse for GUI coding

This is a discussion on Someone help my pathetic excuse for GUI coding within the Windows Programming forums, part of the Platform Specific Boards category; Code: #define WIN32_LEAN_AND_MEAN #define BTN_SUBMIT 100 #include "..\Header\GUI.h" HINSTANCE g_hInst; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int ...

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

    Someone help my pathetic excuse for GUI coding

    Code:
    #define WIN32_LEAN_AND_MEAN
    #define BTN_SUBMIT 100
    #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;
    TCHAR chClassName[]="SecuritySuite";
    	HDC hdc;
    	PAINTSTRUCT ps;
    	TCHAR chTxt[32];
    	HWND hButton1,hCombo,hButton2,hCombo2;
    	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,(HMENU)BTN_SUBMIT,g_hInst,NULL);
    				SendMessage(hButton1,0/*WM_SDASD*/,(WPARAM)BN_CLICKED,0);
    			break;
    		case WM_COMMAND:
    				if(HIWORD(wParam)==BN_CLICKED)
    				{
    					HWND hwnd2;
    					hwnd2=CreateWindowEx(0,chClassName,"Drive Options",WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,CW_USEDEFAULT,330,240,HWND_DESKTOP,NULL,
    						hInstance,NULL);
    					switch(msg)
    						HWND hCombo2,hButton2;
    						case WM_CREATE:
    							hCombo2=CreateWindowEx(NULL,"COMBOBOX","DiskChoice",
    							WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,60,120,180,100,
    							hwnd2,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(0,chClassName,"BUTTON","Submit"
    							WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    							250,120,60,25,hwnd2,(HMENU)BTN_SUBMIT,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;
    }
    Can someone help me fix my code? I know, it's a stupid question, but from articles and stuff from msdn, I don't quite understand them, and I learn better if someone just tells me how to use it since then I can actually get response back instead of reading a article with my head up my ass...

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>I know, it's a stupid question<<

    It definitely is if you don't at least describe the problems you have encountered and the error messages your compiler produces. It's always useful to mention what compiler you're actually using, too. Everyone here is quite happy to help but you must help us to help you by providing as much information as you can about the problems you have encountered.

    >>but from articles and stuff from msdn, I don't quite understand them<<

    While msdn can appear daunting at first, it's the primary resource for windows programming and it's probably wiser to get accustomed to it sooner rather than later. If you have difficulty with any particular concept you read about there then you're always free to initiate a discussion about it here. That said, there are a number of introductory windows (api) programming sites that may be much simpler to navigate and understand - for example, winprog is very popular.

    >>Can someone help me fix my code?<<

    Windows is event driven and each time the operating system sends a message to your application it sends them to your window procedure (WndProc in your program). All of those variables you have declared at the start of your window procedure have local scope only so each time a new message comes in those variables will essentially be new. That is, when you create those controls in your WM_CREATE message handler the values returned from CreateWindowEx will be valid for that message only; thereafter they will contain only junk and will not refer to the control handles when, for example, a WM_COMMAND message is processed. A quick way to fix this is to declare those variables as static - ie where you have
    Code:
    HWND hButton1,hCombo,hButton2,hCombo2;
    replace it with
    Code:
    static HWND hButton1,hCombo,hButton2,hCombo2;
    There may be other errors; I haven't looked, but as I mentioned initially you need to help us to help you by providing us with more information than you have done.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    It's just the entire stucture of my program gui is wrong, I don't know how to get the button to submit the option that is chosen in the combobox at the time and I just hardly know any of this ........, but I don't quit projects... so I fkd myself over...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 06:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 08:09 AM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 02:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 05:32 PM

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