社区
网络编程
帖子详情
有关Win32的问题
bill_li
2004-12-23 12:51:28
我才学不久,老师给了两个作业题,我不太明白,所以问问大家了。
1。创建2个编译框和一个静态文本框,以及一个“计算”按纽。用户在2个编译框中输入数字,然后单击“计算”,在静态文本框中显示求和结果。
在里面我不太会 “在静态文本框中显示求和结果”。
2。编一个程序,绘制一个五角星,五角星用红线绘制,显示在屏幕的中间,五角星的边取客户区宽度和高度最小值。
我不明白“五角星”怎么编 “五角星的边取客户区宽度和高度最小值。”怎么取。
...全文
111
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编程,这两本书必备
Word(WPS文字)+Python
win32
com办公自动化
本课程主要结合Python
win32
com包介绍Word(WPS文字)办公自动化的各种方法。相关内容包括Python语言基础、Word对象包括文档、Range、段落、节、域、页眉页脚、书签、表格、图形、图表、正则表达式等。使用
win32
com,...
python pycharm 无法import
win32
api、
win32
con、
win32
com、
win32
gui
问题
一次解决!方法合集
最近写项目发现pythoncom 导入
win32
api、
win32
con、
win32
com、
win32
gui 等
win32
相关的包都会出现或多或少
问题
,Google一大堆不靠谱的方法试了个遍。 特此记录一下解决办法
python安装
win32
gui的相关
问题
问题
一:直接pip/pip3 install
win32
gui报错,报错代码为"ModuleNotFoundError: No module named '
win32
.distutils.command',我的环境是python3.7。网上有大佬说
win32
gui和python3.7不兼容,但个人感觉是这个模块在...
win11遇到
win32
kbase.sys蓝屏解决方法;(超级详细,不懂的请私信up主)
win11
win32
kbase.sys蓝屏解决方法
Python 使用
win32
gui+
win32
api 通过鼠标获取句柄
Python 使用
win32
gui+
win32
api 通过鼠标获取句柄。
网络编程
18,356
社区成员
64,214
社区内容
发帖
与我相关
我的任务
网络编程
VC/MFC 网络编程
复制链接
扫一扫
分享
社区描述
VC/MFC 网络编程
c++
c语言
开发语言
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章