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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| #include<Windows.h>
#include<vector>
#define ID_ABOUT 40000
#define ID_AIDE 40001
#define ID_QUIT 40002
#define ID_EDIT 40003
#define ID_BUTTON 40004
int i=1;
char text[100]="Default";
HINSTANCE ghInstance;
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
HMENU hMenu;
HWND button;
HWND edit[100];
switch (message)
{
case WM_CREATE:
hMenu = CreateMenu();
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
AppendMenu (hMenu, MF_STRING, ID_QUIT, TEXT ("Quitter")) ;
SetMenu(hwnd,hMenu);
button = CreateWindowEx(0, "BUTTON", "Recopier le texte", WS_VISIBLE|WS_CHILD| WS_BORDER, 20, 20, 200, 40, hwnd, (HMENU)ID_BUTTON, ghInstance, NULL);
edit[0] = CreateWindowEx(0, "EDIT", "", WS_VISIBLE|WS_CHILD| WS_BORDER|ES_WANTRETURN|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL, 20, 80, 200, 20, hwnd, (HMENU)ID_EDIT, ghInstance, NULL);
return 0 ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
TextOut (hdc, 20, 60, "Texte à recopier :", 18);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case ID_QUIT:
PostQuitMessage (0) ;
return 0 ;
case ID_BUTTON :
if (HIWORD (wParam) == BN_CLICKED)
edit[i] = CreateWindowEx(0, "EDIT", "", WS_VISIBLE|WS_CHILD| WS_BORDER|ES_WANTRETURN|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL, 20, 150+i++*30, 200, 20, hwnd, (HMENU)ID_EDIT, ghInstance, NULL);
GetWindowText(edit[0],text,100); //copier le texte contenu dans edit[0] dans la variable text
SetWindowText(edit[i],text); //mettre la valeur de la variable text dans le texte de edit[i]
// --> Ca ne marche pas, edit[i] est vide à sa creation
return 0;
}
break ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
ghInstance = hInstance;
static TCHAR nomApp[] = TEXT ("Demo") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = nomApp ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Nt ou superieur uniquement"), nomApp, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW, nomApp,"",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,250, 500, NULL,NULL,hInstance,NULL);
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
} |
Partager