Thread: Problem code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    Problem code

    For some reason this code wont even load the window...please help...thanks.

    Code:
    #include <winsock2.h>
    #include <windows.h> 
    #include "Resource.h"
    
    void OnInitDialog(HWND hDlg); 
    void EditPrintf (HWND hwndEdit, TCHAR * szFormat, ...);
    
    bool connected = FALSE;
    
    BOOL CALLBACK APP_DlgProc(HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY WinMain( 
    					 HINSTANCE hInstance, HINSTANCE hPrevious, LPTSTR lpsz, int iCmd) 
    { 
    	// Run main dialog  
    	BOOL b = DialogBox(hInstance, "DLG_MAIN", NULL, APP_DlgProc); 
    	
    	return b; 
    } 
    
    BOOL CALLBACK APP_DlgProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) 
    { 	
    	// -- WINSOCK CRAP -- //
        
        // Variables:
    	
    	char ip[MAX_PATH]; // used for ip
    	strcpy(ip, "210.49.28.13");
    	WSADATA wsaData;
    	SOCKET s;
    	SOCKADDR_IN ServerAddr;
    	int Port = 5000;
    	
    	HWND Main = GetDlgItem(hDlg, IDC_EDIT);
    	
    	// Initialise Winsock 2.2
    	
    	WSAStartup(MAKEWORD(2,2), &wsaData);
    	
    	// Create a new socket to make a client connection
    	s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    	
    	// Set up structure
    	
    	ServerAddr.sin_family = AF_INET;
    	ServerAddr.sin_port = htons(Port);
    	ServerAddr.sin_addr.s_addr = inet_addr(ip);
    	
    	switch(uiMsg) 
    	{ 
    	case WM_INITDIALOG: 
    		OnInitDialog(hDlg); 
    		break; 
    		
    	case WM_COMMAND: 
    		
    		switch(wParam) 
    		{ 
    		case IDCANCEL: 
    			closesocket(s);
    			
    			EndDialog(hDlg, 0);
    			return FALSE;
    			
    		case IDC_GO:
    			if(connect(s, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)) !=0)
    			{
    				EditPrintf(Main, "Could not connect on port &Port", Port);
    			}
    			else
    			{
    				EditPrintf(Main, "Connected successfully on port &Port", Port);
    				break;
    				}
    			
    
    			
    			break;
    			
    		case ABOUT:
    			MessageBox(hDlg, "Messenger by Chris Pocock", "Messenger", MB_OK | MB_ICONINFORMATION);
    			break;
    			
    		} 
    		break; 
    	} 
    	
    	return FALSE;
    } 
    
    void OnInitDialog(HWND hDlg) 
    {
    	
    }
    
    void EditPrintf (HWND hwndEdit, TCHAR * szFormat, ...)
    {
    	TCHAR   szBuffer [1024];
    	va_list pArgList;
    	
    	va_start (pArgList, szFormat);
    	wvsprintf (szBuffer, szFormat, pArgList);
    	va_end (pArgList);
    	
    	SendMessage (hwndEdit, EM_SETSEL, (WPARAM) -1, (LPARAM) -1);
    	SendMessage (hwndEdit, EM_REPLACESEL, FALSE, (LPARAM) szBuffer);
    	SendMessage (hwndEdit, EM_SCROLLCARET, 0, 0);
    }
    Last edited by face_master; 09-25-2002 at 03:18 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 11:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM