Hi,
I am trying to use CreateProcess to Size/Position my console windos, as well as modify the text and background colors.
I can Size/Position it, but have had no luck changing the text color or background color from my default settings.
Any clue, because I have tried to use the dwFillAttribute parameters every way I can.
Here is my file:
#include <windows.h>
#pragma comment (lib, "shell32.lib")
#include <winbase.h>
// Compile as win32.exe
void StartPrg(char *szCmdLine)
{
STARTUPINFO si;
PROCESS_INFORMATION pi = { 0 };
static char szBuff[260];
// static char Msg1[]="New Console Created.";
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.lpTitle = "Ed's Console";
si.dwFlags=STARTF_USEFILLATTRIBUTE;
si.dwFillAttribute=FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED;
si.dwFillAttribute=BACKGROUND_BLUE;
si.dwFlags=STARTF_USEPOSITION;
si.dwFlags=STARTF_USESIZE;
si.dwX= 200;
si.dwY = 200;
si.dwXSize = 300;
si.dwYSize = 100;
// Start the child process.
if (!CreateProcess(NULL,
// No module name (use command line)
szCmdLine, //.............. Command line
NULL, //..................... Process handle not inheritable
NULL, //..................... Thread handle not inheritable
FALSE, //.................... Set handle inheritance to FALSE
CREATE_NEW_CONSOLE, //............................. creation flags
NULL, //..................... Use parent's environment block
NULL, //..................... Use parent's starting directory
&si, //.......................... Pointer to STARTUPINFO structure
&pi) //......................... Pointer to PROCESS_INFORMATION structure
)
{
wsprintf(szBuff, "CreateProcess failed (%d).\n", GetLastError());
MessageBox(0, szBuff, "StartPrg", MB_OK);
return;
}
else
{
// // Comment or Not next line Wait until child process exits.
// WaitForSingleObject( pi.hProcess, INFINITE );
// wsprintf(szBuff, "Ed,%s\n", Msg1);
// MessageBox(0, szBuff, "Well", MB_OK | MB_ICONINFORMATION);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
lpCmdLine = "cmd.exe";
if (*lpCmdLine)
StartPrg(lpCmdLine);
return 0;
}
Thanks for any ideas,
Ed