Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

WAR (card game)

raniarania Member Posts: 35
hy every body
i develop a program that first open a file than i want that opened file to run (that file is an audio file that run on windows media player or any suitable program) i use the command

WinExec("complete path of windows media player", sw_show);

this command call the windows media player but still when it run need to enter the file name another time
is this any solution to use the filename that is openned already without retyping again
please can anyone help me
many thanks in advance
regards
rania
«1

Comments

  • pingpongpingpong Member Posts: 937
    try:

    ::ShellExecute(hWnd, "Open", "c:\xxx\something.wav", NULL, NULL, SW_SHOW);

    Notice you pass the file name, it will open up (and play) in the suitable WAV player in your Windows. Pass in a TXT file and notepad will open, DOC file and Word will open and so forth.

    : hy every body
    : i develop a program that first open a file than i want that opened file to run (that file is an audio file that run on windows media player or any suitable program) i use the command
    :
    : WinExec("complete path of windows media player", sw_show);
    :
    : this command call the windows media player but still when it run need to enter the file name another time
    : is this any solution to use the filename that is openned already without retyping again
    : please can anyone help me
    : many thanks in advance
    : regards
    : rania
    :

  • raniarania Member Posts: 35
    thanks for your help it works
    i have another question can i find answer
    about how to print the out put of the program(my program is based on two dialog boxes shown in the same time)(working using winapi32)
    can you help me?
    many thanks in advance
    regards
    rania
  • pingpongpingpong Member Posts: 937
    you are welcome.

    what do you want to print exactly? you have 2 dialog boxes on screen, what exactly do you want on paper? the whole dialog box including border and caption?

    : thanks for your help it works
    : i have another question can i find answer
    : about how to print the out put of the program(my program is based on two dialog boxes shown in the same time)(working using winapi32)
    : can you help me?
    : many thanks in advance
    : regards
    : rania
    :

  • raniarania Member Posts: 35
    well i want to print the holl screen (containing the menu bar , the 2 dialog box)exactly as when pressing on (print screen) and i want that to be printed on paper and to be for each output not one only.

    my source code will be:
    case ID_FILE_PRINT:
    {
    //the source code to be added
    break;
    }

    can you help me?
    many thanks in advance
    regards
    rania




  • pingpongpingpong Member Posts: 937
    OK, I got it. Below is some code I wrote sometime ago to do just that, you call it like this:

    PrintScreen(hWnd, "your document name");

    Where hWnd is a handle to a window (any would do, best to pass your main window), the second parameter is the document name, this is what would come up in the print queue. You can pass whatever you want here.

    P/S Sorry, no MFC, I'm an API guy, it should work from inside an MFC code though.

    [code]
    static BOOL PrintScreen(HWND hWnd, const TCHAR* docName)
    {
    BOOL ret = FALSE;

    PRINTDLG pd;
    ::ZeroMemory(&pd, sizeof(PRINTDLG));
    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = hWnd;
    pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION;

    if(::PrintDlg(&pd))
    {
    ::UpdateWindow(hWnd);

    if(pd.hDC != NULL)
    {
    RECT rcPrinter;
    rcPrinter.left = GetDeviceCaps(pd.hDC, PHYSICALOFFSETX);
    rcPrinter.top = GetDeviceCaps(pd.hDC, PHYSICALOFFSETY);
    rcPrinter.right = GetDeviceCaps(pd.hDC, PHYSICALWIDTH) - rcPrinter.left * 2;
    rcPrinter.bottom = GetDeviceCaps(pd.hDC, PHYSICALHEIGHT) - rcPrinter.top * 2;

    DOCINFO di;
    ::ZeroMemory(&di, sizeof(DOCINFO));
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = docName;
    di.lpszOutput = NULL;
    di.lpszDatatype = NULL;

    ::StartDoc(pd.hDC, &di);
    ::StartPage(pd.hDC);

    ::SetMapMode(pd.hDC, MM_TEXT);

    HDC hDCScreen = ::GetDC(NULL);
    if(hDCScreen != NULL)
    {
    RECT rcScreen;
    rcScreen.left = 0;
    rcScreen.top = 0;
    rcScreen.right = ::GetDeviceCaps(hDCScreen, HORZRES);
    rcScreen.bottom = ::GetDeviceCaps(hDCScreen, VERTRES);

    int cxPrinter = rcPrinter.right - rcPrinter.left;
    int cyPrinter = rcPrinter.bottom - rcPrinter.top;

    if(((float)rcScreen.right / cxPrinter) > ((float)rcScreen.bottom / cyPrinter))
    cyPrinter = (int)((float)rcScreen.bottom * cxPrinter / rcScreen.right + 0.5f);
    else
    cxPrinter = (int)((float)rcScreen.right * cyPrinter / rcScreen.bottom + 0.5f);

    ::StretchBlt(
    pd.hDC,
    rcPrinter.left,
    rcPrinter.top,
    cxPrinter,
    cyPrinter,
    hDCScreen,
    rcScreen.left,
    rcScreen.top,
    rcScreen.right,
    rcScreen.bottom,
    SRCCOPY);

    ::ReleaseDC(NULL, hDCScreen);

    ret = TRUE;
    }


    ::EndPage(pd.hDC);
    ::EndDoc(pd.hDC);

    ::DeleteDC(pd.hDC);
    }
    }

    return ret;
    }
    [/code]

    : well i want to print the holl screen (containing the menu bar , the 2 dialog box)exactly as when pressing on (print screen) and i want that to be printed on paper and to be for each output not one only.
    :
    : my source code will be:
    : case ID_FILE_PRINT:
    : {
    : //the source code to be added
    : break;
    : }
    :
    : can you help me?
    : many thanks in advance
    : regards
    : rania
    :
    :
    :
    :
    :

  • raniarania Member Posts: 35
    well,first, many thanks for your replying.
    then, i do just as you said , and a screen of print is present and i press on the ok button the printer get the command but the paper is white nothing is printed , i try to print it in a file to see what is happened and it gives :
    "%-12345X@PJL JOB NAME="E: est.doc"
    @PJL COMMENT "Context data is not available"
    @PJL SET RET=ON
    @PJL SET DUPLEX=OFF
    @PJL SET ECONOMODE=OFF
    @PJL SET OUTBIN=UPPER
    @PJL SET FINISH=NONE
    @PJL SET PAGEPROTECT=AUTO
    @PJL SET PAPER=A4
    @PJL SET TRAY1TEMP=NORMAL
    @PJL SET HOLD=OFF
    @PJL SET RESOLUTION=600
    @PJL SET BITSPERPIXEL=2
    @PJL ENTER LANGUAGE=PCLXL
    ) HP-PCL XL;2;0;Comment Copyright Hewlett-Packard Company 1989-2000. Version 4.0.2.0
    رXXّہ ّہّڈAہ ّہّHآ phّFہ ّ(ہّ&بء A4ّ%Cہ ّTء ّ1DIB%-12345X@PJL EOJ NAME="E: est.doc"
    %-12345X"

    //////
    i just change the docName to the filename (where the filename is the file i opened and read from it )
    and i write the function like this:

    case ID_FILE_PRINT1:
    PrintScreen( hwnd, filename);
    break;

    is this anything i can do ?

    can you help me?
    many thanks in advance
    regards
    rania


  • pingpongpingpong Member Posts: 937
    Maybe your printer does not support StretchBlt. Could you try this code and tell me what message box shows up?

    [code]
    static BOOL PrintScreen(HWND hWnd, const TCHAR* docName)
    {
    BOOL ret = FALSE;
    BOOL supported = FALSE;

    PRINTDLG pd;
    ::ZeroMemory(&pd, sizeof(PRINTDLG));
    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = hWnd;
    pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION;

    if(::PrintDlg(&pd))
    {
    ::UpdateWindow(hWnd);

    if(pd.hDC != NULL)
    {
    if(GetDeviceCaps(pd.hDC, RASTERCAPS) & RC_STRETCHDIB)
    supported = TRUE;
    else
    supported = FALSE;

    ::DeleteDC(pd.hDC);

    ret = TRUE;
    }
    }

    if(ret)
    {
    if(supported)
    MessageBox(hWnd, "Supported", "StretchBlt", 0);
    else
    MessageBox(hWnd, "Not supported", "StretchBlt", 0);
    }
    else
    MessageBox(hWnd, "Error or canceled", "StretchBlt", 0);

    return ret;
    }
    [/code]

    : well,first, many thanks for your replying.
    : then, i do just as you said , and a screen of print is present and i press on the ok button the printer get the command but the paper is white nothing is printed , i try to print it in a file to see what is happened and it gives :
    : "%-12345X@PJL JOB NAME="E: est.doc"
    : @PJL COMMENT "Context data is not available"
    : @PJL SET RET=ON
    : @PJL SET DUPLEX=OFF
    : @PJL SET ECONOMODE=OFF
    : @PJL SET OUTBIN=UPPER
    : @PJL SET FINISH=NONE
    : @PJL SET PAGEPROTECT=AUTO
    : @PJL SET PAPER=A4
    : @PJL SET TRAY1TEMP=NORMAL
    : @PJL SET HOLD=OFF
    : @PJL SET RESOLUTION=600
    : @PJL SET BITSPERPIXEL=2
    : @PJL ENTER LANGUAGE=PCLXL
    : ) HP-PCL XL;2;0;Comment Copyright Hewlett-Packard Company 1989-2000. Version 4.0.2.0
    : رXXّہ ّہّڈAہ ّہّHآ phّFہ ّ(ہّ&بء A4ّ%Cہ ّTء ّ1DIB%-12345X@PJL EOJ NAME="E: est.doc"
    : %-12345X"
    :
    : //////
    : i just change the docName to the filename (where the filename is the file i opened and read from it )
    : and i write the function like this:
    :
    : case ID_FILE_PRINT1:
    : PrintScreen( hwnd, filename);
    : break;
    :
    : is this anything i can do ?
    :
    : can you help me?
    : many thanks in advance
    : regards
    : rania
    :
    :
    :

  • raniarania Member Posts: 35
    : Maybe your printer does not support StretchBlt. Could you try this code and tell me what message box shows up?
    :
    : [code]
    : static BOOL PrintScreen(HWND hWnd, const TCHAR* docName)
    : {
    : BOOL ret = FALSE;
    : BOOL supported = FALSE;
    :
    : PRINTDLG pd;
    : ::ZeroMemory(&pd, sizeof(PRINTDLG));
    : pd.lStructSize = sizeof(PRINTDLG);
    : pd.hwndOwner = hWnd;
    : pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION;
    :
    : if(::PrintDlg(&pd))
    : {
    : ::UpdateWindow(hWnd);
    :
    : if(pd.hDC != NULL)
    : {
    : if(GetDeviceCaps(pd.hDC, RASTERCAPS) & RC_STRETCHDIB)
    : supported = TRUE;
    : else
    : supported = FALSE;
    :
    : ::DeleteDC(pd.hDC);
    :
    : ret = TRUE;
    : }
    : }
    :
    : if(ret)
    : {
    : if(supported)
    : MessageBox(hWnd, "Supported", "StretchBlt", 0);
    : else
    : MessageBox(hWnd, "Not supported", "StretchBlt", 0);
    : }
    : else
    : MessageBox(hWnd, "Error or canceled", "StretchBlt", 0);
    :
    : return ret;
    : }
    : [/code]
    :
    : : well,first, many thanks for your replying.
    : : then, i do just as you said , and a screen of print is present and i press on the ok button the printer get the command but the paper is white nothing is printed , i try to print it in a file to see what is happened and it gives :
    : : "%-12345X@PJL JOB NAME="E: est.doc"
    : : @PJL COMMENT "Context data is not available"
    : : @PJL SET RET=ON
    : : @PJL SET DUPLEX=OFF
    : : @PJL SET ECONOMODE=OFF
    : : @PJL SET OUTBIN=UPPER
    : : @PJL SET FINISH=NONE
    : : @PJL SET PAGEPROTECT=AUTO
    : : @PJL SET PAPER=A4
    : : @PJL SET TRAY1TEMP=NORMAL
    : : @PJL SET HOLD=OFF
    : : @PJL SET RESOLUTION=600
    : : @PJL SET BITSPERPIXEL=2
    : : @PJL ENTER LANGUAGE=PCLXL
    : : ) HP-PCL XL;2;0;Comment Copyright Hewlett-Packard Company 1989-2000. Version 4.0.2.0
    : : رXXّہ ّہّڈAہ ّہّHآ phّFہ ّ(ہّ&بء A4ّ%Cہ ّTء ّ1DIB%-12345X@PJL EOJ NAME="E: est.doc"
    : : %-12345X"
    : :
    : : //////
    : : i just change the docName to the filename (where the filename is the file i opened and read from it )
    : : and i write the function like this:
    : :
    : : case ID_FILE_PRINT1:
    : : PrintScreen( hwnd, filename);
    : : break;
    : :
    : : is this anything i can do ?
    : :
    : : can you help me?
    : : many thanks in advance
    : : regards
    : : rania
    : :
    : :
    : :
    :
    :

  • raniarania Member Posts: 35
    well, thanks for your support
    i try the function , and it gives this message:
    "stretch blt supported ""ok"
    i think the problem is in the document name (docName ) i pass the name of the program which is general viewer. exe
    and i am working with win api not mfc
    that is the source code

    #include
    #include
    #include
    #include
  • pingpongpingpong Member Posts: 937
    I dont know, it worked fine with me.

    What if you print some text? Put the code from the first PrintScreen back, comment out StretchBlt and instead put:
    TextOut(pd.hDC, 100, 100, "Hello there", lstrlen("Hello there"));
    See if anything comes out of your printer.

    : well, thanks for your support
    : i try the function , and it gives this message:
    : "stretch blt supported ""ok"
    : i think the problem is in the document name (docName ) i pass the name of the program which is general viewer. exe
    : and i am working with win api not mfc
    : that is the source code
    :
    : #include
    : #include
    : #include
    : #include
«1
Sign In or Register to comment.