首先打开vc++6.0,打开file菜单,建立一个win32 Application类型的工程。
然后用new对话框建立一个.c文件,键入下列程序,
编译,链接运行这个程序。
#include<windows.h>
INT PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,INT);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE myhlnst;
char szAppName[]="WinAPIDemo";
char szAppTitle[]="利用应用程序接口的windows应用程序";
INT PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,INT nCmdShow)
{HWND hMainwnd;
MSG message;
WNDCLASS myWC;
if(!hPrevInstance)
{ myWC.style=CS_HREDRAW|CS_VREDRAW;
myWC.lpfnWndProc=WndProc;
myWC.cbWndExtra=0;
myWC.hInstance=hInstance;
myWC.hIcon=LoadIcon(NULL,IDI_APPLICATION);
myWC.hCursor=LoadCursor(NULL,IDC_ARROW);
myWC.hbrBackground=BRUSH(GetStockObject(WHITE_BRUSH));
myWC.lpszMenuName=NULL;
myWC.lpszClassName=szAppName;
RegisterClass(&myWC);
}
hMainwnd=CreateWindow(
szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hMainwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hMainwnd);
while(GetMessage(&message,NULL,0,0))
{TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hMainwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{ char MsgLBTN[]="你刚按下鼠标左键!";
char MsgRBTN[]="你刚按下鼠标右键!";
switch(message)
{case WM_RBUTTONDOWN:
{MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFocus(),MsgRBTN,"Message",
MB_OK|MB_ICONINFORMATION);
break;
}
case WM_LBUTTONDOWN:
{MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFocus(),MsgLBTN,"Message",
MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{PostQuitMessage(0);
return 0;
}
default:break;
}
return DefWindowProc(hMainwnd,message,wParam,lParam);
}
问题是我怎么运行不了呢,出不来窗口,请大家指教。是不是要设置编程环境呢?
我vc++基础的看的差不多了,可一直都编的是dos的程序,我现在该从什么地方看起呢
[此贴子已经被作者于2006-2-10 15:57:01编辑过]