回 帖 发 新 帖 刷新版面

主题:一个hello world怎么回事

#include <windows.h>

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

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT ("HelloWin") ;
    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 ;
     }
    hwnd = CreateWindow( szAppName,    // window class name
            TEXT ("The Hello Program"),    // window caption
            WS_OVERLAPPEDWINDOW,    // window style
            CW_USEDEFAULT,    // initial x position
            CW_USEDEFAULT,    // initial y position
            CW_USEDEFAULT,    // initial x size
            CW_USEDEFAULT,    // initial y size
            NULL,            // parent window handle
            NULL,            // window menu handle
            hInstance,        // program instance handle
            NULL) ;         // creation parameters
     
    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)
{
    HDC            hdc ;
    PAINTSTRUCT ps ;
    RECT        rect ;
     
    switch (message)
     {
    case WM_CREATE:
    case     WM_PAINT:
        hdc = BeginPaint (hwnd, &ps) ;
          
        GetClientRect (hwnd, &rect) ;
          
        DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
            DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
              EndPaint (hwnd, &ps) ;
            return 0 ;
          
    case    WM_DESTROY:
        PostQuitMessage (0) ;
        return 0 ;
     }
   return DefWindowProc (hwnd, message, wParam, lParam) ;
}


程序有问题吗?
怎么编译会有这样的问题

--------------------Configuration: bb - Win32 Debug--------------------
Compiling...
bb.cpp
F:\临时项目\abcd\bb.cpp(21) : error C2039: 'lpszMenuName' : is not a member of 'tagWNDCLASSA'
        c:\program files\microsoft visual studio\vc98\include\winuser.h(1184) : see declaration of 'tagWNDCLASSA'
Error executing cl.exe.

bb.exe - 1 error(s), 0 warning(s)

回复列表 (共9个回复)

沙发

天那~
搞什么啊

我点开那个winusr.h那个里面

发现我的VC里面是这样的
typedef struct tagWNDCLASSA
{
    UINT         style ;
    WNDPROC         lpfnWndProc ;
    int          cbClsExtra ;
    int             cbWndExtra ;
    HINSTANCE      hInstance ;
    HICON           hIcon ;
    HCURSOR      hCursor ;
    HBRUSH          hbrBackground ;
     LPCSTR       lpszClassName ;
}
WNDCLASSA, * PWNDCLASSA, NEAR * NPWNDCLASSA, FAR * LPWNDCLASSA ;


少了一个LPCSTR       lpszMenuName ;我填加进去以后居然又出现了这样的问题


--------------------Configuration: bb - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/bb.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

bb.exe - 2 error(s), 0 warning(s)

天那~怎么办?
太打击一个新手了吧

板凳

工程类型错误,你创建的是控制台应用程序,入口点是main
但现在你的代码是WIN32应用程序的代码.入口点应该是WinMain.

3 楼

typedef struct tagWNDCLASSA {
    UINT        style;
    WNDPROC     lpfnWndProc;
    int         cbClsExtra;
    int         cbWndExtra;
    HINSTANCE   hInstance;
    HICON       hIcon;
    HCURSOR     hCursor;
    HBRUSH      hbrBackground;
    LPCSTR      lpszMenuName;
    LPCSTR      lpszClassName;
} WNDCLASSA, *PWNDCLASSA, NEAR *NPWNDCLASSA, FAR *LPWNDCLASSA;

我的WINUSER.H

4 楼

typedef struct _WNDCLASS { 
    UINT    style; 
    WNDPROC lpfnWndProc; 
    int     cbClsExtra; 
    int     cbWndExtra; 
    HANDLE  hInstance; 
    HICON   hIcon; 
    HCURSOR hCursor; 
    HBRUSH  hbrBackground; 
    LPCTSTR lpszMenuName; 
    LPCTSTR lpszClassName; 
} WNDCLASS; 
 
MSDN里的

5 楼

lpszMenuName 
Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have no default menu. 

6 楼

大家不要上MS的当阿,一个简单的hello world 需要那么多的东西吗
简简单单的就OK了
============================================================================
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,
         LPSTR lpCmdLine,int nShowCmd)
{
    MessageBox(NULL,TEXT("hello world !"),TEXT("NOTICE "),0);
}
============================================================================

要是实在要弄个窗口出来也行,楼主你贴出来的东西是没有错误的,就像2楼说的是工程类型错误

7 楼

因业务需要招聘外挂破解技术员 
人员:    2名-3名
项目:    网络游戏外挂
项目资料:海外网络游戏,无风险,不牵扯法律责任。
          支持当面交易.
工作地点:SOHO
工作待遇:详谈
要求 能独立完成软件加密解密
     精通软件软件逆向分析工程、软件汇编/反汇编分析
     精通系统底层(API)开发、调试/反调试技术
     精通网络通讯协议分析与开发,熟悉网络游戏通过协议及架构
     熟练掌握VC、ASM、VB编程语言中任意一种
     有能力的请与我联系 寻求可以长期合作的
     可将您的个人简历和联系方式投放 EMAI: jiaxinwb@163.com

8 楼

这是书的一个例子

9 楼

基本的程序框架拷过来用就行了,我们要做的只是填空,填上我们想要的就行了。哦,这可不是学C语言!!

我来回复

您尚未登录,请登录后再回复。点此登录或注册