Affichage d'un boutton en Win32

Résolu
Crazy_Joe Messages postés 47 Date d'inscription samedi 2 juillet 2005 Statut Membre Dernière intervention 3 janvier 2008 - 18 juil. 2005 à 20:39
Crazy_Joe Messages postés 47 Date d'inscription samedi 2 juillet 2005 Statut Membre Dernière intervention 3 janvier 2008 - 19 juil. 2005 à 19:53
Bonjour à tous,



Cela va peut-être vous paraître assez bénin mais je n'arrive pas à
afficher un boutton tout simple dans mon application. Voici un bout de
ma fonction WinProc():



switch (message)

{

case WM_CREATE:

Police[0] = "Arial";

Police[1] = "Comic Sans MS";

Police[2] = "Impact";

Police[3] = "Bookman Old Style";



hwndButtonParcourir = CreateWindowEx(0, "BUTTON", "CLASSE BOUTON",


WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON | WS_BORDER,


10, 40, 20, 50, hWnd, (HMENU)IDB_PARCOURIR ,


hInst, NULL);







break;



case WM_PAINT:

hDc = BeginPaint(hWnd,&ps);

GetClientRect(hWnd,&rc);

HFONT Police;



//Tout ce qui est présentation, texte, etc...



EndPaint(hWnd, &ps);

break;



case WM_DESTROY:

DeleteObject(Police);

PostQuitMessage(0);

break;



default:

return DefWindowProc(hwnd,message,wParam,lParam);

break;

}



J'ai essayé de mettre la fonction ShowWindow(hwndButtonParcourir,SW_SHOW) un peu partout mais sans résultat.



Merci de m'aider.



Merci.

10 réponses

cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
19 juil. 2005 à 19:21
En faite j'ai relu j'ai rien compris mdr donc voila ça va plus vite


hwndButtonParcourir = CreateWindowEx(0, "BUTTON", "CLASSE BOUTON",


WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON | WS_BORDER,


10, 40, 20, 50, hwnd, (HMENU)IDB_PARCOURIR ,


hInst, NULL);



Par contre pourquoi l'autre il marche ??? mystère et boule de GUM :)

void Aurevoir( void ); //Bonne journée
3
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
19 juil. 2005 à 19:23
Dans WM_CREATE, CreateWindow n'est pas encore terminé, donc hWnd n'est pas encore bon. Il ne l'est qu'a la fin de WM_CREATE
3
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
18 juil. 2005 à 20:59
Test ton hinstance

Si tu l'as déclarée en globale revoie ton affectation

Si tu la récupère dans ta WndProc, test la fonction utilisée

Sinon j'vois pas trop

void Aurevoir( void ); //Bonne journée
0
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
18 juil. 2005 à 21:44
Bon et pi tant que j'y suis

On ne déclare pas de variable dans des case

la tu fais un HFONT dans WM_PAINT

Et montre un peu comment tu déclares ton tableau de chaine de caractères

parceque c'est pas trop approprié le = pour des chaîne...

void Aurevoir( void ); //Bonne journée
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
18 juil. 2005 à 22:24
hInstance pour CreateWindow est ignoré sous NT/2000/XP

Comme tu mets le style WS_VISIBLE, pas besoin de ShowWindow après
Regarde juste après la création si hwndButtonParcourir est NULL:
if(!hwndButtonParcourir = CreateWindowEx(0, "BUTTON", "CLASSE BOUTON",
WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON | WS_BORDER,
10, 40, 20, 50, hWnd, (HMENU)IDB_PARCOURIR ,
hInst, NULL))
MessageBox(0, "raté", "raté", 0);

Ce nous permettra de savoir ou chercher un peu
0
Crazy_Joe Messages postés 47 Date d'inscription samedi 2 juillet 2005 Statut Membre Dernière intervention 3 janvier 2008
19 juil. 2005 à 13:36
Effectivement, il m'affiche la boîte de
dialogue "raté". Sinon mon hInst est déclaré et global et dans WinMain
je mets: hInst = hThisInstance;
0
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
19 juil. 2005 à 14:28
Poste tout ton code pour voir... Parce que c'est étrange lol xD

void Aurevoir( void ); //Bonne journée
0
Crazy_Joe Messages postés 47 Date d'inscription samedi 2 juillet 2005 Statut Membre Dernière intervention 3 janvier 2008
19 juil. 2005 à 19:09
#include <windows.h>



const HBRUSH hCouleur = CreateSolidBrush(RGB(255,255,255));

HBRUSH hBackground = hCouleur;



static char szClassName[ ] = "FreeCutXP2";



HWND hWnd;

HINSTANCE hInst;



#define IDB_PARCOURIR 100

HWND hwndButtonParcourir;

HWND hwndEditPath;



LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);



static int nHauteur_Caractere = 20;

static int nLargeur_Caractere = 10;

static int nOrientation_Caractere = 0;

static char* Police_Utile = "Arial";



char szTextStatic1[500];



int WINAPI WinMain(HINSTANCE hThisInstance,


HINSTANCE hPrevInstance,


LPSTR lpcmdLine,

int nCmdShow)

{



hInst = hThisInstance;

WNDCLASSEX wincl;



wincl.hInstance = hThisInstance;

wincl.lpfnWndProc = WindowProcedure;

wincl.hbrBackground = hBackground;

wincl.style = CS_HREDRAW | CS_VREDRAW;

wincl.lpszClassName = szClassName;

wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);

wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);

wincl.hCursor = LoadCursor (NULL, IDC_ARROW);

wincl.lpszMenuName = NULL;

wincl.cbClsExtra = 0;

wincl.cbWndExtra = 0;



if (RegisterClassEx (&wincl) == false)

{

return 0;

}



hWnd = CreateWindowEx (0,szClassName,"FreeCutXP2",WS_CAPTION |
WS_SYSMENU |
WS_MINIMIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT,400,200,HWND_DESKTOP,NULL,hThisInstance,NULL);

ShowWindow (hWnd, nCmdShow);



MSG messages;



while (GetMessage(&messages,NULL,0,0))

{

TranslateMessage(&messages);

DispatchMessage(&messages);

}



return messages.wParam;

}



LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)

{

HDC hDc;

RECT rc={10,10,20,20};

PAINTSTRUCT ps;

HFONT Police;



switch
(message)


{

case WM_CREATE:



hwndButtonParcourir = CreateWindowEx(0, "BUTTON", "CLASSE BOUTON",


WS_CHILD |WS_VISIBLE | BS_PUSHBUTTON | WS_BORDER,


10, 40, 20, 50, hWnd, (HMENU)IDB_PARCOURIR ,


hInst, NULL);



if(!hwndButtonParcourir)MessageBox(0, "raté", "raté", 0);



hwndEditPath
= CreateWindowEx(0,
"EDIT", "",


WS_CHILD | ES_LEFT| WS_BORDER



| ES_AUTOVSCROLL |
ES_READONLY| ES_MULTILINE,


10, 40, 20, 50,hWnd, (HMENU)101 ,


(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);

break;



case WM_PAINT:

hDc = BeginPaint(hWnd,&ps);

GetClientRect(hWnd,&rc);



//Présentation, texte, cadre, etc...



EndPaint(hWnd, &ps);

break;



case WM_DESTROY:

//DeleteObject(Police);

PostQuitMessage(0);

break;



default:

return DefWindowProc(hwnd,message,wParam,lParam);

break;

}



return 0;

}
0
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
19 juil. 2005 à 19:19
En faite dans ta procédure de message de la forme

LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM);

le hwnd est celui de la fenêtre créee, donc la fenêtre parent ce n'est
pas hWnd ( celui défini dans WinMain ) mais celui de ta procédure,
c'est une fonction en faite, donc tu remplace hwnd et ça marche



Donc tu peux enlever le HWND hWnd en global

et je te conseil de mettre des handles de bouton dans ta procédure tu ne t'en servira que là normalement...

void Aurevoir( void ); //Bonne journée
0
Crazy_Joe Messages postés 47 Date d'inscription samedi 2 juillet 2005 Statut Membre Dernière intervention 3 janvier 2008
19 juil. 2005 à 19:53
Merci beaucoup, ça marche !



Merci.
0
Rejoignez-nous