Edit Control

cybermatthieu Messages postés 7 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 30 septembre 2004 - 20 juin 2003 à 04:27
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 20 juin 2003 à 08:28
Bonjours,
Je suis en Train d'apprendre comment progrmmer en Win32 avec la Class Windows.h. Ce petit programme ne fait q'afficher des caracter mais j'ai une boite de text editable ou je peut changer le type de caractere a afficher mais voila je ne peut pas ecrir rien dedant!

merci,

voici mon code:
#include <windows.h>

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

HINSTANCE hInstGlobal;
HWND hEdit;

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
hInstGlobal = hInstance;

WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "WinProg";

RegisterClass(&WndClass);

HWND hWindow;
hWindow = CreateWindow("WinProg","Window",WS_OVERLAPPEDWINDOW,
0,0,600,460,NULL,NULL,
hInstance, NULL);

ShowWindow ( hWindow, nCmdShow);

UpdateWindow(hWindow);

MSG Message;
while (GetMessage(&Message,NULL,0 ,0))
{
DispatchMessage(&Message);
}

return (Message.wParam);
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
WPARAM wParam, LPARAM lParam){
switch(uiMessage){
case WM_CREATE:
HWND hButton, hButtonExit, hButtonCls;
hButton = CreateWindow("BUTTON","Show Font", WS_CHILD | WS_VISIBLE |
BS_PUSHBUTTON,10,320,140,20,hWnd, (HMENU) 1,
hInstGlobal, NULL);
hButtonExit = CreateWindow("BUTTON","Exit", WS_CHILD | WS_VISIBLE |
BS_PUSHBUTTON,160,320,140,20,hWnd, (HMENU) 2,
hInstGlobal, NULL);
hButtonCls = CreateWindow("BUTTON","Clear Screen", WS_CHILD | WS_VISIBLE |
BS_PUSHBUTTON,310,320,140,20,hWnd, (HMENU) 3,
hInstGlobal, NULL);

hEdit = CreateWindow("EDIT","SYSTEM_FONT",
WS_CHILD | WS_VISIBLE |
WS_BORDER | ES_AUTOHSCROLL ,
10,340,120,20,hWnd,
(HMENU) 1,
hInstGlobal, NULL);
return 0 ;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED){
if (LOWORD(wParam)==1){
HDC hdc;
hdc = GetDC (GetParent((HWND) lParam));
HFONT hFont;
char string1[255];

SendMessage (hEdit, WM_GETTEXT, 256, (LPARAM) string1);
bool FontDa=0;
if (lstrcmp(string1,"SYSTEM_FONT")==0){
hFont = (HFONT) GetStockObject(SYSTEM_FONT);
FontDa = 1;
}

SelectObject (hdc, hFont);
RECT rect;
SetRect (&rect,0,0,480,280);
HBRUSH hBrush;
hBrush = CreateSolidBrush(RGB(255,255,255));
FillRect (hdc, &rect, hBrush);
TextOut (hdc,340,10,string1,lstrlen(string1));

TEXTMETRIC tm;
GetTextMetrics (hdc, &tm);

int i;
int ix=0,iy=0;

char string[2];
string[1] = 0;
for(i=0;i<255;i++){
string[0] = i;
TextOut (hdc,ix,iy, string,lstrlen(string));
iy = iy + tm.tmHeight;
if((iy/tm.tmHeight) == 16){
iy = 0;
ix = ix + 20;
}
}
ReleaseDC (GetParent((HWND) lParam), hdc);
}
if(LOWORD(wParam) == 2){
SendMessage (GetParent((HWND)lParam),WM_DESTROY,0,0);
return 0;
}
if(LOWORD(wParam) == 3){
HDC hdc;
hdc = GetDC (GetParent((HWND) lParam));
RECT rect;
SetRect (&rect,0,0,480,280);
HBRUSH hBrush;
hBrush = CreateSolidBrush(RGB(255,255,255));
FillRect (hdc, &rect, hBrush);
return 0;
}
}

return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc (hWnd, uiMessage,wParam, lParam);
}
}

1 réponse

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
20 juin 2003 à 08:28
Tres bien d'apprendre a programmer sur win32. Pour debuter avec les controles(button, edit...) le mieux est de faire tes tests sur des dialogbox. Ici l'enchainement des evenements de ta wndproc n'est pas au point. Regarde dans mes sources et reproduit le meme modele evenementiel.
La reference en la matiere reste le Petzold.
Tu le trouveras complet ici:
http://perso.wanadoo.fr/persans-brunews/
CP5Sources.zip et CP5.zip
BruNews, ciao...
0
Rejoignez-nous