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
|
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#include <windows.h>
#pragma comment(lib, "comctl32.lib")
#include <commctrl.h>
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' \
version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
enum { ID_BTN, ON_CREATE = WM_USER+1 };
INT_PTR CALLBACK DialogProc(HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case ON_CREATE:
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof iccx;
iccx.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&iccx);
CreateWindow(TEXT("Button"), TEXT("Split Button"), BS_SPLITBUTTON | WS_VISIBLE |
WS_CHILD, 20, 20, 120, 40, hDialog, (HMENU)ID_BTN, (HINSTANCE)lParam, NULL);
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == ID_BTN)
{
MessageBox(hDialog, TEXT("Button clicked!"), TEXT("Test"), MB_OK);
// button code
return TRUE;
}
break;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case BCN_DROPDOWN:
NMBCDROPDOWN* pDropDown = (NMBCDROPDOWN*)lParam;
if (pDropDown->hdr.hwndFrom == GetDlgItem(hDialog, ID_BTN))
{
MessageBox(hDialog, TEXT("Drop-down clicked!"), TEXT("Test"), MB_OK);
// dropdown code
return TRUE;
}
break;
}
return FALSE;
case WM_CLOSE:
DestroyWindow(hDialog);
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
HWND hDialog = CreateWindow(WC_DIALOG, TEXT("Test"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
200, 200, 500, 400, NULL, NULL, hInst, NULL);
SetWindowLongPtr(hDialog, DWLP_DLGPROC, (LONG_PTR)DialogProc);
SendMessage(hDialog, ON_CREATE, 0, (LPARAM)hInst);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
if (!IsDialogMessage(hDialog, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
|