| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1124 人关注过本帖
标题:这个可是我们的老师都不知道的啊你知道吗?
取消只看楼主 加入收藏
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
 问题点数:0 回复次数:6 
这个可是我们的老师都不知道的啊你知道吗?
谁知道在VC++中只要有"WINDOWS.H"这个头文件在编译时没有错可是在执行时就有错误,是什么原因?
敬请高手指点一二
搜索更多相关主题的帖子: 老师 
2005-10-23 20:56
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
得分:0 
那你知道不?知道就说撒
2005-10-23 21:02
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
得分:0 
不是我的代码有问题啊
这是书上的例子
       已经做了5个不同的题都是这样的啊
在自己的电脑上是这样,在学校的机房也是这样哦
2005-10-23 21:34
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
得分:0 

这是课本的API程序。就是它了: #include<windows.h> #include<stdlib.h> #include<string.h> LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage, UINT wParam,LONG lParam); BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MSG Message; if(! InitWindowsClass(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) { static long nXChar,nCaps,nYChar; HDC hDC; short x; TEXTMETRIC tm; short LnCount=6; PAINTSTRUCT PtStr; static char *textbuf[]= { "This is the first line", "This is the second line", "This is the third line", "This is the fourth line", "this is the fifth line", "this is the sixth line" }; switch(iMessage) { case WM_CREATE: hDC=GetDC(hWnd); GetTextMetrics(hDC,&tm); nXChar=tm.tmAveCharWidth; nYChar=tm.tmHeight+tm.tmExternalLeading; ReleaseDC(hWnd,hDC); return 0; case WM_PAINT: hDC=BeginPaint(hWnd,&PtStr); for( x=0;x<LnCount;x=x+1) TextOut(hDC,nXChar,nYChar*(1+x),textbuf[x],lstrlen(textbuf[x])); EndPaint(hWnd,&PtStr); return 0;

case WM_DESTROY: PostQuitMessage(0); return 0; default: return (DefWindowProc(hWnd,iMessage,wParam,lParam)); } } BOOL InitWindowsClass(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,"END"); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName="WinText"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(&WndClass); } BOOL InitWindows (HINSTANCE hInstance,int nCmdShow) { HWND hWnd; hWnd=CreateWindow("WinText", "文本显示例程序", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (! hWnd) return FALSE; ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE; }

2005-10-26 23:00
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
得分:0 

另外还有: #include<windows.h> #include<stdlib.h> #include<string.h> BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTANCE hInstance,int nCmdShow); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdline,int nCmdShow) { MSG Message; if(! InitWindowsClass(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) { WORD x,y; HCURSOR hCursor; switch(iMessage) { case WM_MOUSEMOVE: x=LOWORD(lParam); y=HIWORD(lParam); if (x>=50&&x<=400&&y>=50&&y<=300) { if (x>=50&&x<=100&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_CROSS); SetCursor(hCursor); }

if (x>=150&&x<=2000&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_HELP); SetCursor(hCursor); } if (x>=50&&x<=100&&y>=100&&y<=150) { hCursor=LoadCursor(NULL,IDC_SIZENESW); SetCursor(hCursor); } if (x>=100&&x<=250&&y>=100&&y<=150) { hCursor=LoadCursor(NULL,IDC_SIZENS); SetCursor(hCursor); } if (x>=250&&x<=400&&y>=100&&y<=150) { hCursor=LoadCursor(NULL,IDC_SIZENWSE); SetCursor(hCursor); } if (x>=100&&x<=150&&y>=150&&y<=300) { hCursor=LoadCursor(NULL,IDC_SIZEWE); SetCursor(hCursor); } if (x>=100&&x<=250&&y>=150&&y<=300) { hCursor=LoadCursor(NULL,IDC_UPARROW); SetCursor(hCursor); } if (x>=250&&x<=400&&y>=150&&y<=300) { hCursor=LoadCursor(NULL,IDC_WAIT); SetCursor(hCursor); } /*if (x>=100&&x<=150&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_SIZEALL); SetCursor(hCursor); } if (x>=100&&x<=150&&y>=50&&y<=100) { hCursor=LoadCursor(NULL,IDC_SIZEALL); SetCursor(hCursor); }*/ } else { hCursor=LoadCursor(NULL,IDC_ARROW); SetCursor(hCursor); } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return(DefWindowProc(hWnd,iMessage,wParam,lParam)); }

}

BOOL InitWindowProc(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,"END"); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName="WinMouse"; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(&WndClass); }

BOOL InitWindoews(HINSTANCE hInstance,int nCmdShow) { HWND hWnd; hWnd=CreateWindow("WinMouse", "鼠标及光标形状设置及示例", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if(! hWnd) return FALSE; ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE; }

2005-10-26 23:02
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
得分:0 
"stdafx.h"这个文件怎么建哪!能不能发过来我瞧瞧哦
2005-11-03 23:35
zh672903
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-10-2
收藏
得分:0 
各位老大!不管怎样,我都得谢谢您们.我编译的时候是直接在C++ Source File里写的,然后直接编译,就是这些步骤了,我根本没有管什么win32,是不是有点傻?首先,我是在c++程序设计的基础上学习vc++面向对象与可视化程序设计的.看了各位老大的建议,我回去试试.再次感谢
2005-11-11 22:07
快速回复:这个可是我们的老师都不知道的啊你知道吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018277 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved