读书人

vc sdk编程遇到的小疑点。单步调试到注

发布时间: 2012-09-13 09:51:52 作者: rapoo

vc sdk编程遇到的小问题。。单步调试到注册类的时候弹出。。

C/C++ code
#include <windows.h>#include <stdio.h>LRESULT CALLBACK WindowProc(                            HWND hwnd,      // handle to window                            UINT uMsg,      // message identifier                            WPARAM wParam,  // first message parameter                            LPARAM lParam   // second message parameter                            );int WINAPI WinMain(  HINSTANCE hInstance,      // handle to current instance                   HINSTANCE hPrevInstance,  // handle to previous instance                   LPSTR lpCmdLine,          // command line                   int nCmdShow              // show state                   ){    WNDCLASS wndcls;    wndcls.cbClsExtra=0;    wndcls.cbWndExtra=0;    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);    wndcls.hCursor=LoadCursor(NULL,IDC_IBEAM);    wndcls.hIcon=LoadIcon(NULL,IDI_EXCLAMATION);    wndcls.hInstance=hInstance;    wndcls.lpfnWndProc=WindowProc;    wndcls.lpszClassName=TEXT("tom");    wndcls.style=CS_HREDRAW|CS_VREDRAW;    RegisterClass(&wndcls);    HWND hWnd;    hWnd=CreateWindow(TEXT("tom"),"MyFirstWin32SDKProgram",WS_OVERLAPPED,200,153,600,400,NULL,NULL,hInstance,NULL);    ShowWindow(hWnd,SW_SHOWNORMAL);    UpdateWindow(hWnd);    MSG msg;    while(GetMessage(&msg,NULL,0,0))    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return 0;}LRESULT CALLBACK WindowProc(                            HWND hwnd,      // handle to window                            UINT uMsg,      // message identifier                            WPARAM wParam,  // first message parameter                            LPARAM lParam   // second message parameter                            ){    HDC hDC;    PAINTSTRUCT ps;    switch(uMsg)    {    case WM_PAINT:        hDC=BeginPaint(hwnd,&ps);        TextOut(hDC,0,0,"Hello WIN32 SDK",strlen("Hello WIN32 SDK"));        EndPaint(hwnd,&ps);        break;    case WM_CHAR:        char szChar[20];        sprintf(szChar,"The char you entered is %c",wParam);        MessageBox(hwnd,"Hello WIN32 SDK","Message",0);        break;    case WM_LBUTTONDOWN:        MessageBox(hwnd,"You've Clicked the LButton!","Message",MB_ABORTRETRYIGNORE);        break;    case WM_DESTROY:        if(IDYES==MessageBox(hwnd,"Are you sure to quit?","Message",MB_OKCANCEL))            DestroyWindow(hwnd);        break;    case WM_QUIT:        PostQuitMessage(0);        break;    default:        DefWindowProc(hwnd,uMsg,wParam,lParam);    }    return 0;    }

看不到窗口。。。单步调试到RegisterClass的时候会报错(记不清楚了,大概是访问非法)
求各位帮我分析一下原因,我不保证我的代码写正确了。。。谢谢大家 急

[解决办法]
C/C++ code
default:        return DefWindowProc(hwnd,uMsg,wParam,lParam); 

读书人网 >C++

热点推荐