社区
网络编程
帖子详情
有关Win32的问题
bill_li
2004-12-23 12:51:28
我才学不久,老师给了两个作业题,我不太明白,所以问问大家了。
1。创建2个编译框和一个静态文本框,以及一个“计算”按纽。用户在2个编译框中输入数字,然后单击“计算”,在静态文本框中显示求和结果。
在里面我不太会 “在静态文本框中显示求和结果”。
2。编一个程序,绘制一个五角星,五角星用红线绘制,显示在屏幕的中间,五角星的边取客户区宽度和高度最小值。
我不明白“五角星”怎么编 “五角星的边取客户区宽度和高度最小值。”怎么取。
...全文
137
9
打赏
收藏
有关Win32的问题
我才学不久,老师给了两个作业题,我不太明白,所以问问大家了。 1。创建2个编译框和一个静态文本框,以及一个“计算”按纽。用户在2个编译框中输入数字,然后单击“计算”,在静态文本框中显示求和结果。 在里面我不太会 “在静态文本框中显示求和结果”。 2。编一个程序,绘制一个五角星,五角星用红线绘制,显示在屏幕的中间,五角星的边取客户区宽度和高度最小值。 我不明白“五角星”怎么编 “五角星的边取客户区宽度和高度最小值。”怎么取。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
bill_li
2005-01-10
打赏
举报
回复
#include <windows.h>
#include <stdio.h>
#include <math.h>
#define MAX_NUM 10000
#define PANE_CONS 100
#define PI 3.1415927
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
static TCHAR szAppName[]=TEXT("RectSample");
static TCHAR szClassName[]=TEXT("RectSampleClass");
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
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=szClassName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program requires WinNT or higher version!"),
szAppName,MB_ICONERROR);
return 0;
}
hWnd=CreateWindow(
szClassName,
TEXT("Drawing Line Funtion Sample"),
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 Msg,WPARAM wParam,LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
static int cxClient,cyClient; //记录用户区宽度和高度
static double dblTheta0=0,nOuterRadius=0,nInnerRadius;
static POINT ptOuter[5],ptInner[5],pt[3];
int i;
static HPEN hpnBlue,hpnOld; //画笔句柄
static HBRUSH hbrRed,hbrOld; //画刷句柄
switch(Msg)
{
case WM_CREATE:
//创建逻辑画笔,实线,3个象素,兰色
hpnBlue=CreatePen(PS_SOLID,3,RGB(0,0,255));
hbrRed=CreateSolidBrush(RGB(255,0,0));
return 0;
case WM_SIZE:
//获取用户区大小
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
nOuterRadius=cxClient<cyClient?cxClient/4.0:cyClient/4.0;
nInnerRadius=nOuterRadius*sin(PI/10)/sin(PI*7/10);
//求点
for(i=0;i<5;i++)
{
ptOuter[i].x=(int)(cxClient/2+nOuterRadius*cos(dblTheta0+PI/2+PI*2*i/5));
ptOuter[i].y=(int)(cyClient/2-nOuterRadius*sin(dblTheta0+PI/2+PI*2*i/5));
ptInner[i].x=(int)(cxClient/2+nInnerRadius*cos(dblTheta0+PI*3/10+PI*2*i/5));
ptInner[i].y=(int)(cyClient/2-nInnerRadius*sin(dblTheta0+PI*3/10+PI*2*i/5));
}
return 0;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
//将hpnRed、hbrBlue选入设备描述表
hpnOld=(HPEN)SelectObject(hDC,hpnBlue);
hbrOld=(HBRUSH)SelectObject(hDC,hbrRed);
for(i=0;i<5;i++)
{
pt[0].x=cxClient/2;
pt[0].y=cyClient/2;
pt[1].x=ptInner[i].x;
pt[1].y=ptInner[i].y;
pt[2].x=ptOuter[i].x;
pt[2].y=ptOuter[i].y;
Polygon(hDC,pt,3);
}
SelectObject(hDC,hbrOld);
for(i=0;i<5;i++)
{
pt[0].x=cxClient/2;
pt[0].y=cyClient/2;
pt[1].x=ptInner[i+1-(i+1)/5*5].x;
pt[1].y=ptInner[i+1-(i+1)/5*5].y;
pt[2].x=ptOuter[i].x;
pt[2].y=ptOuter[i].y;
Polygon(hDC,pt,3);
}
Arc(hDC,cxClient/2-(int)nOuterRadius,cyClient/2-(int)nOuterRadius,
cxClient/2+(int)nOuterRadius,cyClient/2+(int)nOuterRadius,
cxClient/2-(int)nOuterRadius,cyClient/2-(int)nOuterRadius,
cxClient/2-(int)nOuterRadius,cyClient/2-(int)nOuterRadius);
//还原系统默认的画笔、画刷
SelectObject(hDC,hpnOld);
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
//删除不再使用的逻辑画笔
DeleteObject(hpnBlue);
DeleteObject(hbrRed);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
bill_li
2005-01-10
打赏
举报
回复
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define ID_EDIT1 1
#define ID_EDIT2 2
#define ID_STDC1 3
#define ID_STDC2 4
#define ID_STDC3 5
#define ID_COMPT 6
#define ID_CLOSE 7
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpcmdLine, int nCmdShow)
{
static TCHAR szAppName[] = TEXT("Compute");
static TCHAR szClassName[] = TEXT("ComputeClass");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
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 = szClassName;
if ( !RegisterClass( &wndclass ) )
{
MessageBox( NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR );
return 0;
}
hwnd = CreateWindow( szClassName, TEXT("Simple Computation Program"),
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)
{
static HWND hwndEdit1,hwndEdit2;
int cxChar,cyChar;
static HWND hwndStatic1,hwndStatic2,hwndStatic3;
static HWND hwndCmmdBt1,hwndCmmdBt2;
static int cxClient,cyClient;
static int cWinWidth,cWinHeight;
TCHAR szOper1[]=TEXT(" ");
static TCHAR szOper2[]=TEXT("");
TCHAR szReslt[]="";
float fReslt;
HDC hdc;
// PAINTSTRUCT ps;
TEXTMETRIC tm;
switch( message )
{
case WM_CREATE:
hwndEdit1 = CreateWindow( TEXT("edit"), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | ES_LEFT,
0, 0, 0, 0, hwnd, (HMENU) ID_EDIT1,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
hwndEdit2 = CreateWindow( TEXT("edit"), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | ES_LEFT,
0, 0, 0, 0, hwnd, (HMENU) ID_EDIT2,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
hwndStatic1 = CreateWindow( TEXT("static"), NULL,
WS_CHILD | WS_VISIBLE | SS_CENTER,
0, 0, 0, 0, hwnd, (HMENU) ID_STDC1,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
hwndStatic2 = CreateWindow( TEXT("static"), NULL,
WS_CHILD | WS_VISIBLE | SS_CENTER,
0, 0, 0, 0, hwnd, (HMENU) ID_STDC2,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
hwndStatic3 = CreateWindow( TEXT("static"), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER,
0, 0, 0, 0, hwnd, (HMENU) ID_STDC3,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
hwndCmmdBt1 = CreateWindow( TEXT("button"), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | BS_DEFPUSHBUTTON ,
0, 0, 0, 0, hwnd, (HMENU) ID_COMPT,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
hwndCmmdBt2 = CreateWindow( TEXT("button"), NULL,
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, 0, 0, hwnd, (HMENU) ID_CLOSE,
(HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
hdc = GetDC( hwnd );
GetTextMetrics( hdc, &tm );
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight + tm.tmExternalLeading;
cWinWidth = 10 * cxChar + 2 * GetSystemMetrics( SM_CXBORDER );
cWinHeight = cyChar + 2 * GetSystemMetrics( SM_CYBORDER );
MoveWindow( hwndEdit1, cWinWidth, cWinHeight, cWinWidth, cWinHeight, TRUE );
MoveWindow( hwndEdit2, cWinWidth+2*cWinWidth+4,cWinHeight, cWinWidth, cWinHeight, TRUE );
MoveWindow( hwndStatic1, cWinWidth+cWinWidth+2,cWinHeight, cWinWidth, cWinHeight, TRUE );
MoveWindow( hwndStatic2, cWinWidth+3*cWinWidth+6,cWinHeight, cWinWidth, cWinHeight, TRUE );
MoveWindow( hwndStatic3, cWinWidth+4*cWinWidth+8,cWinHeight, 2*cWinWidth, cWinHeight, TRUE );
MoveWindow( hwndCmmdBt1, cWinWidth+cWinWidth+2,2*cWinHeight+cWinWidth, cWinWidth, cWinHeight+8, TRUE );
MoveWindow( hwndCmmdBt2, cWinWidth+3*cWinWidth+6,2*cWinHeight+cWinWidth, cWinWidth, cWinHeight+8, TRUE );
//初始值
SetWindowText(hwndStatic1,TEXT("+"));
SetWindowText(hwndStatic2,TEXT("="));
SetWindowText(hwndCmmdBt1,TEXT("计算"));
SetWindowText(hwndCmmdBt2,TEXT("关闭"));
ReleaseDC( hwnd, hdc );
return 0;
case WM_SETFOCUS:
SetFocus( hwndEdit1 );
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_COMPT:
GetWindowText(hwndEdit1,szOper1,GetWindowTextLength(hwndEdit1)+1);
GetWindowText(hwndEdit2,szOper2,GetWindowTextLength(hwndEdit2)+1);
fReslt=atof(szOper1)+atof(szOper2);
sprintf(szReslt,"%f",fReslt);
SetWindowText(hwndStatic3,szReslt);
break;
case ID_CLOSE:
SendMessage(hwnd,WM_CLOSE,0,0L);
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hwnd, message, wParam, lParam );
}
oyljerry
2004-12-23
打赏
举报
回复
1,用几个控件,接收输入,计算后,显示一下
2,LineTo画线
blhy
2004-12-23
打赏
举报
回复
1、假设结果算出来存在int a 里。假如你用的是SDK 编的话,是这样:
TCHAR char[12];
wsprintf(char ,_T("%d"), a);
SetWindowText(hdc, char); // 这个函数的参数我不太记得清了,你自己查下。其中hdc是你
//的静态文本框的窗口句柄。
2、可以用GetClientRect得到客户区的坐标。
用MoveTo 和LineTo画线。
wangyangcheng
2004-12-23
打赏
举报
回复
处理好Edit的LBUTTONDOWN的消息。
danyueer
2004-12-23
打赏
举报
回复
2 用设备对象绘图,参考函数LineTo
danyueer
2004-12-23
打赏
举报
回复
1 设定Eidt的关联变量,然后UpdateData(TRUE);
HunterForPig
2004-12-23
打赏
举报
回复
怎么跑到此处来啊,兄弟!
nuaawenlin
2004-12-23
打赏
举报
回复
Windows程序设计里面讲得很清楚,160元,要学Windows编程,这两本书必备
(转载)
Win32
常见
问题
解答
博客围绕
Win32
展开,提供常见
问题
解答,涉及信息技术领域中 Windows 系统相关的
Win32
知识。
python pycharm 无法import
win32
api、
win32
con、
win32
com、
win32
gui
问题
一次解决!方法合集
本文介绍了解决PyCharm中导入
win32
api等包时遇到的
问题
,包括检查环境、安装py
win32
库及解决版本冲突的方法。
用Pyinstaller打包时遇到No module named
win32
timezone
问题
在使用Pyinstaller打包Python项目时遇到了`No module named
win32
timezone`的
问题
。打包过程未报错,但运行.exe文件时出现错误。原因是项目中从.mdb数据库读取的日期时间信息包含了
win32
timezone模块,但在打包时未被正确包含。解决方案是在代码中显式导入
win32
timezone,重新打包后
问题
得到解决。对于为何打包前后行为不同,仍存在疑问。
C++ 常见
问题
之VS19无
WIN32
| 九七的C++常见
问题
集锦
本文聚焦C++开发中,使用VS2019创建新项目时无
WIN32
项目类型的
问题
。原因是VS2019将
WIN32
合并到MFC,现在的
WIN32
变为桌面应用程序。给出解决办法,按创建新项目、点击Windows桌面向导等步骤操作即可完成创建。
pcap.h中
WIN32
宏定义
问题
在使用wpcap库时遇到错误C1083,无法打开'sys/time.h'。
问题
在于未定义
WIN32
宏。解决方案是在源文件中添加`#define
WIN32
`,使编译器选择正确的包含文件路径,避免修改第三方头文件。
网络编程
18,356
社区成员
64,165
社区内容
发帖
与我相关
我的任务
网络编程
VC/MFC 网络编程
复制链接
扫一扫
分享
社区描述
VC/MFC 网络编程
c++
c语言
开发语言
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章