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
| #include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#pragma comment(lib, "comctl32.lib")
#define IDC_EDIT1 10001
#define IDC_UPDOWN1 10002
LRESULT CALLBACK TestUpDownWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT ret = 0;
switch(uMsg)
{
case WM_CREATE:
{
HWND hEdit = CreateWindowEx(0, _T("EDIT"), _T("42"), ES_NUMBER|WS_BORDER|WS_VISIBLE|WS_CHILD, 20, 20, 80, 20, hWnd, (HMENU)IDC_EDIT1, NULL, NULL);
HWND hUpDown = CreateWindowEx(0, UPDOWN_CLASS, _T("UpDown1"), WS_VISIBLE|WS_BORDER|WS_CHILD|UDS_SETBUDDYINT, 120, 20, 20, 20, hWnd, (HMENU)IDC_UPDOWN1, NULL, NULL);
SendDlgItemMessage(hWnd, IDC_UPDOWN1, UDM_SETBUDDY, (WPARAM)hEdit, 0);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
ret = DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
}
return ret;
}
void TestUpDown(void)
{
{
INITCOMMONCONTROLSEX icx = {0};
icx.dwSize = sizeof icx;
icx.dwICC = ICC_UPDOWN_CLASS;
//#ifdef ICC_STANDARD_CLASSES
//icx.dwICC |= ICC_STANDARD_CLASSES;
//#endif
if(!InitCommonControlsEx(&icx))
{
DWORD err = GetLastError();
MessageBox(NULL, _T("Échec de InitCommonControlsEx()"), NULL, MB_OK);
return;
}
}
{
WNDCLASSEX wcx = {0};
wcx.cbSize = sizeof wcx;
wcx.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hInstance = GetModuleHandle(NULL);
wcx.lpfnWndProc = TestUpDownWndProc;
wcx.lpszClassName = _T("TestUpDown");
wcx.style = CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&wcx))
{
MessageBox(NULL, _T("Échec de RegisterClassEx()"), NULL, MB_OK);
return;
}
}
{
HWND hWnd = CreateWindowEx(0, _T("TestUpDown"), _T("Test contrôle UpDown"),
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT, 0, 320, 240, NULL, NULL, GetModuleHandle(NULL), NULL
);
MSG msg;
if(hWnd==NULL)
{
MessageBox(NULL, _T("Échec de CreateWindowEx()"), NULL, MB_OK);
return;
}
else
ShowWindow(hWnd, SW_SHOWNORMAL);
while(GetMessage(&msg, NULL, 0, 0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} |
Partager