首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

windows程序报错提示,如何改啊

2012-11-08 
windows程序报错提示,怎么改啊?[codeC/C++][/code]/*-----------------------PRINT.C -- Common routines

windows程序报错提示,怎么改啊?
[code=C/C++][/code]
/*-----------------------
  PRINT.C -- Common routines for Print1, Print2, and Print3
  -----------------------*/

#include <windows.h>

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

extern HINSTANCE hInst ;
extern TCHAR szAppName[] ;
extern TCHAR szCaption[] ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  PSTR szCmdLine, int iCmdShow)
{
  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) GetStockObject (WHITE_BRUSH) ;
  wndclass.lpszMenuName = NULL ;
  wndclass.lpszClassName = szAppName ;
   
  if (!RegisterClass (&wndclass))

  {
  MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  szAppName, MB_ICONERROR) ;
  return 0 ;
  }
   
  hInst = hInstance ;
   
  hwnd = CreateWindow (szAppName, szCaption,
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, CW_USEDEFAULT,
  CW_USEDEFAULT, CW_USEDEFAULT,
  NULL, NULL, hInstance, NULL) ;
   
  ShowWindow (hwnd, iCmdShow) ;
  UpdateWindow (hwnd) ;
   
  while (GetMessage (&msg, NULL, 0, 0))
  {
  TranslateMessage (&msg) ;
  DispatchMessage (&msg) ;
  }
  return msg.wParam ;
}

void PageGDICalls (HDC hdcPrn, int cxPage, int cyPage)
{
  static TCHAR szTextStr[] = TEXT ("Hello, Printer!") ;
   
  Rectangle (hdcPrn, 0, 0, cxPage, cyPage) ;
   
  MoveToEx (hdcPrn, 0, 0, NULL) ;
  LineTo (hdcPrn, cxPage, cyPage) ;
  MoveToEx (hdcPrn, cxPage, 0, NULL) ;
  LineTo (hdcPrn, 0, cyPage) ;
   
  SaveDC (hdcPrn) ;
   
  SetMapMode (hdcPrn, MM_ISOTROPIC) ;
  SetWindowExtEx (hdcPrn, 1000, 1000, NULL) ;
  SetViewportExtEx (hdcPrn, cxPage / 2, -cyPage / 2, NULL) ;
  SetViewportOrgEx (hdcPrn, cxPage / 2, cyPage / 2, NULL) ;
   
  Ellipse (hdcPrn, -500, 500, 500, -500) ;
   
  SetTextAlign (hdcPrn, TA_BASELINE | TA_CENTER) ;
  TextOut (hdcPrn, 0, 0, szTextStr, lstrlen (szTextStr)) ;
  RestoreDC (hdcPrn, -1) ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  static int cxClient, cyClient ;
  HDC hdc ;
  HMENU hMenu ;
  PAINTSTRUCT ps ;
   
  switch (message)
  {
  case WM_CREATE:
  hMenu = GetSystemMenu (hwnd, FALSE) ;
  AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
  AppendMenu (hMenu, 0, 1, TEXT ("&Print")) ;
  return 0 ;


   
  case WM_SIZE:
  cxClient = LOWORD (lParam) ;
  cyClient = HIWORD (lParam) ;
  return 0 ;
   
  case WM_SYSCOMMAND:
  if (wParam == 1)
  {
  if (!PrintMyPage (hwnd))
  MessageBox (hwnd, TEXT ("Could not print page!"),
  szAppName, MB_OK | MB_ICONEXCLAMATION) ;
  return 0 ;
  }
  break ;
   
  case WM_PAINT :
  hdc = BeginPaint (hwnd, &ps) ;
   
  PageGDICalls (hdc, cxClient, cyClient) ;
   
  EndPaint (hwnd, &ps) ;
  return 0 ;
   
  case WM_DESTROY :
  PostQuitMessage (0) ;
  return 0 ;
  }
  return DefWindowProc (hwnd, message, wParam, lParam) ;




[color=#FF0000][/color]
报错提示:
1>ClCompile:
1> 图形和文字.cpp
1>图形和文字.obj : error LNK2001: 无法解析的外部符号 "wchar_t * szCaption" (?szCaption@@3PA_WA)
1>图形和文字.obj : error LNK2001: 无法解析的外部符号 "struct HINSTANCE__ * hInst" (?hInst@@3PAUHINSTANCE__@@A)
1>图形和文字.obj : error LNK2001: 无法解析的外部符号 "wchar_t * szAppName" (?szAppName@@3PA_WA)
1>图形和文字.obj : error LNK2019: 无法解析的外部符号 "int __cdecl PrintMyPage(struct HWND__ *)" (?PrintMyPage@@YAHPAUHWND__@@@Z),该符号在函数 "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>F:\CODE\MFC\13-打印图形和文字\Debug\13-打印图形和文字.exe : fatal error LNK1120: 4 个无法解析的外部命令

[解决办法]
代码不全啊
是手工敲的么?
光盘里有源码的吧
[解决办法]
extern HINSTANCE hInst ;
extern TCHAR szAppName[] ;
extern TCHAR szCaption[] ;
-------------------
你这些都是在哪里定义的?
[解决办法]

C/C++ code
#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;BOOL PrintMyPage (HWND) ;HINSTANCE hInst ;TCHAR szAppName[] = TEXT("hello");  //TCHAR szCaption[] = TEXT("world");  // 初始化!!int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,    PSTR szCmdLine, int iCmdShow){    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) GetStockObject (WHITE_BRUSH) ;    wndclass.lpszMenuName = NULL ;    wndclass.lpszClassName = szAppName ;    if (!RegisterClass (&wndclass))    {        MessageBox (NULL, TEXT ("This program requires Windows NT!"),            szAppName, MB_ICONERROR) ;        return 0 ;    }    hInst = hInstance ;    hwnd = CreateWindow (szAppName, szCaption,        WS_OVERLAPPEDWINDOW,        CW_USEDEFAULT, CW_USEDEFAULT,        CW_USEDEFAULT, CW_USEDEFAULT,        NULL, NULL, hInstance, NULL) ;    ShowWindow (hwnd, iCmdShow) ;    UpdateWindow (hwnd) ;    while (GetMessage (&msg, NULL, 0, 0))    {        TranslateMessage (&msg) ;        DispatchMessage (&msg) ;    }    return msg.wParam ;}void PageGDICalls (HDC hdcPrn, int cxPage, int cyPage){    static TCHAR szTextStr[] = TEXT ("Hello, Printer!") ;    Rectangle (hdcPrn, 0, 0, cxPage, cyPage) ;    MoveToEx (hdcPrn, 0, 0, NULL) ;    LineTo (hdcPrn, cxPage, cyPage) ;    MoveToEx (hdcPrn, cxPage, 0, NULL) ;    LineTo (hdcPrn, 0, cyPage) ;    SaveDC (hdcPrn) ;    SetMapMode (hdcPrn, MM_ISOTROPIC) ;    SetWindowExtEx (hdcPrn, 1000, 1000, NULL) ;    SetViewportExtEx (hdcPrn, cxPage / 2, -cyPage / 2, NULL) ;    SetViewportOrgEx (hdcPrn, cxPage / 2, cyPage / 2, NULL) ;    Ellipse (hdcPrn, -500, 500, 500, -500) ;    SetTextAlign (hdcPrn, TA_BASELINE | TA_CENTER) ;    TextOut (hdcPrn, 0, 0, szTextStr, lstrlen (szTextStr)) ;    RestoreDC (hdcPrn, -1) ;}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){    static int cxClient, cyClient ;    HDC hdc ;    HMENU hMenu ;    PAINTSTRUCT ps ;    switch (message)    {    case WM_CREATE:        hMenu = GetSystemMenu (hwnd, FALSE) ;        AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;        AppendMenu (hMenu, 0, 1, TEXT ("&Print")) ;        return 0 ;    case WM_SIZE:        cxClient = LOWORD (lParam) ;        cyClient = HIWORD (lParam) ;        return 0 ;    case WM_SYSCOMMAND:        if (wParam == 1)        {            if (!PrintMyPage (hwnd))                MessageBox (hwnd, TEXT ("Could not print page!"),                szAppName, MB_OK | MB_ICONEXCLAMATION) ;            return 0 ;        }        break ;    case WM_PAINT :        hdc = BeginPaint (hwnd, &ps) ;        PageGDICalls (hdc, cxClient, cyClient) ;        EndPaint (hwnd, &ps) ;        return 0 ;    case WM_DESTROY :        PostQuitMessage (0) ;        return 0 ;    }    return DefWindowProc (hwnd, message, wParam, lParam) ;}//  这个方法你没有写。。。BOOL PrintMyPage (HWND hWnd){    return TRUE;} 


[解决办法]
咦?原来关于win32的这几篇帖子都是楼主发的。。吼吼!在学windows程序设计?

热点排行