⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winmain.cpp

📁 Visual C++ 游戏开发与设计实例 源代码(所有)
💻 CPP
字号:
/*---------------------------------------------
   HEAD.C -- Displays beginning (head) of file
             (c) Charles Petzold, 1998
  ---------------------------------------------*/

#include <windows.h>

#define ID_LIST     1
#define MAXNOTICE	64

HWND     hwndList;

bool InitServer();
void TerminateServer();
DWORD WINAPI AcceptThread( LPVOID pParam );
DWORD WINAPI WorkerThread( LPVOID pParam ); 

LRESULT CALLBACK WndProc  (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("serverv2") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;
     
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     
     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     
     hwnd = CreateWindow (szAppName, TEXT ("Server v2.0"),
                          WS_OVERLAPPEDWINDOW ^WS_SIZEBOX^WS_MAXIMIZEBOX, 
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          400,300,
                          NULL, NULL, 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 message, WPARAM wParam, LPARAM lParam)
{
     int		cxChar, cyChar ;
     
     switch (message)
     {
     case WM_CREATE :
          cxChar = LOWORD (GetDialogBaseUnits ()) ;
          cyChar = HIWORD (GetDialogBaseUnits ()) ;
           
          hwndList = CreateWindow (TEXT ("listbox"), NULL,
                              WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD ^ LBS_SORT,
                              cxChar, cyChar,
                              cxChar * 44 + GetSystemMetrics (SM_CXVSCROLL),
                              cyChar * 16,
                              hwnd, (HMENU) ID_LIST,
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                              NULL) ;
          
		  if ( !InitServer() )
			  PostQuitMessage (0) ;

		  CreateThread( NULL, 0, AcceptThread, NULL, 0, NULL );
		  CreateThread( NULL, 0, WorkerThread, NULL, 0, NULL );

          return 0 ;
          
     case WM_SETFOCUS :
          SetFocus (hwndList) ;
          return 0 ;
          
//     case WM_COMMAND :
//          return 0 ;
   
     case WM_DESTROY :
		  TerminateServer();
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

void Notice( int num, ...)
{
	TCHAR	*s = new TCHAR[MAXNOTICE];
	s[0] = 0;

	va_list		vl;
    va_start( vl, num );
	
    // Step through the list.
    for( int i = 0; i<num ; i++ )
        lstrcat( s, va_arg( vl, TCHAR * ) );
    va_end( vl );

	// Display msg
	SendMessage( hwndList, LB_ADDSTRING, 0, (LPARAM)s );
}

void Notice( LPCTSTR head, int msgid ) {
	TCHAR	*s = new TCHAR[MAXNOTICE];
	
	lstrcpy( s, head );
	int len = strlen( s );
	itoa( msgid, &s[len], 16 );
	s[len+4] = 0;

	// Display msg
	SendMessage( hwndList, LB_ADDSTRING, 0, (LPARAM)s );
}

     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -