这是我编写的Hellowwindows程序,但有问题运行不了
#include<windows.h>
#include<string>
#include<stdio.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//入口函数
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR
lpCmdLine,int nCmdShow)
{
WNDCLASS wndclass;
HWND hwnd;
MSG msg;
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 = "windows窗口创建";
if(! RegisterClass(&wndclass))
return FALSE;
hwnd = CreateWindow("window窗口创建","window窗口创建",
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)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd,&ps);
TextOut(hdc,10,20,"哈哈,Windows编程创建的窗口!",28EndPaint (hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd,message,wParam,lParam );
}
但是按下F7后出现了这个结果,再按下F5后没有窗口出现,但查看资源管理器时有后台的.exe程序运行,为什么?我用的是VS2010的C++,如果有高手,再详细说一下创建项目的步骤,谢谢了
1>------ Build started: Project: windows1, Configuration: Debug Win32 ------
1>Build started 2012/5/25 18:00:20.
1>InitializeBuildStatus:
1> Creating "Debug\windows1.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> windows.cpp
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Manifest:
1> All outputs are up-to-date.
1>LinkEmbedManifest:
1> All outputs are up-to-date.
1> windows1.vcxproj -> C:\Users\windy\Documents\Visual Studio 2010\Projects\windows1\Debug\windows1.exe
1>FinalizeBuildStatus:
1> Deleting file "Debug\windows1.unsuccessfulbuild".
1> Touching "Debug\windows1.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:20.15
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
但是按下F7后出现了这个结果,再按下F5后没有窗口出现,但查看资源管理器时有后台的.exe程序运行,为什么?我用的是VS2010的C++,如果有高手,再详细说一下创建项目的步骤,谢谢了
[解决办法]
- C/C++ code
#include<windows.h>#include<string>#include<stdio.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);//入口函数int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){ WNDCLASS wndclass; HWND hwnd; MSG msg; 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 = TEXT("windows窗口创建"); if(! RegisterClass(&wndclass)) return FALSE; hwnd = CreateWindow(wndclass.lpszClassName, TEXT("window窗口创建"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL, hInstance, NULL); DWORD dwERR = GetLastError(); 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){ HDC hdc; PAINTSTRUCT ps; switch (message) { case WM_CREATE: return 0; case WM_PAINT: hdc = BeginPaint (hwnd,&ps); TextOut(hdc,10,20,TEXT("哈哈,Windows编程创建的窗口!"),28); EndPaint (hwnd,&ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd,message,wParam,lParam );}
[解决办法]
我以为是 Hello world 呵呵。。。。。。。
