// kang44.cpp : Defines the entry point for the application.
//#include <stdio.h>
#include "stdafx.h"
#include "resource.h"
#include <stdlib.h>
#define MAX_LOADSTRING 100// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance, //handle to current instance                     HINSTANCE hPrevInstance,//handle to previous instance
                     LPSTR     lpCmdLine,//command line
                     int       nCmdShow)//show state
{
  // TODO: Place code here.
MSG msg;
HACCEL hAccelTable; // Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_KANG44, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance); // Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) 
{
return FALSE;
} hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_KANG44); // Main message loop:
while (GetMessage(&msg, NULL, 0, 0)) 
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return msg.wParam;
}//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wcex; //wcex.cbSize = sizeof(WNDCLASS);  wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION);
wcex.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
wcex.lpszMenuName = NULL;//(LPCSTR)IDC_KANG44;
wcex.lpszClassName = "kang";
//wcex.hIconSm = NULL;//LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClass(&wcex);
}//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;   hInst = hInstance; // Store instance handle in our global variable   hWnd = CreateWindow("kang", "康晓宇", WS_OVERLAPPEDWINDOW /*& ~WS_MAXIMIZEBOX*/,
      CW_USEDEFAULT,CW_USEDEFAULT, 600,400, NULL, NULL, hInstance, NULL);//CW_USEDEFAULT   if (!hWnd)
   {
      return FALSE;
   }   ShowWindow(hWnd, SW_SHOWNORMAL);//nCmdShow
   UpdateWindow(hWnd);   return TRUE;
}//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND - process the application menu
//  WM_PAINT - Paint the main window
//  WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) 
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hWnd,szChar,"kang",MB_OK);
break;
case WM_COMMAND:
wmId    = LOWORD(wParam); 
wmEvent = HIWORD(wParam); 
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
   break;
case IDM_EXIT:
   DestroyWindow(hWnd);
   break;
default:
   return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE; case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
    return FALSE;
}

解决方案 »

  1.   

    #include <stdio.h>
    #include "stdafx.h"
    #include "resource.h"
    #include <stdlib.h>using namespace std//如果还不行:
    #include <stdio>//去掉h
    #include "stdafx.h"
    #include "resource.h"
    #include <stdlib.h>using namespace std
      

  2.   

    Requirements
    Routine
     Required header
     
    sprintf, _sprintf_l
     <stdio.h>
     
    swprintf, _swprintf_l
     <stdio.h> or <wchar.h>
     
      

  3.   


    #include <stdio.h>放到头人件最后。可以解决!
      

  4.   

    文件包含由原先
    #include <stdio.h>
    #include "stdafx.h"
    #include "resource.h"
    #include <stdlib.h>
    修改为:
    #include "stdafx.h"
    #include <stdio.h>
    #include "resource.h"
    可以通过编译,记住如果有预定义#include "stdafx.h",最好的习惯是放第一个