IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

MFC et Windows 7


Sujet :

MFC

  1. #1
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut MFC et Windows 7
    Bonjour

    j'ai une application MFC qui fonctionne bien sous XP, Vista.
    Elle fonctionnait bien sous Windows 7 mais après quelleque petites modifications d'interface (rajout d'un bmp assez "gros" entre autre) elle ne démarre plus, le processeur tournant à 50%.
    N'ayant pas encore installé Windows 7 sur ma machine, je vous pose la question "Avez-vous une idée de la raison du pourquoi qu'est-ce ?"
    Merci.
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut,
    vu comme ça non ,
    A part un verrou mortel quelque part, le CPU a 50% me dit que c'est un processeur 2 cœurs donc il ne fait monter le cpu qu'a 50%...

  3. #3
    Expert éminent sénior
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 362
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 362
    Points : 20 391
    Points
    20 391
    Par défaut
    Citation Envoyé par Trap D Voir le message
    Elle fonctionnait bien sous Windows 7 mais après quelleque petites modifications d'interface (rajout d'un bmp assez "gros" entre autre) elle ne démarre plus, le processeur tournant à 50%.
    Ok mais la grosse BMP comment est-elle chargée ? Est-ce qu'elle est liée en ressources dans l'exécutable ?
    Est-ce qu'au niveau des API GDI tu utilises bien SelectObject etc...comme il faut ?

  4. #4
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    Le bmp est dans les ressources et quand je dis gros celà reste tout de même modeste 66 Ko.
    Au démarrage de mon appli, je n'utilise pas les API GDI, je ne pense donc pas que le problème vienne de là.
    A ce sujet, j'aurais une autre question : dans une autre partie du programme qui ne s'effectue pas au démarrage, je crée à la volée des boutons et je leur affecte un bitmap, voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    HANDLE hdl = :: LoadImage(NULL, 
                     BtnPath+FindFileData.cFileName+CString("\\bouton.bmp"), 
                     IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
    if (hdl != NULL)
    {
        MyCButton* pmyButton1 = new MyCButton;
        pmyButton1->Create(_T(""), WS_CHILD|WS_VISIBLE| BS_BITMAP  | BS_AUTORADIOBUTTON,
                     CRect(10 + Col * DL , 10 + Line * DH,  10 + LARGEUR + Col * DL, 20 + HAUTEUR + Line * DH),
    		 GetDlgItem(IDC_FOND_BOUTONS), FIRST_BTN+i);
       pmyButton1->SetBitmap((HBITMAP) hdl);
       // DeleteObject(hdl);
    }
    Sous Vista je faisais DeleteObject(hdl); et les boutons s'affichaient bien mais sous XP je suis obligé d'enlever le DeleteObject car sinon les boutons ne s'affichent pas.

    Ais-je fait une erreur quelque part où est-ce normal ?

    Merci.
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  5. #5
    Expert éminent sénior
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 362
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 362
    Points : 20 391
    Points
    20 391
    Par défaut
    Salut Trap D en principe DeleteObject() est appelée si tu appelles initialement des API comme CreateFont par exemple ou CreateBitmap.
    Dans le MSDN concernant CButton::SetBitmap() ou CStatic on ne parle pas de DeletObject donc en théorie on ne devrait pas l'appeler.
    Tu as aussi les sources des MFC tu peux tracer pour voir si DeleteObject est appelée en interne.
    Selon Vista ou XP il faudrait voir si les classes MFC et API Windows ont changé


    J'ai un MSDN qui date un peu as-tu vu cet article ?
    This article was previously published under Q141863
    SUMMARY
    In a Microsoft Foundation Class (MFC) Library application for Windows, it is occasionally useful to be able to display a bitmap larger than a normal icon in a dialog box. This can either be done using the resource editor or at run time. The Bdlg32.exe sample demonstrates four methods for placing a bitmap on a dialog box.

    NOTE: This is the 32-bit version of this sample.
    MORE INFORMATION
    The following file is available for download from the Microsoft Download Center:

    Bdlg32.exe

    Release Date: Sept-18-2000

    For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
    119591 How to Obtain Microsoft Support Files from Online Services

    Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. NOTE: Use the -d option when you run Bdlg32.exe, to decompress the file and recreate the proper directory structure.

    To display a bitmap using the resource editor place a picture control on a dialog template. Bring up the properties dialog for the picture control and associate the control with a bitmap type (SS_BITMAP style) and an image by specifying a bitmap resource ID. If you want to associate a bitmap resource ID with the picture control only at run time or if you would like to change the bitmap at run time then use the function CStatic::SetBitmap(). There are four possible methods to display a bitmap at runtime:
    BitBlt() a bitmap onto the dialog box in its OnDraw() handler.
    BitBlt() or StretchBlt() into a "static" frame control.
    BitBlt() or StretchBlt() in OnEraseBkgnd().
    Use a CBitmapButton as a picture control.
    The Bdlg32.exe sample demonstrates these four methods for placing a bitmap on a dialog box.
    Method 1: BitBlt() in OnDraw()
    The first method uses a simple BitBlt(), when the dialog box receives a WM_PAINT message, to paint a bitmap in a hard-coded location on a dialog box. This method demonstrates the following:


    Using LoadBitmap().
    Creating a compatible memory device context (DC).
    Saving a handle to an object selected out of a DC between messages.
    Using BitBlt().
    Cleaning up a loaded bitmap and memory DC when finished with them.
    Because this is a common technique, a basic version of the few steps needed to draw a bitmap on a dialog box using MFC are listed below. These steps assume you have already created a C++ class, named CMyDlg, and that it has been associated with either a dialog box template created in Visual Studio or with a dialog editor.


    Add a bitmap resource with an ID of IDB_MYBITMAP (or whatever ID you want) to your project. With App Studio, you can do this by either creating a new bitmap resource and setting the ID, or by importing an already created bitmap with a .BMP extension.
    Add a WM_PAINT handler to your CMyDlg class. To do this in Visual Studio .NET, click to select the CMyDlg class node in the Class View window, open the Properties window, click the Messages icon, locate the WM_PAINT window message, and then add an OnPaint handler through the Properties window. With earlier versions of Visual C++, just use Class Wizard to add an OnPaint() handler to your dialog box class.
    Now, your OnPaint() function will have to load and use BitBlt() to paint the bitmap in your resource onto the dialog box. The code to do this is the following:
    void CMyDlg::OnPaint()
    {
    CPaintDC dc( this ); // Device context for painting

    CBitmap bmp, *poldbmp;
    CDC memdc;

    // Load the bitmap resource
    bmp.LoadBitmap( IDB_CORPLOGO );

    // Create a compatible memory DC
    memdc.CreateCompatibleDC( &dc );

    // Select the bitmap into the DC
    poldbmp = memdc.SelectObject( &bmp );

    // Copy (BitBlt) bitmap from memory DC to screen DC
    dc.BitBlt( 10, 10, 47, 47, &memdc, 0, 0, SRCCOPY );

    memdc.SelectObject( poldbmp );

    // Do not call CDialog::OnPaint() for painting messages
    }

    After adding this code and adding an OnPaint entry to the message map for your CMyDlg class, you should see the bitmap image displayed in the dialog box at run time.
    Note that the first four parameters to CDC::BitBlt() depend on your program and the size of the bitmap resource. The first two (10, 10) position the upper-left corner where the bitmap will be drawn on the dialog box's client area. The second two (47, 47) specify the width and height of the bitmap area to copy over in logical units. These dimensions can be less than the size of the actual bitmap. The sixth and seventh parameters specify the upper-left corner of the bitmap in the memory DC to start copying from.

    One other thing to note is that the CDC and CPaintDC objects in the code above are created on the stack so you do not need to call the Windows API functions DeleteDC() and ReleaseDC() on the memory and paint DC objects, respectively.

    For more information about bitmaps and device contexts, refer to the documentation for the Windows API and MFC versions of BitBlt(), SelectObject(), and CreateCompatibleDC(). For a more complete example of this, please see the BDLG32 sample.
    Method 2: BitBlt() or StretchBlt() in "Static" Frame Control
    The second method uses StretchBlt() and, using techniques similar to those in the "Paint" dialog box, draws the bitmap in the client area of a "static" picture frame control.

    The BDLG32 sample associates a CStatic member variable with the static control by using the Add Variable menu when the static control is selected in the Dialog Editor.

    NOTE: Adding a static control in the Visual C++ 6.0 and Visual C++ .NET designers generates a default ID of IDC_STATIC for the control. The Dialog Editor does not permit you to associate a member variable with a control with the ID of IDC_STATIC. Change the ID of the static control in the Properties window to an ID that is defined by your application so that you can add a member variable of type CStatic to the dialog class.

    In addition to these techniques, Method 2 demonstrates calculating the client area of a child control. Note that subclassing the CStatic member (after associating the control to a class member variable, just change the type in the header from CStatic to a class you've derived from CStatic) allows you to have the subclassed control paint a bitmap in its client area when it receives a WM_PAINT.
    Method 3: BitBlt() or StretchBlt() in OnEraseBkgnd()
    The third method StretchBlt's the bitmap onto the background of a dialog box in the dialog box's WM_ERASEBKGND handler, OnEraseBkgnd(). It also demonstrates handling WM_CTLCOLOR messages and returning background brushes from that handler (transparent in this case).
    Method 4: CBitmapButton as Picture Control
    The fourth and last method uses a CBitmapButton class to CBitmapButton::AutoLoad() a bitmap into a disabled owner-draw button on a dialog box. It is probably the simplest method of the four, although it does not allow for much flexibility or changing of what is being painted to reflect changes in the dialog box.

    In Visual Studio .NET, you must add a member variable of type CButton because the wizard does not allow you to associate CBitmapButton objects directly. After you add the CButton derived class, edit the source file to derive the class from CBitmapButton instead.

    Please note the following when creating your resources for using a CBitmapButton class. When you add the button to your dialog box template, which you will later be associating with a CBitmapButton, the ID is relatively unimportant, but the button must be set as owner-draw in the Properties window and the caption text will be used to load your bitmap. If your button caption text is "BITB", you should create your bitmap and give it an ID of "BITBU". Your bitmap ID MUST have the double quotation marks or it will be saved as just a numeric ID and fail to load when you use CBitmapButton::AutoLoad(). See the documentation for CBitmapButton for more information.


    Additional query words: BDLG 4.0 4.00 4.1 4.10 4.2 4.20

    Keywords: kbdownload kbBitmap kbcode kbDlg kbfile kbGDI kbinfo kbSample KbUIDesign KB141863
    Technology: kbAudDeveloper kbMFC kbVC32bitSearch kbVC400 kbVC410 kbVC420 kbVC500 kbVC500Search kbVC600 kbVCsearch

  6. #6
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    Merci beaucoup pour cet article, je vais l'étudier.
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  7. #7
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    Bon, finalement, il semble que ce soit un problème Windows 7 sur une machine particulière plutôt qu'autre chose : je l'ai installé chez moi en Virtual PC et ça fonctionne bien.
    topic résolu.
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème avec les MFC de windows
    Par tiagocerqueira dans le forum MFC
    Réponses: 3
    Dernier message: 02/02/2010, 11h30
  2. [MFC] ActiveX Windows Media Player
    Par Philippe320 dans le forum MFC
    Réponses: 0
    Dernier message: 24/11/2008, 10h44
  3. Difference entre MFC et Windows Application
    Par abbd dans le forum Visual C++
    Réponses: 2
    Dernier message: 27/02/2007, 13h18
  4. [WIN32][MFC] Compilation ..WINDOWS.H
    Par fantasma dans le forum MFC
    Réponses: 9
    Dernier message: 07/09/2006, 11h51
  5. Réponses: 15
    Dernier message: 18/01/2005, 23h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo