| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 332 人关注过本帖
标题:VC++新手请教简单问题
只看楼主 加入收藏
fuyucao
Rank: 1
等 级:新手上路
帖 子:67
专家分:7
注 册:2011-10-17
结帖率:100%
收藏
 问题点数:0 回复次数:0 
VC++新手请教简单问题
怎么显示出x,y的值


#include <windows.h>
#include<stdio.h>
#include<dshow.h>
#include<wingdi.h>
//#include "resource.h
BYTE *fdata1;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HWND        hWnd2;
HINSTANCE   hs2;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT ("HelloWin") ;
    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    = szAppName ;

    if (!RegisterClass (&wndclass))
     {
        MessageBox (    NULL, TEXT ("This program requires Windows NT!"),
                          szAppName, MB_ICONERROR) ;
        return 0 ;
     }
    hwnd = CreateWindow( szAppName,    // window class name
            TEXT ("The Hello Program"),    // window caption
            WS_OVERLAPPEDWINDOW,    // window style
            CW_USEDEFAULT,    // initial x position
            CW_USEDEFAULT,    // initial y position
            CW_USEDEFAULT,    // initial x size
            CW_USEDEFAULT,    // initial y size
            NULL,            // parent window handle
            NULL,            // window menu handle
            hInstance,        // program instance handle
            NULL) ;         // creation parameters
     
    ShowWindow (hwnd, iCmdShow) ;
    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)
{
    HDC            hdc ;
    PAINTSTRUCT ps ;
    RECT        rect ;
    //int Gray;
    float Gray1;
    BYTE     Gray;
    int R,G,B;
    FILE *fp9;
    int i,j,x,y,m;
    int sum1=0;
    int sum2=0;
    m=1;
    //COLORREF rgb;


    fdata1=(BYTE*)malloc(460827*2);
        if ((fp9=fopen("StillCap.bmp","r"))==NULL)
        {                                                                                                                                                                                                                                                                                                                                                     
            printf("cannot open the file.\n");
            exit(1);
        }
        fread(fdata1,640*480*3+54,1,fp9);
        printf("fdata1=%d\n",fdata1);
        fclose(fp9);      
for(i=0;i<325;i++)
{
    for(j=480;j>0;j--)
    {
      B= (int)(*(fdata1+54+640*(480-j)*3));
      G = (int)(*(fdata1+54+640*(480-j)*3+1));
      R= (int)(*(fdata1+54+640*(480-j)*3+2));
     Gray1=0.299*R+0.587*G+0.114*B;//使用浮点计算
     if(Gray1>=120)
     {
       sum1+=i;
       sum2+=j;
       m++;
     }
    }
}
x=sum1/m;
y=sum2/m;

  switch (message)
     {
  case WM_CREATE:

      return x,y;

        //return 0 ;

    case     WM_PAINT:
      
        hdc = BeginPaint (hwnd, &ps) ;
         
        GetClientRect (hwnd, &rect) ;
         
        SetDIBitsToDevice (
                           hdc,               // device context handle
                           0,              // x destination coordinate
                           0,              // y destination coordinate
                           640,             // source rectangle width
                           480,             // source rectangle height
                           0,              // x source coordinate
                           0,              // y source coordinate
                           0,             // first scan line to draw
                           480,           // number of scan lines to draw
                           fdata1+54,             // pointer to DIB pixel bits
                       (BITMAPINFO*)(fdata1+14),             // pointer to DIB information
                            DIB_RGB_COLORS) ;         // color use flag
        EndPaint (hwnd, &ps) ;

        return 0 ;
        
    case    WM_DESTROY:
        PostQuitMessage (0) ;
        return 0 ;
     }
   return DefWindowProc (hwnd, message, wParam, lParam) ;
}
搜索更多相关主题的帖子: include 
2011-11-02 17:21
快速回复:VC++新手请教简单问题
数据加载中...
 
   



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

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