求个用c/c++编写windows程序源代码

求个用c/c++编写windows程序源代码期末考试用,,100行左右的代码就可以... 求个用c/c++编写windows程序源代码
期末考试用,,100行左右的代码就可以
展开
 我来答
金色潜鸟
2014-06-20 · TA获得超过3.2万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:5697万
展开全部
下面是完整程序,MS VC++ 6.0 编译器。
主要用途,用鼠标点击调节 RGB 数值,椭圆里显示 对应的颜色。
程序里有多余的码,你可以删去。(一个多余是试验鼠标移动时连续显示坐标数值,还有一个多余部分是调用Vfw32.lib播放一个avi视频。)

// cl show_color.cpp
#include <Afxwin.h>
#include <math.h>
// #include <Vfw.h>
// #pragma comment (lib, "Vfw32.lib")
#define DEBUG 1
HWND hWndMain;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
char one_line[80];
int len,NN;
LPTSTR argv;
RECT RectR, RectG, RectB, RectX;
int RectDy,RectW,RectH;
int x_r=495,x_g=495,x_b=495,x_shift=100;
long int v_r,v_g,v_b;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
MSG Msg;
int i;
RectDy = 50; RectW = 400; RectH = 30;
RectR.left = 0; RectR.right=RectW; RectR.bottom=200; RectR.top = RectR.bottom + RectH;
RectG.left = 0; RectB.left = 0;
RectG.right=RectW; RectB.right=RectW;
RectG.bottom=RectR.bottom + RectDy; RectB.bottom=RectG.bottom + RectDy;
RectG.top = RectG.bottom + RectH;
RectB.top = RectB.bottom + RectH;
v_r = (x_r - x_shift) * 255 / RectW;
v_g = (x_g - x_shift) * 255 / RectW;
v_b = (x_b - x_shift) * 255 / RectW;

if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);
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 long nXChar,nYChar,xInc,yInc;
static int xClient, yClient; // width height of client area
static int xClientMax; // maximum width of client area
static int xChar, yChar; // horizontal vertical scrolling unit
static int xPos,yPos; // current horizontal vertical scrolling position
static int xMax,yMax; // maximum horizontal scrolling position
SCROLLINFO si;
HDC hdc;
short x;
TEXTMETRIC tm;
PAINTSTRUCT ps;
COLORREF color;
HFONT font;
HPEN hP1; // pen
HBRUSH hBr,hBrR,hBrG,hBrB;
CPoint aP,mousePos;
HWND h_wnd2;

int i;
char szlocation[100]; //temp
CPoint pt,pt2; // temp
RECT rect,rect2;
switch(message)
{
case WM_LBUTTONDOWN: case WM_LBUTTONUP:
mousePos.x = LOWORD( lParam );
mousePos.y = HIWORD( lParam );
if (mousePos.x >= RectR.left+x_shift && mousePos.x <= RectR.right+x_shift){
if (mousePos.y > RectR.bottom && mousePos.y < RectR.top) x_r = mousePos.x;
if (mousePos.y > RectG.bottom && mousePos.y < RectG.top) x_g = mousePos.x;
if (mousePos.y > RectB.bottom && mousePos.y < RectB.top) x_b = mousePos.x;
v_r = (x_r - x_shift) * 255 / RectW;
v_g = (x_g - x_shift) * 255 / RectW;
v_b = (x_b - x_shift) * 255 / RectW;
ShowWindow(hwnd, SW_HIDE);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
};
return 0;
case WM_CREATE:
hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
nXChar=tm.tmAveCharWidth;
nYChar=tm.tmHeight;
xInc=1;yInc=1; xChar=nXChar; yChar=nYChar; // for scroll window
ReleaseDC(hwnd,hdc);
xClientMax = 800;
// h_wnd2 = MCIWndCreate(hwnd,NULL,0,"sylvtwt.avi"); //Play
// MCIWndPlay(h_wnd2); // Play
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps); // begin paint
SetGraphicsMode(hdc,GM_ADVANCED);
SetWindowExtEx(hdc,700,400,NULL); // cx=700,cy=400 logical unit
SetViewportExtEx(hdc,600,400,NULL);
SetViewportOrgEx(hdc,x_shift,10,NULL);
SetMapMode(hdc,MM_ANISOTROPIC);

color=RGB(0,128,128);
hP1=CreatePen(PS_SOLID,0,color);
SelectObject(hdc,hP1);

hBrR = CreateSolidBrush( RGB(255,0,0));
hBrG = CreateSolidBrush( RGB(0,255,0));
hBrB = CreateSolidBrush( RGB(0,0,255));
hBr = CreateSolidBrush( RGB(200,200,200));
SelectObject(hdc,hBrR);
FillRect(hdc, &RectR, hBrR);
RectX=RectR; RectX.left=x_r-x_shift; SelectObject(hdc,hBr); FillRect(hdc, &RectX, hBr);
SelectObject(hdc,hBrG);
FillRect(hdc, &RectG, hBrG);
RectX=RectG; RectX.left=x_g-x_shift; SelectObject(hdc,hBr); FillRect(hdc, &RectX, hBr);
SelectObject(hdc,hBrB);
FillRect(hdc, &RectB, hBrB);
RectX=RectB; RectX.left=x_b-x_shift; SelectObject(hdc,hBr); FillRect(hdc, &RectX, hBr);

font=CreateFont(
24,10,0,0, FW_NORMAL,0,0,0, ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,NULL,"myfont"
);
SelectObject(hdc,font);
GetTextMetrics(hdc,&tm);
nYChar=tm.tmHeight;
color=RGB(0,0,0);
sprintf(one_line,"R=%3d",v_r);
TextOut(hdc,RectR.right+10,RectR.bottom,one_line,strlen(one_line));
sprintf(one_line,"G=%3d",v_g);
TextOut(hdc,RectG.right+10,RectG.bottom,one_line,strlen(one_line));
sprintf(one_line,"B=%3d",v_b);
TextOut(hdc,RectB.right+10,RectB.bottom,one_line,strlen(one_line));
color = RGB(v_r,v_g,v_b);
hBr = CreateSolidBrush(color);
SelectObject(hdc,hBr);
Ellipse(hdc, 100, 30, 326, 144);

EndPaint(hwnd,&ps); // end paint
return 0L;

case WM_SIZE:
yClient = HIWORD (lParam);
xClient = LOWORD (lParam);
yMax = max (0, 600 - yClient/yChar); // need to calculate
yPos = min (yPos, yMax); // current position not exceed the maximum
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = 0; si.nMax = yMax; si.nPage = yClient / yChar;
si.nPos = yPos;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
xMax = max (0, 2 + (1600 - xClient)/xChar);
xPos = min (xPos, xMax);
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = 0;
si.nMax = xMax;
si.nPage = xClient / xChar;
si.nPos = xPos;
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
UpdateWindow (hwnd);
return 0;
case WM_VSCROLL:
switch(LOWORD (wParam))
{
case SB_PAGEUP: // User clicked shaft left of the scroll box.
yInc = -4; break;
case SB_PAGEDOWN: // User clicked shaft right of the scroll box.
yInc = 4; break;
case SB_LINEUP: // User clicked the left arrow.
yInc = -1; break;
case SB_LINEDOWN: // User clicked the right arrow.
yInc = 1; break;
case SB_THUMBTRACK: // User dragged the scroll box.
yInc = HIWORD(wParam) - yPos; break;
default:
yInc = 0; break;
}
if (yInc = max(-yPos, min(yInc, yMax - yPos)))
{
yPos += yInc;
ScrollWindowEx(hwnd, 0, -yChar * yInc,
(CONST RECT *) NULL, (CONST RECT *) NULL,
(HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = yPos;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
UpdateWindow (hwnd);
};
return 0;

case WM_HSCROLL:
switch(LOWORD (wParam))
{
case SB_PAGEUP: // User clicked shaft left of the scroll box.
xInc = -4; break;
case SB_PAGEDOWN: // User clicked shaft right of the scroll box.
xInc = 4; break;
case SB_LINEUP: // User clicked the left arrow.
xInc = -1; break;
case SB_LINEDOWN: // User clicked the right arrow.
xInc = 1; break;
case SB_THUMBTRACK: // User dragged the scroll box.
xInc = HIWORD(wParam) - xPos; break;
default:
xInc = 0; break;
}
if (xInc = max(-xPos, min(xInc, xMax - xPos)))
{
xPos += xInc;
ScrollWindowEx(hwnd, -xChar * xInc, 0,
(CONST RECT *) NULL, (CONST RECT *) NULL,
(HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE);
si.cbSize = sizeof(si);
si.fMask = SIF_POS;
si.nPos = xPos;
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
UpdateWindow (hwnd);
};
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,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="Windows Fill";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
return(RegisterClass(&wndclass));
}

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow(
"Windows Fill",
"Show_color",
WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_BORDER | WS_HSCROLL | WS_VSCROLL,
100,100,800,400,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
ban888zhang
2014-06-19 · 超过16用户采纳过TA的回答
知道答主
回答量:70
采纳率:0%
帮助的人:29.5万
展开全部
mfc的图形界面,还是控制台的呢?具体功能是什么啊
追问
mfc的,,,功能最好是小游戏之类的,,
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
飞絮落花时候丶
2014-06-19 · TA获得超过117个赞
知道小有建树答主
回答量:173
采纳率:0%
帮助的人:111万
展开全部
Qt写的要么?
追问
能用VS2010之类的软件编译运行吗?
追答
直接编译肯定不行
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式