VC++运行看不到窗口,简单的windows程序,高手看看,问题解决了有高分
//基于消息响应机制//关于设置:设置->连接->sun#include"windows.h"#include"stdio.h"LRESULTCALLBACKWinSun...
//基于消息响应机制
//关于设置:设置->连接->sun
#include"windows.h"
#include"stdio.h"
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,//当前的实例句柄
HINSTANCE hPrevInstance,//先前的一个实例句柄、假设没有的话究是空
LPSTR lpCmdLine,//长指针,命令行参数
int nCmdShow //显示方式.如是最大化.不显示..
)
{
//设计一个窗口类WNDCLASS style
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW; //窗口显示类型
wndclass.lpfnWndProc=WinSunProc; //回调函数
wndclass.cbClsExtra=0; //附加参数
wndclass.cbWndExtra=0; //附加参数
wndclass.hInstance=hInstance; //代表当前的实例号
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR); //图标句柄,指示窗口左上角的那个小图标
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS); //光标句柄,在应用程序窗口中的光标
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);// 窗口背景
wndclass.lpszMenuName="Hello" ; //类名
wndclass.lpszClassName=NULL; //窗口所用的菜单
wndclass.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
//注册窗口类
RegisterClass(&wndclass);
//创建窗口
HWND hwnd;
hwnd=CreateWindow("Hello","标题栏", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInstance,NULL);//里面的各个参数就不多说了,看MSDN
//显示窗口更新窗口
ShowWindow(hwnd,SW_SHOWNORMAL); //显示
UpdateWindow(hwnd); //更新
//消息循环
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{case WM_CHAR:
char a[10];
sprintf(a,"CHAR IS %d",wParam);
MessageBox(hwnd,a,"hello",MB_OKCANCEL);
break;
case WM_CLOSE:
DestroyWindow(hwnd); //销毁窗口
break;
case WM_DESTROY:
PostQuitMessage(0); //反回一个WM_QUIT消息,getmessage得到的是WM_QUIT的时
//候就返回0就可以退出消息循环
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
调试的时候调试信息:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found. 展开
//关于设置:设置->连接->sun
#include"windows.h"
#include"stdio.h"
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,//当前的实例句柄
HINSTANCE hPrevInstance,//先前的一个实例句柄、假设没有的话究是空
LPSTR lpCmdLine,//长指针,命令行参数
int nCmdShow //显示方式.如是最大化.不显示..
)
{
//设计一个窗口类WNDCLASS style
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW; //窗口显示类型
wndclass.lpfnWndProc=WinSunProc; //回调函数
wndclass.cbClsExtra=0; //附加参数
wndclass.cbWndExtra=0; //附加参数
wndclass.hInstance=hInstance; //代表当前的实例号
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR); //图标句柄,指示窗口左上角的那个小图标
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS); //光标句柄,在应用程序窗口中的光标
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);// 窗口背景
wndclass.lpszMenuName="Hello" ; //类名
wndclass.lpszClassName=NULL; //窗口所用的菜单
wndclass.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
//注册窗口类
RegisterClass(&wndclass);
//创建窗口
HWND hwnd;
hwnd=CreateWindow("Hello","标题栏", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInstance,NULL);//里面的各个参数就不多说了,看MSDN
//显示窗口更新窗口
ShowWindow(hwnd,SW_SHOWNORMAL); //显示
UpdateWindow(hwnd); //更新
//消息循环
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{case WM_CHAR:
char a[10];
sprintf(a,"CHAR IS %d",wParam);
MessageBox(hwnd,a,"hello",MB_OKCANCEL);
break;
case WM_CLOSE:
DestroyWindow(hwnd); //销毁窗口
break;
case WM_DESTROY:
PostQuitMessage(0); //反回一个WM_QUIT消息,getmessage得到的是WM_QUIT的时
//候就返回0就可以退出消息循环
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
调试的时候调试信息:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询