#include<windows.h>
INT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
char szClassName[]="windowclass1";
char szAppTitle[]="chen";
INT PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,INT nCmdShow)
{
HWND hMainWnd;
MSG msg;
WNDCLASS myWC;
if(!hPrevInstance)
{
myWC.style=CS_HREDRAW|CS_VREDRAW;
myWC.lpfnWndProc=WndProc;
myWC.cbClsExtra=0;
myWC.cbWndExtra=0;
myWC.hInstance=hInstance;
myWC.hIcon=LoadIcon(NULL,IDI_APPLICATION);
myWC.hCursor=LoadCursor(NULL,IDC_ARROW);
myWC.hbrBackground=GetStockObject(WHITE_BRUSH);
myWC.lpszMenuName=NULL;
myWC.lpszClassName=szClassName;
}
hMainWnd=CreateWindow(
szClassName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hMainWnd,SW_SHOWMAXIMIZED);
UpdateWindow(hMainWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
INT CALLBACK WndProc(HWND hMainwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
char messageleft[]="the left button have been pushed";
char messageright[]="the right button have been pushed";
switch(message)
{
case WM_RBUTTONDOWN:
{
MessageBox(GetFocus(),messageright,"chen",MB_OK|MB_ICONINFORMATION);
break;
}

case WM_LBUTTONDOWN:
{
MessageBox(GetFocus(),messageleft,"chen",MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
break;
}
return DefWindowProc(hMainwnd,message,wParam,lParam);
}
Configuration: progect4 - Win32 Debug--------------------
Compiling...
4.1.cpp
F:\software C++ 6.0\C++ Book 6.0\progect4\4.1.cpp(13) : error C2440: '=' : cannot convert from 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\software C++ 6.0\C++ Book 6.0\progect4\4.1.cpp(19) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Error executing cl.exe.4.1.obj - 2 error(s), 0 warning(s)

解决方案 »

  1.   

    不是 INT CALLBACK WndProc
    long WINAPI WndProc#define CALLBACK    __stdcall
    #define WINAPI      __stdcall
    #define WINAPIV     __cdecl
    #define APIENTRY    WINAPI
    #define APIPRIVATE  __stdcall
    #define PASCAL      __stdcall
    yong WINAPI 
      

  2.   

    LRESULT CALLBACK WndProc(HWND hMainwnd,UINT message,WPARAM wParam,LPARAM lParam)
      

  3.   

    再学习下孙鑫的视频,模拟MFC窗口的启动过程。