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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
| #include <stdlib.h>
#include <stdio.h>
#include <windows.h> //ajouter les commandes pour le compilateur Dev-C++ 4: -mwindows -lwsock32
#include <winsock.h> //
#include <commctrl.h>
// Global Variables:
HINSTANCE hInst; // current instance
// The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void addcolumn(int, int, char column_name[16], int);
const HMENU ID_BUTTON_OK = (HMENU)1;
const HMENU ID_LIST = (HMENU)2;
const HMENU ID_EDIT = (HMENU)3;
HWND hbouton;
HWND hedit;
HWND hliste;
HWND hcolumn;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
//wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.hbrBackground = static_cast<HBRUSH> (GetStockObject(LTGRAY_BRUSH));
wcex.lpszMenuName = 0;
wcex.lpszClassName = "ma fenetre";
wcex.hIconSm = 0;
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow("ma fenetre", "Mon titre", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 300, 600, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
int static xbutton, ybutton;
switch (message)
{
case WM_CREATE:
xbutton = LOWORD(GetDialogBaseUnits()); // Abscisse de la fenêtre principale //
ybutton = HIWORD(GetDialogBaseUnits()); // Ordonnée de la fenêtre principale //
hbouton = CreateWindow("BUTTON", "OK", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
20 +xbutton, 435 + ybutton, 50, 25, hWnd, ID_BUTTON_OK, hInst, NULL);
RECT rcl;
INITCOMMONCONTROLSEX icex;
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
// Create the list-view window in report view with label
// editing enabled.
GetClientRect (hWnd, &rcl);
hliste = CreateWindow (WC_LISTVIEW, "",
WS_VISIBLE |WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
10, 10, 80, 80,
hWnd, (HMENU) 301, hInst, NULL);
if (hliste == NULL)
return NULL;
addcolumn(301,1,"prem col",30);
hedit = CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD |WS_BORDER ,
20+xbutton, 500 +ybutton, 300, 25, hWnd, ID_EDIT, hInst, NULL);
SetFocus(hedit);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_BUTTON_OK:
char text[200];
GetWindowText( hedit, text, 200 );
SendMessage( hliste, LB_ADDSTRING, 0, (long)&text);
SetWindowText( hedit, "" );
SetFocus(hedit);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
void addcolumn(int listview_ID, int column_number, char column_name[16], int column_width)
{
char *column_nam;
column_nam=column_name;
LVCOLUMN lvc;
lvc.mask=LVCF_WIDTH|LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT;
lvc.cx=column_width;
lvc.fmt=LVCFMT_LEFT;
lvc.pszText=column_nam;
lvc.cchTextMax=strlen(column_name);
lvc.iSubItem=((listview_ID-300)*10+300)+column_number+1;
hcolumn=SendMessage(hliste, LVM_INSERTCOLUMN, column_number,(LPARAM)&lvc);
} |
Partager