Win32 Application 应用程序怎么不显示窗口??

pengcao89 2010-05-06 11:05:45
#include<windows.h>
#include<stdlib.h>
#include<string.h>

BOOL IintWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);

HFONT CreateFont(HDC hDc,int nCharHeight,BOOL bItalic);

int i=0;
int x[11],y[11];
int color[11];
POINT pt;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
MSG Message;
if (!IintWindowsClass(hInstance))
return FALSE;
if (!InitWindows(hInstance,nCmdShow))
return FALSE;
while (GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
HDC hDC;
HFONT hF;
PAINTSTRUCT ps;
TEXTMETRIC tm;
char str[]="Hello VC";
switch (iMessage)
{
case WM_CREATE:
SetTimer(hWnd,1,40,NULL);
GetCursorPos(&pt);
for (i=0;i<11;i++)
{
x[i]=pt.x;
y[i]=pt.y;
color[i]=25*(i-1);
}
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
hF=CreateFont(hDC,40,0);
SelectObject(hDC,hF);
GetTextMetrics(hDC,&tm);
for (i=10;i>1;i--);
{
x[i]=x[i-1]+50;
y[i]=y[i-1];
}
GetCursorPos(&pt);
x[1]=pt.x;
y[1]=pt.y;
for (i=1;i<11;i++)
{
SetTextColor(hDC,RGB(255-color[1],color[i],255));
TextOut(hDC,x[i],y[i],&str[i],1);
}
color[1]=color[0];
for(i=10;i>1;i--)
color[i]=color[i-1];
DeleteObject(hF);
EndPaint(hWnd,&ps);
return 0;
case WM_TIMER:
InvalidateRect(hWnd,NULL,1);
break;
case WM_DESTROY:
PostQuitMessage(0);
KillTimer(hWnd,1);
return 0;
default:
return (DefWindowProc(hWnd,iMessage,wParam,lParam));
}
return 0;
}

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("键盘-鼠标综合应用示例",
"Mouse Text Application",
WS_OVERLAPPEDWINDOW,
0,
0,
800,
600,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}


BOOL IintWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="键盘-鼠标综合应用示例";
wndclass.lpszMenuName=NULL;
wndclass.style=0;
return RegisterClass(&wndclass);
}

HFONT CreateFont(HDC hDC,int nCharHeight,BOOL bItalic)
{
HFONT hFont;
hFont=CreateFont(nCharHeight,
0,
0,
0,
400,
bItalic,
0,
0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
OUT_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"Arial");
if(hFont==NULL)
return FALSE;
else
return hFont;

}



代码如上面所示..刚刚开始接触这个东西..只要按照书上的一步一步的将代码敲下来..编译连接都成功了.
可是竟然不显示窗口..不知道 怎么修改...
还请 大虾们多多帮帮忙a..
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dskit 2010-05-06
  • 打赏
  • 举报
回复

#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);

HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京维新科学技术培训中心",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);

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, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"维新培训",strlen("维新培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧