Thread: Creating pop up menus

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    k I got the menu working and everything

    here is my code so far
    Code:
    case WM_COMMAND:
    			{
    					
    				switch(LOWORD(wParam))
    				{
    					case ID_COUCHCOLOR_RED:
    						{
    							couchR = 1.0;
    							couchG = 0.0;
    							couchB = 0.0;
    							
    						}
    					case ID_COUCHCOLOR_WHITE:
    						{
    							couchR = 1.0;
    							couchG = 1.0;
    							couchB = 1.0;
    						}
    					case ID_COUCHCOLOR_BLUE:
    						{
    							couchR = 0.0;
    							couchG = 0.0;
    							couchB = 1.0;
    						}
    				}
    
    			}
    the problem now is it won't apply the IE when I click on red it won't apply red it just applies teh ID_COUCHCOLOR_BLUE

    however If I remove the 2 cases WHITE and BLUE then I get red why is this?

    it just applies the latest color to the object.

    anyway I can fix this?
    -Ti22-

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    You've forgot the break statements to exit out of your switch, aka

    Code:
    switch(LOWORD(wParam)) {
                 
                      case ID_COUCHCOLOR_RED:
                      {
    							                   couchR = 1.0;
    		   couchG = 0.0;
    		   couchB = 0.0;
    		   break; //<-----------add this after each case					
    	  }
    You'll need to add that for each case statement. Or return, however you have your program setup.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    cool thx

    its working like a charm now .


    Thx.
    -Ti22-

  4. #4
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    hmm I've ran into another problem, its pretty minor though

    after a certain number of clicks my pop up menu won't work anymore

    any idea how to fix this?
    -Ti22-

  5. #5
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    I am going to need you to post some more code to answer that question.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  6. #6
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    here is my winmain

    Code:
    int WINAPI WinMain (HINSTANCE hInstance,
    					HINSTANCE hPrevInstance,
    					LPSTR	lpCmdLine,
    					int		nCmdShow)
    {
    	MSG		msg;
    	bool	done = false;
    
    	//The next part will be a message box that pops up to ask the user if he/she wishes to run in
    	//Fullscreen mode.
    	if(MessageBox(NULL, "Would you like to run in Full Screen Mode", "Ti-X Engine", MB_YESNO | MB_ICONQUESTION)==IDNO)
    	{
    		fullscreen = false;			//runs in windowed mode (since the fullscreen way up there has been set to true by default)
    	}
    
    	//This is where we create the OpenGL window (using the creat_gl_window function we wrote earlier)
    	if(!create_gl_window("Ti-X WGL Skeleton", 1280, 1024, 16, fullscreen))
    	{
    		return 0;			//Quit if the window was not able to creat
    	}
    
    	while (!done)			//While we're not done continue in the while loop (this is actually our main loop)
    	{
    		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			if (msg.message==WM_QUIT)			//If recieve a message telling to quit then set done to true
    			{	
    				done = true;				//This will make the program quit
    			}
    			else					//if we're not done then handle the messages.
    			{
    				TranslateMessage(&msg);		//Translate message
    				DispatchMessage(&msg);		//Dispatch messate
    			}
    		}
    		else
    		{
    			if(program_status)
    			{
    				if (keys[VK_ESCAPE])		//If the escape key is pressed
    				{
    					done = true;			//Done to true, so we quit
    				}
    				else					//if not then continue drawing our stuff.
    				{
    					draw_scene(); //here we finally call the draw_scene function which will draw our stuff
    					SwapBuffers(hDC); //Since we're using double buffering we need this to swap the buffer
    					if (keys['L'] && !l_stat)
    					{
    						l_stat = true;
    						light = !light;
    
    						if (!light)
    						{
    							glDisable(GL_LIGHTING);
    						}
    						else
    						{
    							glEnable(GL_LIGHTING);
    						}
    					}
    					if (!keys['L'])
    					{
    						l_stat = false;
    					}
    					if (keys['W'])
    					{
    						camera_x -= (float)sin(-mouse_y * piover180) * 0.05f;
    						camera_z -= (float)cos(-mouse_y * piover180) * 0.05f;
    					}
    					if (keys['S'])
    					{
    						camera_x += (float)sin(-mouse_y * piover180) * 0.05f;
    						camera_z += (float)cos(-mouse_y * piover180) * 0.05f;
    					}
    					if (keys['A'])
    					{
    						camera_x -= (float)cos(mouse_y * piover180) * 0.05f;
    						camera_z -= (float)sin(mouse_y * piover180) * 0.05f;
    					}
    					if (keys['D'])
    					{
    						camera_x += (float)cos(mouse_y * piover180) * 0.05f;
    						camera_z += (float)sin(mouse_y * piover180) * 0.05f;
    					}
    					if (keys[VK_LEFT])
    					{
    						direction += 0.02f;
    						rotate_z = direction;
    					}
    					if (keys[VK_RIGHT])
    					{
    						direction -= 0.02f;
    						rotate_z = direction;
    					}
    					if (keys[VK_PRIOR])
    					{
    						height += 0.01f;
    					}
    					if (keys[VK_NEXT])
    					{
    						height -= 0.01f;
    					}
    					
    					
    				}
    			}
    			//This next bit of code will alow you to switch from windowed to fullscreen mode.
    			if(keys[VK_F1])
    			{
    				keys[VK_F1] = false;  // If f1 is pressed make false 
    				kill_gl_window();
    				fullscreen = !fullscreen;
    				// Recreate our GL window
    				if (!create_gl_window("Ti-x WGL Framework", 1280, 1024, 16, fullscreen))
    				{
    					return 0;
    				}
    			}
    		}
    	}
    	//shut down	
    	kill_gl_window();		//Kill window
    	return(msg.wParam);		//Exit the program
    
    
    }
    here is my WndProc

    Code:
    //this callback function will handle the message out put by window.
    LRESULT CALLBACK WndProc( HWND hWnd,
    						  UINT uMsg,
    						  WPARAM wParam,
    						  LPARAM lParam)
    {
    	static HMENU hMenu;
    	//POINT point;
    	
    	
    	switch(uMsg)			//This will check for all sorts of windows message.
    	{
    		case WM_MOUSEMOVE:
    			{
    				mouse_y = LOWORD(lParam);
    				mouse_x = HIWORD(lParam);
    			}
    		case WM_INITDIALOG:
    			{	
    				hMenu = LoadMenu(GetModuleHandle(NULL),//Load Menu
    				MAKEINTRESOURCE(IDR_MENU2));
    				hMenu = GetSubMenu(hMenu,0);//Get Sub Menu
    				return 0;
    			}
    		case WM_RBUTTONDOWN:
    			{
    				//point.x = LOWORD(lParam);
    				//point.y = HIWORD(lParam);
    				TrackPopupMenu(hMenu,TPM_LEFTALIGN | TPM_RIGHTBUTTON,
    				mouse_y,mouse_x,NULL,hWnd,NULL);
    				return 0;
    			}
    				
    				
    		case WM_COMMAND:
    			{
    
    				switch(LOWORD(wParam))
    				{
    					case ID_COUCHCOLOR_RED:
    						{
    							couchRGB[0] = 1.0;
    							couchRGB[1] = 0.0;
    							couchRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_COUCHCOLOR_WHITE:
    						{
    							couchRGB[0] = 1.0;
    							couchRGB[1] = 1.0;
    							couchRGB[2] = 1.0;
    							return 0;
    						}
    					case ID_COUCHCOLOR_BLUE:
    						{
    							couchRGB[0] = 0.0;
    							couchRGB[1] = 0.0;
    							couchRGB[2] = 1.0;
    							return 0;
    						}
    
    					case ID_TVCOLOR_GREEN:
    						{
    							tv_setRGB[0] = 0.0;
    							tv_setRGB[1] = 1.0;
    							tv_setRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_TVCOLOR_RED:
    						{
    							tv_setRGB[0] = 1.0;
    							tv_setRGB[1] = 0.0;
    							tv_setRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_TVCOLOR_YELLOW:
    						{
    							tv_setRGB[0] = 0.7;
    							tv_setRGB[1] = 0.5;
    							tv_setRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_TVSTANDCOLOR_WHITE:
    						{
    							tv_standRGB[0] = 1.0;
    							tv_standRGB[1] = 1.0;
    							tv_standRGB[2] = 1.0;
    							return 0;
    						}
    					case ID_TVSTANDCOLOR_RED:
    						{
    							tv_standRGB[0] = 1.0;
    							tv_standRGB[1] = 0.0;
    							tv_standRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_TVSTANDCOLOR_GREY:
    						{
    							tv_standRGB[0] = 0.2;
    							tv_standRGB[1] = 0.2;
    							tv_standRGB[2] = 0.2;
    							return 0;
    						}
    					case ID_TEATABLECOLOR_GREY:
    						{
    							tea_tableRGB[0] = 0.0;
    							tea_tableRGB[1] = 1.0;
    							tea_tableRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_TEATABLECOLOR_BLUE:
    						{
    							tea_tableRGB[0] = 0.1;
    							tea_tableRGB[1] = 0.1;
    							tea_tableRGB[2] = 1.0;
    							return 0;
    						}
    					case ID_TEATABLECOLOR_BROWN:
    						{
    							tea_tableRGB[0] = 0.07;
    							tea_tableRGB[1] = 0.037;
    							tea_tableRGB[2] = 0.007;
    							return 0;
    						}
    					case ID_ROOMCOLOR_RED:
    						{
    							wallRGB[0] = 0.6;
    							wallRGB[1] = 0.1;
    							wallRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_ROOMCOLOR_WHITE:
    						{
    							wallRGB[0] = 1.0;
    							wallRGB[1] = 1.0;
    							wallRGB[2] = 1.0;
    							return 0;
    						}
    					case ID_ROOMCOLOR_GREEN:
    						{
    							wallRGB[0] = 0.0;
    							wallRGB[1] = 1.0;
    							wallRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_PICTUREFRAMECOLOR_WHITE:
    						{
    							picture_frameRGB[0] = 1.0;
    							picture_frameRGB[1] = 1.0;
    							picture_frameRGB[2] = 1.0;
    							return 0;
    						}
    					case ID_PICTUREFRAMECOLOR_RED:
    						{
    							picture_frameRGB[0] = 1.0;
    							picture_frameRGB[1] = 0.0;
    							picture_frameRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_PICTUREFRAMECOLOR_GREEN:
    						{
    							picture_frameRGB[0] = 0.0;
    							picture_frameRGB[1] = 1.0;
    							picture_frameRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_WINDOWFRAMECOLOR_RED:
    						{
    							windowRGB[0] = 1.0;
    							windowRGB[1] = 0.0;
    							windowRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_WINDOWFRAMECOLOR_GREEN:
    						{
    							windowRGB[0] = 0.0;
    							windowRGB[1] = 1.0;
    							windowRGB[2] = 0.0;
    							return 0;
    						}
    					case ID_WINDOWFRAMECOLOR_ORANGE:
    						{
    							windowRGB[0] = 0.4;
    							windowRGB[1] = 0.3;
    							windowRGB[2] = 0.0;
    							return 0;
    						}
    					return 0;
    
    				}
    				return 0;
    			}
    		case WM_ACTIVATE:
    		{
    			if(!HIWORD(wParam))	//Check if Program is in Minimize state
    			{
    				program_status = true;				//Program is still active
    			}
    			else
    			{
    				program_status = false;				//Program is going into Minimize state
    			}
    			
    			return 0;
    		}
    		case WM_SYSCOMMAND:	
    		{
    			switch (wParam)
    			{
    				case SC_SCREENSAVE:			//In case that screensaver is trying to start
    				case SC_MONITORPOWER:		//In case that monitor going into power saving mode
    				return 0; //<< this will prevent the above from happening.
    			}
    			break;
    		}
    		case WM_CLOSE:			//If the X at the top right hand corner is pressed
    		{
    			DestroyMenu(hMenu);
    			EndDialog(hWnd,0);
    			PostQuitMessage(0);			//Post a Quit Message
    			return 0;					
    		}
    		case WM_KEYDOWN:		//If a key is being pressed
    		{
    			keys[wParam] = true;		//If a key is being pressed mark it as true
    			return 0;
    		}
    		case WM_KEYUP:			//If a key is released
    		{
    			keys[wParam] = false;		//If a key is released mark as false
    			return 0;
    		}
    		case WM_SIZE:			// If the Resize button is pressed
    		{
    			resize_window(LOWORD(lParam), HIWORD(lParam));		//LoWord = width HiWord = Height
    			return 0;
    		}
    		return 0;
    	}
    
    	//Of course there are more windows message we don't give a damn about so we can pass it through this:
    	return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    -Ti22-

  7. #7
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Code:
    case WM_COMMAND:
    
                 switch(LOWORD(wParam))  {
                                         //your case statements
                 }
                 break; //<----------------instead of return 0;
    
    //other case statements
    try that out and let me know.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating push & pop functions... decrementing/tracking?
    By Sparrowhawk in forum C Programming
    Replies: 22
    Last Post: 12-14-2008, 09:10 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. creating menus and other stuff
    By C+noob in forum Windows Programming
    Replies: 4
    Last Post: 07-13-2005, 07:20 PM
  4. Creating menus
    By firestorm in forum C++ Programming
    Replies: 13
    Last Post: 04-06-2005, 11:19 AM
  5. Creating menus
    By jr2007 in forum Windows Programming
    Replies: 4
    Last Post: 10-27-2003, 03:11 PM