GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Aug-2007, 23:33
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 406
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

win32 CreateProcess(), STARTUPINFO not working well for 98 console


I have been trying to use CreateProcess() STARTUPINFO to custom set a windows98 console window with no success except I get a Title change... Big Whoop...

MS says it's doable ...ahem : http://msdn2.microsoft.com/en-us/library/ms682528.aspx
Quote:
When a process uses CreateProcess, it can specify a STARTUPINFO structure, whose members control the characteristics of the first new console (if any) created for the child process. The STARTUPINFO structure specified in the call to CreateProcess affects a console created if the CREATE_NEW_CONSOLE flag is specified. It also affects a console created if the child process subsequently uses AllocConsole. The following console characteristics can be specified:
* Size of the new console window, in character cells
* Location of the new console window, in screen pixel coordinates
* Size of the new console's screen buffer, in character cells
* Text and background color attributes of the new console's screen buffer
* Display name for the title bar of the new console's window
Ok~~?...
I think I've tried about every change I thought might make a difference without much difference. I include a function which shows that the values make it to my STARTUPINFO structure , but the consoles don't show up as expected. With STARTF_USESHOWWINDOW flag set I might say there are some subtle differences with the different wShowWindow values 0 - 11. (hide does hide!) But as far as locations, sizes and FillAttribute... nada.

It may be just my windows 98 console. I was wondering if anyone had any insight to the problem or even go so far as to humbly ask if they might try it on XP to see those results. I have two programs I've been using for experimentation.
The main program:
CPP / C++ / C Code:
/* Cproc_x1.c        */
#include <windows.h>
#include <stdio.h>
#define PAUSE while(getc(stdin) != '\n')

int main(int argc, char * argv[])
{
  /*    Create these two structures */
  STARTUPINFO startinfo;             /* struct holds startup parameters    */
  PROCESS_INFORMATION procinfo;  /* CreateProcess fills this structure with
                                    stuff you can pass to other winapi
                                    functions to control the child process */
  printf("Just hit enter through all these screens... \n\n");
  /*    initialize the memory                                              */
  /* ZeroMemory(&startinfo, sizeof(STARTUPINFO));    ( for 2000 pro up)    */
  memset(&startinfo, 0, sizeof(STARTUPINFO) );     /* works the same with
                                                  or without...That is NOT */
  /*    initialize the startupinfo members
        used in this prog            ** the typedef struct _STARTUPINFO {  */
  startinfo.cb = sizeof(STARTUPINFO);  /* DWORD  cb                        */
  startinfo.lpReserved = NULL;         /* LPTSTR lpReserved                */
  startinfo.lpDesktop = NULL;          /* LPTSTR lpDesktop                 */
  startinfo.lpTitle = "Howdy There!";  /* LPTSTR lpTitle                   */
  startinfo.dwX = 500;                 /* DWORD  dwX    -window' offset in */
  startinfo.dwY = 500;                 /* DWORD  dwY         pixels        */
  startinfo.dwXSize = 50;              /* DWORD  dwXSize -window frame size*/
  startinfo.dwYSize = 15;              /* DWORD  dwYSize     in pixels     */
  startinfo.dwXCountChars = 100;       /* DWORD  dwXCountChars -console buff */
  startinfo.dwYCountChars =  30;       /* DWORD  dwYCountChars   size      */
                                       /* DWORD  dwFillAttribute           */
  startinfo.dwFillAttribute = BACKGROUND_RED | FOREGROUND_BLUE;
  /* startinfo.dwFlags  = 0; */         /* DWORD  dwFlags                   */
  startinfo.dwFlags     =
    STARTF_USEPOSITION      |
    STARTF_USESHOWWINDOW    |
    STARTF_USECOUNTCHARS    |
    STARTF_USEFILLATTRIBUTE |
    STARTF_USESIZE          |
    STARTF_USESTDHANDLES
  ;
  startinfo.wShowWindow = 1;           /* WORD   wShowWindow               */
  startinfo.cbReserved2 = 0;           /* WORD   cbReserved2               */
  startinfo.lpReserved2 = NULL;        /* LPBYTE lpReserved2               */
                                       /* HANDLE hStdInput                 */
                                       /* HANDLE hStdOutput                */
                                       /* HANDLE hStdOutput                */
                                       /* HANDLE hStdError                 */
                                       /* } STARTUPINFO, *LPSTARTUPINFO;   */
/* Obviously they don't ALL have to be set here are the modes to try in:
 wShowWindow
     If dwFlags specifies STARTF_USESHOWWINDOW, this member can be any of the SW_ constants defined in Winuser.h. Otherwise, this member is ignored.
        SW_HIDE            0                      // hidden, get file selector
        SW_NORMAL          1  SW_SHOWNORMAL    1  // normal...
        SW_SHOWMINIMIZED   2                      // normal? 
        SW_MAXIMIZE        3  SW_SHOWMAXIMIZED 3  // proc win goes top left
        SW_SHOWNOACTIVATE  4                      // wierd, shows but like 0
        SW_SHOW            5                      // normal?
        SW_MINIMIZE        6                      // minimizes window
        SW_SHOWMINNOACTIVE 7                      // minimizes inactive window
        SW_SHOWNA          8                      // wierd, shows but like 0
        SW_RESTORE         9                      // fairly normal?
        SW_SHOWDEFAULT    10                      // fairly normal?
        SW_FORCEMINIMIZE  11  SW_MAX 11           // hidden, like 0
*/
  /* ZeroMemory(&procinfo, sizeof(PROCESS_INFORMATION)); (2000 pro up)     */
  memset(&procinfo, 0, sizeof(PROCESS_INFORMATION) );

  if (argc != 2) {
    printf("waaah! you didn't give me a program to execute. \n" );
    return 1; /* bail out if there is no program to run */
  }

  /* this is the most important line in the program.
     it runs the program specified in the command-line argument (argv[1])
     Here's what we set  ..and the actual function declaration             */
  CreateProcess(    /* BOOL WINAPI CreateProcess(                          */
    NULL,           /*   LPCTSTR lpApplicationName,                        */
    argv[1],        /*   LPTSTR lpCommandLine,                             */
    NULL,           /*   LPSECURITY_ATTRIBUTES lpProcessAttributes,        */
    NULL,           /*   LPSECURITY_ATTRIBUTES lpThreadAttributes,         */
 /* FALSE, */       /*   BOOL bInheritHandles,                             */
    FALSE,
 /* 0, */           /*   DWORD dwCreationFlags,                            */
    CREATE_NEW_CONSOLE,
    NULL,           /*   LPVOID lpEnvironment,                             */
    NULL,           /*   LPCTSTR lpCurrentDirectory,                       */
    &startinfo,     /*   LPSTARTUPINFO lpStartupInfo,                      */
    &procinfo       /*   LPPROCESS_INFORMATION lpProcessInformation  );    */
  );

  /* see if I get any effect in an allocated console....                   */
/*
  AllocConsole();
  PAUSE;
  printf(" Allo there");
  PAUSE;
  FreeConsole();
*/
  printf("Hello there");
  PAUSE;                /* process 1 waits here until process 2 catches up
               If Alloc and Free above are done there is process 1 has no
               stdin for PAUSE and is left orphaned (ctrl-alt-del to kill) */

  /*     clean up the process handles it gave me                           */
  CloseHandle(procinfo.hProcess);
  CloseHandle(procinfo.hThread);

  return 0;
}
...and the program given as a command line arg which I call with the process:
CPP / C++ / C Code:
/*  CprocTest.c     */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#define PAUSE while(getc(stdin) != '\n')

void SBuffInfo(HANDLE hOut);
void getstartup(void);

int main(void)
{
  HANDLE HO1;
  HO1 = GetStdHandle(STD_OUTPUT_HANDLE);

  printf("Console 1   ...Just hit a bunch of enters through all these screens...  \n\n" );

  printf("  Test a PAUSE 1: ");
  PAUSE;

  printf("\n  test getch() 1: ");
  getch();

  getstartup();
  printf("\n  test getch() 2: ");
  getch();

  SBuffInfo(HO1);
  printf("\n  test getch() 3:  ");
  getch();

  printf("\n   ...Test a getchar() 1:  ");
  getchar();

  printf("\n   Test a PAUSE 2:  ");
  PAUSE;

  FreeConsole();
  AllocConsole();
  printf(" In Test - AllocConsole() \n");
  PAUSE;
  getstartup();
  printf("\n   Test a PAUSE 1: ");
  PAUSE;
  printf(" bye bye... ");
  Sleep(1000);
  FreeConsole();

  return 0;
}
/********************************************************************/
void SBuffInfo(HANDLE hOut)
{
  CONSOLE_SCREEN_BUFFER_INFO SBInfo;               /* pointer to structure */

  GetConsoleScreenBufferInfo(hOut, &SBInfo);
  printf("GetConsoleScreenBufferInfo(hOut, &SBInfo);   A snapshot:\n");
  printf("SBInfo.dwSize.X , Y            : %d x %d  \n", SBInfo.dwSize.X, SBInfo.dwSize.Y);
  printf("SBInfo.dwCursorPosition.X, Y   : (%d, %d) \n", SBInfo.dwCursorPosition.X, SBInfo.dwCursorPosition.Y);
  printf("SBInfo.wAttributes             : 0x%04x   \n", (unsigned)SBInfo.wAttributes);
  printf("SBInfo.srWindow.Top            : %d  \n", SBInfo.srWindow.Top);
  printf("SBInfo.srWindow.Left           : %d  \n", SBInfo.srWindow.Left);
  printf("SBInfo.srWindow.Bottom         : %d  \n", SBInfo.srWindow.Bottom);
  printf("SBInfo.srWindow.Right          : %d  \n", SBInfo.srWindow.Right);
  printf("SBInfo.dwMaximumWindowSize.X, Y: %d x %d  \n", SBInfo.dwMaximumWindowSize.X, SBInfo.dwMaximumWindowSize.Y);
}
/********************************************************************/
void getstartup(void)
{
  STARTUPINFO SUInfo;
  int i;
  LPBYTE lpbyte;
  WORD     word = 2;
  DWORD   dword = 2;

  printf("Here's this screens STARTUPINFO: \n");

  GetStartupInfo(&SUInfo);
  printf("             cb= %lu \n", SUInfo.cb);
  printf("     lpReserved= %s \n", SUInfo.lpReserved);
  printf("      lpDesktop= %s \n", SUInfo.lpDesktop);
  printf("        lpTitle= %s \n", SUInfo.lpTitle);
  printf("            dwX= %lu \n", SUInfo.dwX);
  printf("            dwY= %lu \n", SUInfo.dwY);
  printf("        dwXSize= %lu \n", SUInfo.dwXSize);
  printf("        dwYSize= %lu \n", SUInfo.dwYSize);
  printf("  dwXCountChars= %lu \n", SUInfo.dwXCountChars);
  printf("  dwYCountChars= %lu \n", SUInfo.dwYCountChars);
  printf("dwFillAttribute= %lu \n", SUInfo.dwFillAttribute);
  printf("        dwFlags= %lx \n", SUInfo.dwFlags);
  printf("    wShowWindow= %u \n", SUInfo.wShowWindow);
  printf("    cbReserved2= %u \n", SUInfo.cbReserved2);
  printf("    lpReserved2= %s \n", SUInfo.lpReserved2);
  printf("      hStdInput= %p \n", SUInfo.hStdInput);
  printf("     hStdOutput= %p \n", SUInfo.hStdOutput);
  printf("      hStdError= %p \n", SUInfo.hStdError);

  printf("\n ...now what the heck are those datatypes: \n");
  printf("  sizeof(WORD)= %d : ", sizeof(WORD) );
  for(i = 0, word = 2; i < 5; i++, word--)
    printf("%d, ", word);
  if(word > 0)
    printf("     'WORD' is unsigned \n");
  else printf("     'WORD' is signed \n" );

  printf(" sizeof(DWORD)= %d : ", sizeof(DWORD) );
  for(i = 0, dword = 2; i < 5; i++, dword--)
    printf("%ld, ", dword);
  if(dword > 0)
    printf("     'DWORD' is unsigned \n");
  else printf("     'DWORD' is signed \n" );

  printf("sizeof(LPBYTE)= %d : ", sizeof(LPBYTE) );
  lpbyte = (unsigned char*)"test";  printf("%s, ", lpbyte);
  printf("   ...and lastly: sizeof(SUInfo)= %d \n", sizeof(SUInfo) );
}
Then I run it with START > RUN (or command line) with this:
Cproc_x1.exe CprocTest.exe

Any musings? I will probably just have to give up on this approach and do the customizing in each consoles SBinfo etc... after they have been started. If nothing else, this has been a fun intro into the way win32 processes work. Thanks,
Howard;
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert win32 console application to win32 application jaro C Programming Language 3 17-Nov-2005 02:35
Bloodshed Dev C++ Project Options JdS CPP / C++ Forum 6 11-Nov-2005 17:23
Chaning Font and Color In win32 console app. Tperry23 MS Visual C++ / MFC Forum 2 02-May-2005 14:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:01.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.