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 :

[Débutant] Toolbar et Dialog based


Sujet :

MFC

  1. #1
    Membre éclairé
    Inscrit en
    Novembre 2006
    Messages
    422
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 422
    Par défaut [Débutant] Toolbar et Dialog based
    Salut,
    est ce que c'est possible d'avoir une toolbar (flottante si possible) avec le modèle Dialog Based ?
    Si oui comment faire ?
    Merci.

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 67
    Par défaut Oui...
    Oui, c'est possible. Je mets le code ci-dessous en précisant bien que ce n'est pas moi qui l'ai écrit mais que je l'ai trouvé sur le net et je me souviens plus où..

    en gros, tu crées des CToolBar dans ta CDialog, et dans le OnInitDialog de ta boite tu appelles une fonction style CreateToolBar qui fait à peu près :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    BOOL CMyDialog::CreateToolbar(CToolBar *wndToolBar, int ID)
    {
      // ID est l'ID de la Toolbar dessinée dans les ressources...
     if(!wndToolBar->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP|  CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC ) ||	!wndToolBar->LoadToolBar(ID))
    	{
    	 TRACE0("Failed to Create Dialog Toolbar\n");
    	 EndDialog(IDCANCEL);
    	}
     
    	CRect	rcClientOld; // Old Client Rect
    	CRect	rcClientNew; // New Client Rect with Tollbar Added
    	GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
     
    	// Called to reposition and resize control bars in the client 
    	// area of a window. The reposQuery FLAG does not really traw the 
    	// Toolbar.  It only does the calculations. And puts the new 
    	// ClientRect values in rcClientNew so we can do the rest of the 
    	// Math.
    	RepositionBars(AFX_IDW_CONTROLBAR_FIRST, _CONTROLBAR_LAST,0,reposQuery,rcClientNew);
     
    	// All of the Child Windows (Controls) now need to be moved so 
    	// the Tollbar does not cover them up. Offest to move all child 
    	// controls after adding Tollbar
    	CPoint ptOffset(rcClientNew.left-rcClientOld.left,
    	 rcClientNew.top-rcClientOld.top);
     
    	CRect	rcChild;
     
    	// Handle to the Dialog Controls
    	CWnd*	pwndChild = GetWindow(GW_CHILD);
    	while(pwndChild) // Cycle through all child controls
    	{
    	 pwndChild->GetWindowRect(rcChild); // Get the child control RECT
    	 ScreenToClient(rcChild);
     
    	// Changes the Child Rect by the values of the claculated offset
    	 rcChild.OffsetRect(ptOffset);
    	  pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
    	  pwndChild = pwndChild->GetNextWindow();
    	}
     
    	CRect	rcWindow;
    	GetWindowRect(rcWindow); // Get the RECT of the Dialog
     
    	// Increase width to new Client Width
    	rcWindow.right += rcClientOld.Width() - rcClientNew.Width();
     
    	// Increase height to new Client Height
    	rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
     
    	MoveWindow(rcWindow,FALSE); // Redraw Window
     
    	// Now we REALLY Redraw the Toolbar
    	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
    	 AFX_IDW_CONTROLBAR_LAST,0);
     
    	return TRUE;  // return TRUE unless you set the focus to a control
    }

  3. #3
    Membre éclairé
    Inscrit en
    Novembre 2006
    Messages
    422
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 422
    Par défaut

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

Discussions similaires

  1. Réponses: 9
    Dernier message: 21/07/2013, 07h21
  2. [SOAP][débutant] où trouver les bases?
    Par mirthak dans le forum XML/XSL et SOAP
    Réponses: 4
    Dernier message: 02/11/2005, 11h11
  3. [débutant] Comment créer une base ?
    Par laffreuxthomas dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 14/12/2004, 22h12
  4. Une application Dialog based pas rectangulaire....
    Par feed_our_vision dans le forum MFC
    Réponses: 2
    Dernier message: 14/06/2004, 10h10
  5. "Tree Control" pour "Dialog Based"
    Par bigboomshakala dans le forum MFC
    Réponses: 4
    Dernier message: 22/04/2004, 10h32

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