📄 pgpoptionsdialog.cpp
字号:
hwndOptionsControl,
poiParent,
hdc,hFont,
&optionData,
xpos,ypos,MaxWidth);
}
poi->nextChild=
CreateOptionsControls(hwndOptionsControl,poi,hdc,hFont,
xpos+INDENT,ypos,MaxWidth,
optionData.subOptions);
if(poi->bDisableChildrenIfUnchecked)
{
EnableOrDisableChildren(poi,poi->dwTempValue);
}
if(OldOption!=NULL)
OldOption->nextSibling=poi;
OldOption=poi;
if(FirstOption==NULL)
FirstOption=poi;
++optionIndex;
}
return( FirstOption );
}
LRESULT CALLBACK CustomOptionsWndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_CREATE :
{
PGPOptionListRef options;
LPCREATESTRUCT lpcs;
HFONT hFont;
LOGFONT lf;
int ypos;
HDC hdc;
TEXTMETRIC tm;
int HeaderWidths;
POPTDLG pod;
pod=(POPTDLG)malloc(sizeof(OPTDLG));
memset(pod,0x00,sizeof(OPTDLG));
SetWindowLong(hwnd, GWL_USERDATA, (DWORD)pod);
lpcs=(LPCREATESTRUCT)lParam;
options=(PGPOptionListRef)lpcs->lpCreateParams;
pod->options=options;
SystemParametersInfo (SPI_GETICONTITLELOGFONT,
sizeof(LOGFONT), &lf, 0);
hFont=CreateFontIndirect (&lf);
hdc=GetDC(hwnd);
SelectObject(hdc,hFont);
GetTextMetrics (hdc, &tm) ;
pod->cxChar = tm.tmAveCharWidth ;
pod->cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * (pod->cxChar) / 2 ;
pod->cyChar = tm.tmHeight + tm.tmExternalLeading ;
pod->MaxWidth = GetClientWidth(hwnd)-2*(pod->cyChar);
HeaderWidths=MeasureOptionsControls(hdc,0,options);
if(HeaderWidths>pod->MaxWidth)
pod->MaxWidth=HeaderWidths;
ypos=pod->cyChar;
pod->headpoi=CreateOptionsControls(hwnd,NULL,hdc,hFont,0,&ypos,pod->MaxWidth,options);
ypos+=pod->cyChar; // margin at bottom?
ReleaseDC(hwnd,hdc);
pod->NumLines=ypos/pod->cyChar;
return 0 ;
}
case WM_DESTROY:
{
POPTDLG pod;
pod=(POPTDLG)GetWindowLong(hwnd,GWL_USERDATA);
free(pod);
break;
}
case WM_COMMAND:
{
HWND hwndItem;
hwndItem=(HWND)lParam;
if(hwndItem!=NULL)
{
POPTIONINFO poi;
char WinClass[255];
poi=(POPTIONINFO)GetWindowLong(hwndItem,GWL_USERDATA);
GetClassName(hwndItem,WinClass,255);
if(!strcmp(WinClass,"Button"))
{
poi->dwTempValue=!poi->dwTempValue;
Button_SetCheck(hwndItem,poi->dwTempValue);
if(poi->bDisableListBoxesIfChecked)
{
// Hardcode in the conventional encryption disabling
// (Ugly I know, but there is no API for this)
HWND hDlg;
hDlg=GetParent(hwnd);
EnableWindow(GetDlgItem(hDlg,IDC_USER_ID_LIST),!poi->dwTempValue);
EnableWindow(GetDlgItem(hDlg,IDC_RECIPIENT_LIST),!poi->dwTempValue);
}
if(poi->bDisableChildrenIfUnchecked)
{
EnableOrDisableChildren(poi,poi->dwTempValue);
}
}
if(!strcmp(WinClass,"ComboBox"))
{
if(HIWORD(wParam)==CBN_SELCHANGE)
{
poi->dwTempValue=SendMessage(hwndItem,CB_GETCURSEL,0,0)+1;
}
}
}
return 0;
}
case WM_SIZE :
{
int x,y;
POPTDLG pod;
pod=(POPTDLG)GetWindowLong(hwnd,GWL_USERDATA);
pod->cxClient = LOWORD (lParam) ;
pod->cyClient = HIWORD (lParam) ;
// pod->iVscrollPos=pod->iHscrollPos=0;
pod->iVscrollMax = max (0, pod->NumLines - pod->cyClient/ pod->cyChar) ;
x = min (pod->iVscrollPos, pod->iVscrollMax) ;
y = x - pod->iVscrollPos;
ScrollWindow (hwnd, 0, -(pod->cyChar) * y, NULL, NULL) ;
pod->iVscrollPos=x;
SetScrollRange (hwnd, SB_VERT, 0, pod->iVscrollMax, FALSE) ;
SetScrollPos (hwnd, SB_VERT, pod->iVscrollPos, TRUE) ;
pod->iHscrollMax = max (0,
2 + (pod->MaxWidth + 2*(pod->cyChar) - pod->cxClient) / pod->cxChar) ;
x = min (pod->iHscrollPos, pod->iHscrollMax) ;
y = x - pod->iHscrollPos;
ScrollWindow (hwnd, -(pod->cxChar) * y, 0, NULL, NULL) ;
pod->iHscrollPos=x;
SetScrollRange (hwnd, SB_HORZ, 0, pod->iHscrollMax, FALSE) ;
SetScrollPos (hwnd, SB_HORZ, pod->iHscrollPos, TRUE) ;
return 0 ;
}
case WM_VSCROLL :
{
POPTDLG pod;
pod=(POPTDLG)GetWindowLong(hwnd,GWL_USERDATA);
switch (LOWORD (wParam))
{
case SB_TOP :
pod->iVscrollInc = -(pod->iVscrollPos) ;
break ;
case SB_BOTTOM :
pod->iVscrollInc = pod->iVscrollMax - (pod->iVscrollPos) ;
break ;
case SB_LINEUP :
pod->iVscrollInc = -1 ;
break ;
case SB_LINEDOWN :
pod->iVscrollInc = 1 ;
break ;
case SB_PAGEUP :
pod->iVscrollInc = min (-1, -(pod->cyClient) / pod->cyChar) ;
break ;
case SB_PAGEDOWN :
pod->iVscrollInc = max (1, pod->cyClient / pod->cyChar) ;
break ;
case SB_THUMBTRACK :
pod->iVscrollInc = HIWORD (wParam) - pod->iVscrollPos ;
break ;
default :
pod->iVscrollInc = 0 ;
}
pod->iVscrollInc = max (-(pod->iVscrollPos),
min (pod->iVscrollInc, pod->iVscrollMax - (pod->iVscrollPos))) ;
if (pod->iVscrollInc != 0)
{
pod->iVscrollPos += pod->iVscrollInc ;
ScrollWindow (hwnd, 0, -(pod->cyChar) * pod->iVscrollInc, NULL, NULL) ;
SetScrollPos (hwnd, SB_VERT, pod->iVscrollPos, TRUE) ;
UpdateWindow (hwnd) ;
}
return 0 ;
}
case WM_HSCROLL :
{
POPTDLG pod;
pod=(POPTDLG)GetWindowLong(hwnd,GWL_USERDATA);
switch (LOWORD (wParam))
{
case SB_LINEUP :
pod->iHscrollInc = -1 ;
break ;
case SB_LINEDOWN :
pod->iHscrollInc = 1 ;
break ;
case SB_PAGEUP :
pod->iHscrollInc = -8 ;
break ;
case SB_PAGEDOWN :
pod->iHscrollInc = 8 ;
break ;
case SB_THUMBPOSITION :
pod->iHscrollInc = HIWORD (wParam) - pod->iHscrollPos ;
break ;
default :
pod->iHscrollInc = 0 ;
}
pod->iHscrollInc = max (-(pod->iHscrollPos),
min (pod->iHscrollInc, pod->iHscrollMax - (pod->iHscrollPos))) ;
if (pod->iHscrollInc != 0)
{
pod->iHscrollPos += pod->iHscrollInc ;
ScrollWindow (hwnd, -(pod->cxChar) * pod->iHscrollInc, 0, NULL, NULL) ;
SetScrollPos (hwnd, SB_HORZ, pod->iHscrollPos, TRUE) ;
}
return 0 ;
}
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
HWND CreateOptionsControl(HWND hwndParent,
PGPOptionListRef options,
int x,int y,int dx,int dy)
{
static char szClassName[] = "CustomOptionsControl" ;
WNDCLASSEX wndclass ;
HWND hwndOptionsWindow;
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = CustomOptionsWndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = gPGPsdkUILibInst ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szClassName ;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
RegisterClassEx (&wndclass) ;
hwndOptionsWindow = CreateWindowEx (WS_EX_CONTROLPARENT,szClassName, "CustomOptionsWindow",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | WS_DLGFRAME | WS_TABSTOP,
x,y,
dx,dy,
hwndParent,NULL,gPGPsdkUILibInst,(LPVOID)options) ;
return hwndOptionsWindow;
}
// Helper function for SaveOptionSettings
void RecurseOptionSettings(POPTIONINFO poi)
{
while(poi!=NULL)
{
*(poi->pdwFinalValue)=poi->dwTempValue;
// Go through the children
RecurseOptionSettings(poi->nextChild);
poi=poi->nextSibling;
}
}
// Save all temp values to output (Use for OK cases...
// For cancel everything is thrown away)
void SaveOptionSettings(HWND hwndOptionsWindow)
{
POPTDLG pod;
if(hwndOptionsWindow!=NULL)
{
pod=(POPTDLG)GetWindowLong(hwndOptionsWindow,GWL_USERDATA);
RecurseOptionSettings(pod->headpoi);
}
}
void ResizeOptionsControl(HWND hwndOptions,
int x,int y,
int dx,int dy)
{
if(hwndOptions!=NULL)
{
InvalidateRect(hwndOptions,NULL,TRUE);
MoveWindow(hwndOptions,
x,y,
dx,dy,TRUE);
}
}
void MoveOptionsDialog(HWND hDlg,HWND hwndChild,
int cxClient,int cyClient)
{
ResizeOptionsControl(hwndChild,
10,10,cxClient-20,cyClient-55);
InvalidateRect(GetDlgItem(hDlg, IDOK),NULL,TRUE);
MoveWindow(GetDlgItem(hDlg, IDOK),
cxClient-175,cyClient-35,
75,25,TRUE);
InvalidateRect(GetDlgItem(hDlg, IDCANCEL),NULL,TRUE);
MoveWindow(GetDlgItem(hDlg, IDCANCEL),
cxClient-85,cyClient-35,
75,25,TRUE);
}
BOOL CALLBACK
OptionsDialogProc (HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
RECT rc;
CPGPOptionsDialogOptions *options;
PDLGDATA pdd;
pdd=(PDLGDATA)lParam;
SetWindowLong(hDlg, GWL_USERDATA, (DWORD)pdd);
options=pdd->options;
if(options->mPrompt!=NULL)
SetWindowText(hDlg,options->mPrompt);
GetClientRect(hDlg,&rc);
pdd->hwndOptions=CreateOptionsControl(hDlg,
options->mClientOptions,
10,10,rc.right-rc.left-10,
rc.bottom-rc.top-20);
MoveOptionsDialog(hDlg,pdd->hwndOptions,
rc.right-rc.left,
rc.bottom-rc.top);
return TRUE;
}
case WM_SIZE :
{
int cxClient, cyClient;
CPGPOptionsDialogOptions *options;
PDLGDATA pdd;
pdd=(PDLGDATA)GetWindowLong(hDlg,GWL_USERDATA);
options=pdd->options;
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
MoveOptionsDialog(hDlg,pdd->hwndOptions,
cxClient,
cyClient);
break ;
}
case WM_GETMINMAXINFO:
{
MINMAXINFO* lpmmi;
lpmmi = (MINMAXINFO*) lParam;
lpmmi->ptMinTrackSize.x = MINDLGX;
lpmmi->ptMinTrackSize.y = MINDLGY;
break;
}
case WM_COMMAND:
{
switch(wParam)
{
case IDOK:
{
PDLGDATA pdd;
pdd=(PDLGDATA)GetWindowLong(hDlg,GWL_USERDATA);
SaveOptionSettings(pdd->hwndOptions);
EndDialog(hDlg, TRUE);
break;
}
case IDCANCEL:
{
EndDialog(hDlg, FALSE);
break;
}
}
break;
}
case WM_QUIT:
case WM_CLOSE:
case WM_DESTROY:
{
EndDialog(hDlg, FALSE);
break ;
}
}
return FALSE;
}
PGPError
pgpOptionsDialogPlatform(
PGPContextRef context,
CPGPOptionsDialogOptions *options)
{
PGPError err = kPGPError_NoErr;
PDLGDATA pdd;
pdd=(PDLGDATA)malloc(sizeof(DLGDATA));
memset(pdd,0x00,sizeof(DLGDATA));
pdd->options=options;
InitRandomKeyHook(&hhookKeyboard,&hhookMouse);
DialogBoxParam(gPGPsdkUILibInst,
MAKEINTRESOURCE(IDD_OPTIONSDIALOG),
options->mHwndParent,
(DLGPROC)OptionsDialogProc,
(LPARAM)pdd);
UninitRandomKeyHook(hhookKeyboard,hhookMouse);
free(pdd);
return( err );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -