vc显示窗口问题
来源:百度知道 编辑:UC知道 时间:2024/05/10 04:38:18
小弟我初学windows编程,以下是我几乎照着例子打的一个程序,但始终不能显示窗口。
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInst,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
WNDCLASS wwindow;
wwindow.cbClsExtra=0;
wwindow.cbWndExtra=0;
wwindow.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wwindow.hCursor=LoadCursor(NULL,IDC_ARROW);
wwindow.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wwindow.hInstance=hInst;
wwindow.lpszClassName="qqqq";
wwindow.lpszMenuName=NULL;
wwindow.style=CS_VREDRAW|CS_HREDRAW;
wwindow.lpfnWndProc=WindowProc;
RegisterClass(&wwindow);
HWND hwnd;
hwnd=CreateWindow("qqqq","标题",WS_OVERLAPPEDWIN
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInst,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
WNDCLASS wwindow;
wwindow.cbClsExtra=0;
wwindow.cbWndExtra=0;
wwindow.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wwindow.hCursor=LoadCursor(NULL,IDC_ARROW);
wwindow.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wwindow.hInstance=hInst;
wwindow.lpszClassName="qqqq";
wwindow.lpszMenuName=NULL;
wwindow.style=CS_VREDRAW|CS_HREDRAW;
wwindow.lpfnWndProc=WindowProc;
RegisterClass(&wwindow);
HWND hwnd;
hwnd=CreateWindow("qqqq","标题",WS_OVERLAPPEDWIN
default:DefWindowProc(hwnd,uMsg,wParam,lParam);
改为
default: return DefWindowProc(hwnd,uMsg,wParam,lParam);
因为在Create窗口时,你返回的是0
在Createwindow时,会发送WM_CREATE消息,DefWindowProc会根据处理消息的结果返回不同的值,这个值会通过某种途径变为窗口的地址作为CreateWindow的返回值,那么你返回0,hwnd没有得到应该有的值,后面的
ShowWindow
和
UpdateWindow也就失败了
主函数的返回类型值不是为0,不知道是msg.wParam还是msglParam,你试下.
io
托控件多方便。何必自己敲代码呢?