Ce forum est maintenant fermé, seule cette archive statique reste consultable.
  FORUM Rue-Montgallet.com
  Programmation
  C - C++

  interface graphique

Bas de page
Auteur Sujet :

interface graphique

n°19686
zaynou
Profil : Jeune recrue
Posté le 11-12-2009 à 11:56:34  
 

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 " sous visual studio  , 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 , j'ai besoin d'aide svp .
mon fichier .bmp est sur mon disque et je veux l'afficher sur un emulateur .
 
voila le code :
 
// Subproject2.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_Subproject2, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);
 
    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))  
    {
        return FALSE;
    }
 
    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_Subproject2);
 
    // 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;
}
 
 
 
Thankssss.

mood
Pub
Posté le 11-12-2009 à 11:56:34  
 

n°19687
cmoila
Profil : Membre
Posté le 13-12-2009 à 18:20:10  
 

Oui c'est ça.
 
WndProc() est la procédure que TU écris et que est appellée par windows pour gérer les messages systemes.
WM_PAINT est le message de redessin.
Ton DrawText() est où il faut.
 
Mais tu devrais pour pas encombrer le swich(message) qui va grandir avec tout sorte d'autres messages comme la gestion clavier,
faire une routine gestion du dessin :
 
LRESULT ReponseWMPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { ...}
 
et de meme pour les autres messages que tu interceptes.
WndProc() ressemblera à ca
 
 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)  
    {
        case WM_PAINT:
            ReponseWMPaint(hWnd, wParam, lParam) ;
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}


Message édité par cmoila le 15-12-2009 à 19:20:46
  FORUM Rue-Montgallet.com
  Programmation
  C - C++

  interface graphique

© 2000-2024 Forum.rue-montgallet.com - Tous droits réservés