can you help me? thanks for you

junzli 2004-12-26 02:12:05
#include "stdafx.h"
#include "resource.h"
#include "math.h"
#include "string.h"

#define MAX_LOADSTRING 100
#define MAX_DEVICES 100
#define MAX_NUM 10000
#define PANE_CONS 100 //网格密度
#define PI 3.1415927
static int crSet[2];
static int CurrentVal[2],PrevVal[2];
static HWND hwScroll[2];
char szString[10];
HINSTANCE hInst;
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK SETDlgProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WINDOWTEST, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINDOWTEST);
SendMessage(hWnd,WM_COMMAND,IDM_START,0L);
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WINDOWTEST);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_WINDOWTEST;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}
crSet[0]=25;
crSet[1]=0;
CurrentVal[0]=25;
CurrentVal[1]=2;

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

static HPEN hPen,hpen1,hpen2;
POINT Points[MAX_NUM];
static int cxClient,cyClient;
int x,y;
int i;

switch (message)
{
case WM_CREATE:
hpen1=CreatePen(PS_SOLID,3,RGB(0,0,0));
hpen2=CreatePen(PS_SOLID,1,RGB(255,0,0));
CurrentVal[0]=25;
CurrentVal[1]=2;
break ;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_SETTING:
DialogBox(hInst,(LPCTSTR)IDD_CHANGE,hWnd,(DLGPROC)SETDlgProc);
break;
case IDM_START:
hdc=BeginPaint(hWnd,&ps);
for(x=cxClient/PANE_CONS; x<cxClient;x+=cxClient/PANE_CONS)
{
MoveToEx(hdc,x,0,NULL);
LineTo(hdc,x,cyClient);
}
for(y=cyClient/PANE_CONS;y<cyClient;y+=cyClient/PANE_CONS)
{
MoveToEx(hdc,0,y,NULL);
LineTo(hdc,cxClient,y);
}
SelectObject(hdc,hpen1);
MoveToEx(hdc,0,cyClient/2,NULL);
LineTo(hdc,cxClient,cyClient/2);
SelectObject(hdc,hpen2);
for( i=0;i<MAX_NUM;i++)
{
Points[i].x=i*cxClient/MAX_NUM;
Points[i].y=(int)(cyClient/2*(float)(CurrentVal[1])
/10*(1-sin(PI*2*i/MAX_NUM)))
+(int)(2*cyClient*(float)CurrentVal[1]/10);
}
Polyline(hdc,Points,MAX_NUM);
SelectObject(hdc,GetStockObject(BLACK_PEN));
EndPaint(hWnd,&ps);
break;
case IDM_STOP:
break;


//////////////////////////////////////////////////////////////////////////

case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:

break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
LRESULT CALLBACK SETDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

int i;
switch (message)
{
case WM_INITDIALOG:
for(i=0;i<2;i++)
{
CurrentVal[i]=crSet[i];
PrevVal[i]=crSet[i];
SetScrollPos(hwScroll[i],SB_CTL,CurrentVal[i],TRUE);
SetDlgItemText(hDlg,IDC_VALFREQ+i,itoa(CurrentVal[i],szString,10));
}
hwScroll[0]=GetDlgItem(hDlg,IDC_FREQ);
hwScroll[1]=GetDlgItem(hDlg,IDC_HUDU);
SetScrollRange(hwScroll[0],SB_CTL,MIN_FREQUENT,MAX_FREQUENT,FALSE);
SetScrollRange(hwScroll[1],SB_CTL,MIN_HUDU,MAX_HUDU,FALSE);
SetFocus(hwScroll[0]);
break;
case WM_HSCROLL:
i=0;
while(hwScroll[i]!=(HWND)lParam)
i++;
switch(LOWORD(wParam))
{
case SB_LINERIGHT:
CurrentVal[i]++;
if(i==0)
{
if(CurrentVal[i]>MAX_FREQUENT)
CurrentVal[i]=MAX_FREQUENT;
}
if(i==1)
{
if(CurrentVal[i]>MAX_HUDU)
CurrentVal[i]=MAX_HUDU;
}
break;
case SB_LINELEFT:
CurrentVal[i]--;
if(i==0)
{
if(CurrentVal[i]<MIN_FREQUENT)
CurrentVal[i]=MIN_FREQUENT;
}
if(i==1)
{
if(CurrentVal[i]<MIN_HUDU)
CurrentVal[i]=MIN_HUDU;
}
break;
case SB_PAGERIGHT:
if(i==0)
CurrentVal[i]+=(MAX_FREQUENT-CurrentVal[i])/2;
CurrentVal[i]+=(MAX_HUDU-CurrentVal[i])/2;
break;
case SB_PAGELEFT:
if(i==0)
{
CurrentVal[i]-=(MIN_FREQUENT+CurrentVal[i])/2;
if(CurrentVal[i]<MIN_FREQUENT)
CurrentVal[i]=MIN_FREQUENT;
}
CurrentVal[i]-=(MIN_HUDU+CurrentVal[i])/2;
if(CurrentVal[i]<MIN_HUDU)
CurrentVal[i]=MIN_HUDU;
break;
case SB_THUMBTRACK:
CurrentVal[i]=HIWORD(wParam);
break;
case SB_TOP:
if(i==0)
CurrentVal[i]=MIN_FREQUENT;
CurrentVal[i]=MIN_HUDU;
break;
case SB_BOTTOM:
if(i==0)
CurrentVal[i]=MAX_FREQUENT;
CurrentVal[i]=MAX_HUDU;
break;
}
SetScrollPos(hwScroll[i],SB_CTL,CurrentVal[i],TRUE);
SetDlgItemText(hDlg,IDC_VALFREQ+i,itoa(CurrentVal[i],szString,10));
crSet[i]=CurrentVal[i];
SendMessage(hWnd,WM_COMMAND,IDM_START,0L);
break;

case WM_COMMAND:
switch(wParam)
{
case IDOK:
for(i=0;i<2;i++)
crSet[i]=CurrentVal[i];
EndDialog(hDlg,TRUE);
return(TRUE);
case IDCANCEL:
for(i=0;i<2;i++)
crSet[i]=CurrentVal[i];
EndDialog(hDlg,TRUE);
return(TRUE);
}
break;
}
return FALSE;
}
...全文
69 点赞 收藏 2
写回复
2 条回复
superxiaomm 2004年12月26日
你用debug试试
回复 点赞
junzli 2004年12月26日
我的思想是:想通过调节弹出窗口里面的Scrollbar控件来调整主窗口输出不同振幅的sin函数图形!
出现的问题是:
①点击“参数设置”这个菜单选项时要 先 点击"运行"菜单下面的“开始”选项才能正常运行,
如果当程序一运行就点击“参数设置”就会参数死循环。
②“参数设置里面”的Scrollbar控件的调节 与 主窗口绘制的sin函数振幅没有联系起来。
③当“参数设置”窗口停留一会儿是再移动该窗口就会在主窗口里面形成一个背景为白色的矩形。

回复 点赞
发动态
发帖子
网络编程
创建于2007-09-28

7880

社区成员

6.4w+

社区内容

VC/MFC 网络编程
社区公告
暂无公告