RedPanda-CPP/redpanda-win-git-askpass/main.cpp

74 lines
2.0 KiB
C++
Raw Normal View History

2022-02-25 08:58:58 +08:00
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include <stdio.h>
HINSTANCE hInst;
2022-02-25 18:56:34 +08:00
LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
2022-02-25 08:58:58 +08:00
2022-02-25 18:56:34 +08:00
LRESULT CALLBACK TxtPasswordWndProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
2022-02-25 08:58:58 +08:00
WNDPROC lpfnTxtPasswordWndProc=NULL;
HWND hMainDlg = NULL;
HWND hwndTxtPassword = NULL;
int WINAPI WinMain(HINSTANCE hInstance,
2022-04-25 12:43:23 +08:00
HINSTANCE /*hPrevInstance*/,
2022-02-25 08:58:58 +08:00
LPTSTR lpCmdLine, int nCmdShow) {
MSG msg;
hMainDlg = CreateDialog(hInstance, (LPCTSTR)IDD_MAIN_DIALOG, 0,(DLGPROC)MainDlgProc);
ShowWindow(hMainDlg, nCmdShow);
hwndTxtPassword = GetDlgItem(hMainDlg,ID_TXT_PASSWORD);
lpfnTxtPasswordWndProc = (WNDPROC) SetWindowLongPtr(hwndTxtPassword, GWLP_WNDPROC, (LONG_PTR)TxtPasswordWndProc);
HWND hwndTxtPrompt = GetDlgItem(hMainDlg,ID_TXT_PROMPT);
Static_SetText(hwndTxtPrompt, lpCmdLine);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//In Subclass Proc
LRESULT CALLBACK TxtPasswordWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_KEYDOWN:
if (wParam==VK_RETURN) {
char s[500+1];
Edit_GetText(hwndTxtPassword,s,500);
printf(s);
DestroyWindow(hMainDlg);
return TRUE;
}
break;
}
return CallWindowProc(lpfnTxtPasswordWndProc, hwnd, msg, wParam, lParam);
}
2022-04-25 12:43:23 +08:00
LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/) {
2022-02-25 08:58:58 +08:00
switch (message) {
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam)) {
case IDOK :
case IDCANCEL :
DestroyWindow(hDlg);
return TRUE ;
}
break ;
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
};
2022-02-25 18:56:34 +08:00
return FALSE;
2022-02-25 08:58:58 +08:00
}