why

This is a discussion on why within the Windows Programming forums, part of the Platform Specific Boards category; why wont this work Code: /****************************************************************************/ /* created by:adam * /* on 2-21-02 * /* * /* * /* * ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    why

    why wont this work



    Code:
    /****************************************************************************/
    /*	created by:adam															*	
    /*	on 2-21-02																*
    /*																			*	
    /*																			*
    /*																			*
    /*																			*
    /*																			*	
    /*																			*
    /****************************************************************************/
    #include <windows.h>									
    #include <stdio.h>											
    
    #define ID_CONNECT 2556;
    #define ID_SEND    2557
    
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);	
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)			
        {														
        HWND        hwnd;										
        MSG         msg;									
        WNDCLASSEX  wndclass;									
    
        wndclass.cbSize        = sizeof (wndclass);				
        wndclass.style         = CS_HREDRAW | CS_VREDRAW;		
        wndclass.lpfnWndProc   = WndProc;					
        wndclass.cbClsExtra    = 0;							
        wndclass.cbWndExtra    = 0;								
        wndclass.hInstance     = hInstance;						
        wndclass.hIcon         = LoadIcon (NULL,NULL);
        wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);	
        wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
        wndclass.lpszMenuName  = NULL;							
        wndclass.lpszClassName = "client";			
        wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION);
    
    	RegisterClassEx (&wndclass);							
    
        hwnd = CreateWindow ("client",				
    						 "client",		  			
    						 WS_POPUP,				
    						 200,						
    						 150,						
    						 600,						
    						 400,					    
    						 NULL,								
    						 NULL,								
    						 hInstance,						    
    						 NULL);								
    
    	HWND hWndConnect = CreateWindow(TEXT("BUTTON"),
    									TEXT("Connect"),
    									BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
    									10,
    									10,
    									65,
    									15,
    									hwnd,
    									(HMENU)ID_CONNECT,
    									hInstance,
    									NULL ) ;
        
    
    	ShowWindow (hwnd, iCmdShow);							
        UpdateWindow (hwnd);									
    															
    	while (GetMessage (&msg, NULL, 0, 0))					
        {													
    		TranslateMessage (&msg);						
    		DispatchMessage (&msg);								
        }
        
    	return msg.wParam ;										
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (iMsg)
    	{
    		case WM_LBUTTONDOWN:
    			PostQuitMessage(0);
    			break;	
    
    		case WM_COMMAND:
    			switch(wParam)
    			{
    				case ID_CONNECT:
    					MessageBox(hWnd, "Button was clicked!!!", "Event...", MB_OK);
    					PostQuitMessage(0);
    					break;
    			}
    			break;
    	}
    			return DefWindowProc (hwnd, iMsg, wParam, lParam);	
    }

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    What's the problem? What's going wrong? I have a couple of ideas, but I need to know your error. Is it a compile-time error? Runtime? Something just not doing what you expect?
    1978 Silver Anniversary Corvette

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Why are you creating the window with param WS_POPUP?
    1978 Silver Anniversary Corvette

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Can you spot what's wrong with this -

    #define ID_CONNECT 2556;

    2556; will be substituted where ever the preprocessor sees ID_CONNECT.

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    The smallest things...
    1978 Silver Anniversary Corvette

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    the thing im reading told me to define it to a number

    and the errors are things like missing ; after the : when there already is one and a missing ) before ; when there already is one

    and they are all compile time errors

  7. #7
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >and they are all compile time errors

    I know, and they'll be confusing errors because your macro is wrong. You don't want the semi-colon after the number, or that'll be substituted into your code aswell which will confuse the hell out of your compiler.

    //incorrect
    #define ID_CONNECT 2556;


    //correct
    #define ID_CONNECT 2556

Popular pages Recent additions subscribe to a feed

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