[API win32 sans MFC] Création textbox et evenement bouton

Résolu
cs_nitrique Messages postés 344 Date d'inscription jeudi 1 mai 2003 Statut Membre Dernière intervention 4 avril 2011 - 16 mai 2006 à 14:38
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 17 mai 2006 à 17:31
Bonjour,


Je fais un petit soft pour windows CE (embedded) et je découvre en même temps le C++.
J'aimerais comprendre le fonctionnement de base pour créer des composants (textbox et bouton).


Je me sert de CreateWindow (est-ce la bonne solution ?).
hEdit = CreateWindow(_T("EDIT"),_T("Texte"),WS_VISIBLE|WS_CHILD|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL,0,0,150,100,hWnd,NULL,hInst,NULL);
(hEdit est déclaré à la racine de la classe)
Seulement ça ne marche que si il est dans le WM_PAINT... Ca me semble étrange de le créer à chaque fois !
En toute logique, il faut le créer une fois dans le WM_CREATE et le redessiner dans le WM_PAINT mais ça ne marche pas...


J'ai retourné le Web mais pas moyen de trouver des exemples pour cette chose qui a l'air si simple !


Quelqu'un peut-il m'éclairer ?


Merci d'avance.

[;)] David, à VERSAILLES
http://www.gentag.fr
A voir également:

6 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
16 mai 2006 à 19:52
case WM_COMMAND:
switch(wParam) {
  case idTonBouton:
    SetWindowText(hedit, "Mon texte");
    return 0;
  case autreID:
    etc....
}
......

ciao...
BruNews, MVP VC++
3
mogwai93 Messages postés 362 Date d'inscription mardi 31 décembre 2002 Statut Membre Dernière intervention 4 novembre 2023
16 mai 2006 à 14:52
pour creer un textbox ou edit ou tout autre fenetre
--> CreateWindow
ou
--> utiliser les ressources

et il faut bien le creer dans le WM_CREATE
le WM_PAINT de le dessine pas

voici un exemple qui fonctionne sous windows "tout court" donc ca devrait fonctionner pour windows CE (embedded) à qques parametres près
---------------


#include <windows.h>


/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;


/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";


int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)


{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */


hInst = hThisInstance;
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);


/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;


/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;


/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);


/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);


/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}


/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}



/* This function is called by the Windows function DispatchMessage() */


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


switch (message) /* handle the messages */
{
case WM_CREATE:
hEdit = CreateWindow("EDIT","Texte",WS_VISIBLE|WS_CHILD|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL,0,0,150,100,hwnd,NULL,hInst,NULL);


break;


case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}


return 0;
}
0
cs_nitrique Messages postés 344 Date d'inscription jeudi 1 mai 2003 Statut Membre Dernière intervention 4 avril 2011 1
16 mai 2006 à 15:18
Bonjour Mogwai93,
Merci de ta rapidité !

En effet, ça marche... Je ne sais pas ce qu'il s'est passé quand j'avais essayé avant !
J'aimerais aussi savoir comment créer un bouton qui, quand on clique dessus, change le texte du texteBox !

Avec ces bases, je pourrais comprendre le fonctionnement de C++ et aller plus loin de moi même.

[;)] David, à VERSAILLES
http://www.gentag.fr
0
cs_nitrique Messages postés 344 Date d'inscription jeudi 1 mai 2003 Statut Membre Dernière intervention 4 avril 2011 1
17 mai 2006 à 11:07
Impeccable, merci pour tout BruNews

[;)] David, à VERSAILLES
http://www.gentag.fr
0

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

Posez votre question
cs_nitrique Messages postés 344 Date d'inscription jeudi 1 mai 2003 Statut Membre Dernière intervention 4 avril 2011 1
17 mai 2006 à 11:19
Heu...

Juste comme ça... Comment on ajoute du texte ?
J'ai bien essayé: SendMessage(hEdit,CB_ADDSTRING,0,(LPARAM)(LPCTSTR)_T("Entree"));
Mais il me semble que c'est pour une comboBox...

[;)] David, à VERSAILLES
http://www.gentag.fr
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
17 mai 2006 à 17:31
ben oui, CB_xxxx est message combo.

ciao...
BruNews, MVP VC++
0
Rejoignez-nous