none
afficher des bitmaps RRS feed

  • Question

  • Bonjour ,
    actuellement , je develloppe une application graphique , qui doit afficher des bitmaps sur un emulateur Pocket PC , j'ai ouvert une application graphique " hello world classique " , et je veux savoir , est ce qu'il suffit d'ajouter du code "qui affiche le bitmap " dans la partie ou il est ecrit  ""// TODO: Add any drawing code here..."" , ou il  faut proceder autrement ,
    Je suis débutant dans le domaine .
    Thankssss.

    vendredi 11 décembre 2009 10:08

Toutes les réponses

  • Bonjour,

    Je crois reconnaître dans "// TODO :" le commentaire créé par l'assistant de Visual C++ qui génère un squelette d'application MFC. Est-ce bien ça ?
    Ce commentaire est placé dans la méthode OnDraw de la classe dérivée de CView, c'est ça ?

    Si oui, alors la classe dérivée de CView est responsable de l'affichage des données. Notamment la méthode OnDraw.
    Dans le modèle MFC, les données (par ex : le fichier bitmap) sont stockées dans un objet dérivé de CDocument, et l'affichage des données se fait par la classe CView.
    Donc oui, il faut écrire du code dans OnDraw pour afficher le bitmap.

    Liens :
    - présentation des concepts MFC : http://msdn.microsoft.com/fr-fr/library/kkcb3t0w.aspx
    - charger une image : http://www.blogmfc.com/2008/02/24/ChargerUneImagePNGJPEGDepuisLesRessourcesEnCMFC.aspx

    Pierre

    vendredi 11 décembre 2009 13:32
    Auteur de réponse
  • oui c'est à peu pres ça ..

    voila le squellete que j'ai :

    // Subproject3.cpp : Defines the entry point for the application.
    //

    #include "StdAfx.h"
    #include "resource.h"

    #define MAX_LOADSTRING 100

    // Global Variables:
    HINSTANCE hInst;                      // current instance
    TCHAR szTitle[MAX_LOADSTRING];        // The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];  // The title bar text

    // Forward declarations of functions included in this code module:
    ATOM MyRegisterClass(HINSTANCE hInstance);
    BOOL InitInstance(HINSTANCE, int);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

    int WINAPI WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR     lpCmdLine,
                         int       nCmdShow)
    {
        // TODO: Place code here.
        MSG msg;
        HACCEL hAccelTable;

        // Initialize global strings
        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
        LoadString(hInstance, IDC_Subproject3, szWindowClass, MAX_LOADSTRING);
        MyRegisterClass(hInstance);

        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow))
        {
            return FALSE;
        }

        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_Subproject3);

        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0))
        {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        return msg.wParam;
    }



    //
    //  FUNCTION: MyRegisterClass()
    //
    //  PURPOSE: Registers the window class.
    //
    //  COMMENTS:
    //
    //    This function and its usage is only necessary if you want this code
    //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
    //    function that was added to Windows 95. It is important to call this function
    //    so that the application will get 'well formed' small icons associated
    //    with it.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
        WNDCLASS wc;

        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = (WNDPROC) WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = 0;
        wc.hCursor = 0;
        wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName = 0;
        wc.lpszClassName = szWindowClass;

        return RegisterClass(&wc);
    }

    //
    //   FUNCTION: InitInstance(HANDLE, int)
    //
    //   PURPOSE: Saves instance handle and creates main window
    //
    //   COMMENTS:
    //
    //        In this function, we save the instance handle in a global variable and
    //        create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;

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

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

       if (!hWnd)
       {
          return FALSE;
       }

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

       return TRUE;
    }

    //
    //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_COMMAND  - process the application menu
    //  WM_PAINT    - Paint the main window
    //  WM_DESTROY  - post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        PAINTSTRUCT ps;
        HDC hdc;
        TCHAR szHello[MAX_LOADSTRING];
        LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

        switch (message)
        {
            case WM_PAINT:
                hdc = BeginPaint(hWnd, &ps);


                // TODO: Add any drawing code here...


                RECT rt;
                GetClientRect(hWnd, &rt);
                DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_CENTER);
                EndPaint(hWnd, &ps);
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }
     

    normalement l'affichage se fait sur un emulateur (avec windows CE) , et moi a la place de "hello world " , il faut que j'affiche des images .bmp ,
    je veux juste savoir comment proceder sachant que je suis débutant ,

    Merci bcp .

    vendredi 11 décembre 2009 13:57