OK down below where my IDM button is under WM_COMMAND: is my checkbox processing body.
Under WM_CREATE is the checkbox being created. The problem is my application always starts
with the check box checked, and will NOT let me uncheck it with the mouse. Please help would
be great!
/********************************************************************/
/* Account Reset Tool*/
/******************************************************/
/*******Developed by: Cody Oebel******************/
/****** Cody.Oebel@petco.com **************/
/**************************/
// Preprocessor Directives for auotmation functionality
#include <windows.h>
#include <dos.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
#define IDC_MAIN_BUTTON 101 // Button identifier
#define IDC_MAIN_EDIT 102 // Edit box identifier
HWND hEdit;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static char *title = TEXT("Account Reset Tool by: Cody Oebel");
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = TEXT( "PasswordResetTool" );
wc.hInstance = hInstance ;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClass(&wc);
CreateWindow( wc.lpszClassName, title,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
150, 350, 430, 190, 0, 0, hInstance, 0);
while( GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CREATE:
{
// Create an edit box
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
"",
WS_CHILD|WS_VISIBLE|
ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
10,
100,
300,
50,
hwnd,
(HMENU)IDC_MAIN_EDIT,
GetModuleHandle(NULL),
NULL);
HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit,
WM_SETFONT,
(WPARAM)hfDefault,
MAKELPARAM(FALSE,0));
SendMessage(hEdit,
WM_SETTEXT,
NULL,
(LPARAM)"Enter users name");
// Create a push button
HWND hWndButton=CreateWindowEx(NULL,
"BUTTON",
"Unlock and Reset Users Password to Petco1234",
WS_TABSTOP|WS_VISIBLE|
WS_CHILD|BS_DEFPUSHBUTTON,
40,
60,
250,
24,
hwnd,
(HMENU)IDC_MAIN_BUTTON,
GetModuleHandle(NULL),
NULL);
SendMessage(hWndButton,
WM_SETFONT,
(WPARAM)hfDefault,
MAKELPARAM(FALSE,0));
CreateWindow(TEXT("button"), TEXT("Unlock Account"),
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
20, 20, 185, 35,
hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
CheckDlgButton(hwnd, 1, BST_CHECKED);
break;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_MAIN_BUTTON:
{
BOOL checked = IsDlgButtonChecked(hwnd, 1);
if (checked)
{
CheckDlgButton(hwnd, 1, BST_UNCHECKED);
MessageBox(0,
"Unlocking user and resetting users password to Petco1234",
"Unlocking account, and PW reset",
MB_ICONINFORMATION);
LPWSTR buffer[256];
SendMessage(hEdit,
WM_GETTEXT,
sizeof(buffer)/sizeof(buffer[0]),
reinterpret_cast<LPARAM>(buffer));
/*MessageBox(0,
(LPCSTR)buffer,
"Information",
MB_ICONINFORMATION);
*/
// ADD THE USERS NAME TO ADMINISTRATORS GROUP
ofstream out;
out.open("c:\\UserReset.dat");
out<<(LPCSTR)buffer;
out.close();
ifstream in;
in.open("c:\\UserReset.dat");
string userid;
in>>userid;
in.close();
string cmd = "/C net user "+userid+" Petco1234 /domain /active:yes";
LPCSTR lpcmd = cmd.c_str();
//system(cmd.c_str()); Need to shellexcute command line invisible here
ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
//Unlock users account, and reset password to Petco1234
}
else
{
//CheckDlgButton(hwnd, 1, BST_UNCHECKED);
MessageBox(0,
"Resetting users password to Petco1234",
"Reset Password",
MB_ICONINFORMATION);
LPWSTR buffer[256];
SendMessage(hEdit,
WM_GETTEXT,
sizeof(buffer)/sizeof(buffer[0]),
reinterpret_cast<LPARAM>(buffer));
/*MessageBox(0,
(LPCSTR)buffer,
"Information",
MB_ICONINFORMATION);
*/
// ADD THE USERS NAME TO ADMINISTRATORS GROUP
ofstream out;
out.open("c:\\UserReset.dat");
out<<(LPCSTR)buffer;
out.close();
ifstream in;
in.open("c:\\UserReset.dat");
string userid;
in>>userid;
in.close();
string cmd = "/C net user "+userid+" Petco1234 /domain";
LPCSTR lpcmd = cmd.c_str();
//system(cmd.c_str()); Need to shellexcute command line invisible here
ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
//Unlock users account, and reset password to Petco1234
};
}
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}