Windows의 사용자 정의 버튼 제목으로 경고를 표시 하시겠습니까?
-
19-09-2019 - |
문제
CoreFoundation을 사용하면 다음과 함께 경고 대화 상자를 표시 할 수 있습니다.
CFUserNotificationDisplayAlert(0.0,
kCFUserNotificationPlainAlertLevel,
NULL, NULL, NULL,
CFSTR("Alert title"),
CFSTR("Yes?),
CFSTR("Affirmative"),
CFSTR("Nah"),
NULL, NULL);
Windows C API를 사용하여 이것을 어떻게 복제합니까? 내가 얻은 가장 가까운 것은 다음과 같습니다.
MessageBox(NULL, "Yes?", "Alert title", MB_OKCANCEL);
그러나 그 하드 코드 "OK"및 "cancel"은 버튼 제목으로, 내가 원하는 것이 아닙니다. 이 주위에 어떤 방법이 있습니까? 아니면 사용할 대체 기능이 있습니까?
해결책
SetWindowText를 사용하여 버튼의 범례를 변경할 수 있습니다. MessageBox ()는 실행 흐름을 차단하기 때문에이를 해결하려면 약간의 메커니즘이 필요합니다. 아래 코드는 타이머를 사용합니다.
FindWindow 코드는 MessageBox ()에 대한 부모가 없다는 것에 의존 할 수 있다고 생각하지만 확실하지 않습니다.
int CustomMessageBox(HWND hwnd, const char * szText, const char * szCaption, int nButtons)
{
SetTimer( NULL, 123, 0, TimerProc );
return MessageBox( hwnd, szText, szCaption, nButtons );
}
VOID CALLBACK TimerProc(
HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime
)
{
KillTimer( hwnd, idEvent );
HWND hwndAlert;
hwndAlert = FindWindow( NULL, "Alert title" );
HWND hwndButton;
hwndButton = GetWindow( hwndAlert, GW_CHILD );
do
{
char szBuffer[512];
GetWindowText( hwndButton, szBuffer, sizeof szBuffer );
if ( strcmp( szBuffer, "OK" ) == 0 )
{
SetWindowText( hwndButton, "Affirmative" );
}
else if ( strcmp( szBuffer, "Cancel" ) == 0 )
{
SetWindowText( hwndButton, "Hah" );
}
} while ( (hwndButton = GetWindow( hwndButton, GW_HWNDNEXT )) != NULL );
}
다른 팁
Windows Vista 이상에 자신을 기꺼이 묶으려면TaskDialog"기능. 나는 그것이 당신이 원하는 것을 할 수 있다고 생각합니다.
제휴하지 않습니다 StackOverflow