#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//窗口说明
//--------------以下初始化窗口类-------------
int WINAPI WinMain(HINSTANCE hInstance, //winmain函数说明
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="My-windows";
wndclass.style=0; //窗口类型为默认类型
wndclass.lpfnWndProc = WndProc;//窗口处理函数为WndProc
wndclass.cbClsExtra=0; //窗口类无扩展
wndclass.cbWndExtra=0; //窗口实例无扩展
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);//为什么说这里是不合法的类型转换?
wndclass.lpszClassName=lpszClassName;
//---------------以下进行窗口类的注册---------------------
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName, //窗口类名
lpszTitle, //窗口标题
WS_OVERLAPPEDWINDOW, //窗口的风格
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口左上脚坐标为默认
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口的高和宽为默认值
NULL, //无父窗口
NULL, //无主菜单
hInstance, //应用程序的当前句柄
NULL); //不使用该值
//显示窗口
ShowWindow(hwnd,nCmdShow);
//绘制用户区
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)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);//调用PostQuitMessage发出WM_QUIT消息
default: //默认时采用系统消息默认处理函数
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}
请各位前辈指点一二,谢谢。
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//窗口说明
//--------------以下初始化窗口类-------------
int WINAPI WinMain(HINSTANCE hInstance, //winmain函数说明
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口";
char lpszTitle[]="My-windows";
wndclass.style=0; //窗口类型为默认类型
wndclass.lpfnWndProc = WndProc;//窗口处理函数为WndProc
wndclass.cbClsExtra=0; //窗口类无扩展
wndclass.cbWndExtra=0; //窗口实例无扩展
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);//为什么说这里是不合法的类型转换?
wndclass.lpszClassName=lpszClassName;
//---------------以下进行窗口类的注册---------------------
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(lpszClassName, //窗口类名
lpszTitle, //窗口标题
WS_OVERLAPPEDWINDOW, //窗口的风格
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口左上脚坐标为默认
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口的高和宽为默认值
NULL, //无父窗口
NULL, //无主菜单
hInstance, //应用程序的当前句柄
NULL); //不使用该值
//显示窗口
ShowWindow(hwnd,nCmdShow);
//绘制用户区
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)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);//调用PostQuitMessage发出WM_QUIT消息
default: //默认时采用系统消息默认处理函数
return DefWindowProc(hwnd,message,wParam,lParam);
}
return (0);
}
请各位前辈指点一二,谢谢。
解决方案 »
- 怎么用GetPrivateProfileString获取ini里多行数据?
- GDI+ Pen TextureBrush问题?
- 高分求助,郁闷了好久!见内容
- winInet 使用post 方法的奇怪问题
- 为什么用HtmlHelp函数调出Context Help窗口,再点击对话框其它部分,使弹出的窗口消失,只要一点击就会报错??
- 好久没来了,有认识偶的吗. 顺便散分送礼
- 请教一下那里可以找到关于链表类及其使用的文章vc下的!
- 如何解决这两个WARING 和ERROR? 编译问题~各25分
- 谁用过iphlpapi库中的函数SendARP这个函数!
- 消息传递问题,路过请进来帮忙看看
- 散分!100
- 关于基于API的串行通信,急!在线
好像这个错误常有人出!
其它的错误别人已经指出来了。
我这个方法实现了你的程序。
如果你还没有实现的话,可以发E_MAIL给我。我帮你哟!
[email protected]。
我按照你们说的把错误修改了,编译是通过了,但是link的时候出错了,错误是这样的:
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/myproj.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
应该是说没有主函数吧?怎样才能在我得机器上生成一个窗口呢?
CreateWindow(……)就是创建windows窗口了
ShowWindow(……)则是显示它
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable; // Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_NT2, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance); // Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_NT2); // Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return msg.wParam;
}//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_NT2);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_NT2;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);
}//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd)
{
return FALSE;
} ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd); return TRUE;
}//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE; case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
这个自动帮你生成的。不过API确实是一个比较烦的东西,刚开始可能会一天才啃俩页,
还会不知其所以然,慢慢的结合MFC就能了解深刻了,
期望楼主的毅力!