NO

Author Topic: dwFillAttribute not working with CreateProcess and Create_New_Console  (Read 5230 times)

EdPellesC99

  • Guest

   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:

Code: [Select]

#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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Use this:
Code: [Select]
si.dwFlags=STARTF_USEFILLATTRIBUTE | STARTF_USESIZE | STARTF_USEPOSITION;
Or this way adding options:
Code: [Select]
si.dwFlags=STARTF_USEFILLATTRIBUTE;
...
si.dwFlags |= STARTF_USEPOSITION;
...
si.dwFlags |= STARTF_USESIZE;
« Last Edit: May 06, 2010, 10:03:02 PM by timovjl »
May the source be with you

EdPellesC99

  • Guest


  Thanks so much Timo, both of your solutions worked.


  I did have one other problem, when I tried your solution (either one), I saw a flash of the correct console, but it was quickly replaced by the default colors on my cmd.exe file.

  I have set my defaults using the right click on the console title bar method and choosing defaults. I had mine set to aqua with white text. This is the window I would see, after I saw the flash of the correct foreground and background colors.
I reset my default's using the right click method, setting the background to black and the text to white.

  My problem remained unchanged.

  I then went to the registry and found the culprit on this key:

Quote

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"DefaultColor"=dword:0000003f




   For some reason the registry was not taking my default changes.
I edited the key to be:

"DefaultColor"=dword:00000000

   (This is the only place in the registry for "DefaultColor" having to do with the console.)

   Then your solution worked in full glory.

   Thanks Timo, I would never have tried your solutions, I had concluded the feature was perhaps deprecated.

   Tx, Ed