WAR (card game)

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

Comments

  • 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
    :

  • 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
  • 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
    :

  • 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




  • 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
    :
    :
    :
    :
    :

  • 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 :
    "%[email protected] 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%[email protected] 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


  • 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 :
    : "%[email protected] 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%[email protected] 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
    :
    :
    :

  • : 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 :
    : : "%[email protected] 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%[email protected] 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
    : :
    : :
    : :
    :
    :

  • 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
    #include
    #include
    #include"resource.h"


    _finddata_t fd;

    unsigned char b[9999999];
    long i;
    //char filename[50];
    char filename[100];
    HDC hdc,memdc;
    ///////
    //variables
    char outch[400000];
    char outcd[400000];
    char outca[400000];
    long byteoff=0;
    //functions
    void PrintFileconthex();
    void PrintFilecontdec();
    void PrintFilecontasc();
    //////

    char dir[40];
    char drive[64];
    char fname[90];
    char ext[5];

    void SplitFile()
    {
    _splitpath(filename,drive,dir,fname,ext);
    char k[100];
    sprintf(k,"%s",fname);
    sprintf(k,"%s",ext);
    }


    void ReadFile(HWND hwnd)
    {
    ifstream in(filename,ios::binary|ios::in);
    in.read(b,999999);
    }



    long WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
    BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    BOOL CALLBACK DlgProc1(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    BOOL CALLBACK DlgProc2(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    static BOOL PrintScreen(HWND hwnd, const TCHAR* docName);

    HINSTANCE hInst;
    int APIENTRY WinMain(HINSTANCE hi,HINSTANCE pi,LPSTR cline,int scmd)
    { WNDCLASS wc;
    hInst=hi;
    wc.style= CS_HREDRAW| CS_VREDRAW;
    wc.lpszClassName="myclass";
    wc.lpfnWndProc=WndProc ;
    wc.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    //wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    wc.hIcon=LoadIcon(hi,MAKEINTRESOURCE(IDI_ICON2));
    wc.hInstance=hi;
    wc.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
    wc.cbWndExtra=0;
    wc.cbClsExtra=0;
    RegisterClass(&wc);
    HWND hwnd;
    hwnd=CreateWindow("myclass","GENERAL VIEWER",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hi,0);
    ShowWindow(hwnd,scmd);
    UpdateWindow(hwnd);
    MSG msg;
    while(GetMessage(&msg,hwnd,0,0)>0)
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return 0;
    }

    /*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;
    }
    */

    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;
    }



    long WINAPI WndProc(HWND hwnd ,UINT mid,WPARAM wp,LPARAM lp)
    {
    OPENFILENAME ofn;
    HWND hdlg;
    RECT rect1,rect2;
    int width1,width2,height1,height2;
    char k[30];

    switch(mid)
    {

    case WM_COMMAND:
    switch(wp)
    {
    case ID_FILE_OPEN1:
    memset(&ofn,0,sizeof(ofn));
    ofn.lStructSize=sizeof(ofn);
    ofn.hInstance=hInst;
    //ofn.nMaxFile=50;
    ofn.nMaxFile=100;

    ofn.lpstrFile=filename;
    GetOpenFileName(&ofn);
    ReadFile(hwnd);

    hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    ShowWindow(hdlg,1);

    GetWindowRect(hdlg,&rect1);
    width1=rect1.right-rect1.left;
    height1=rect1.bottom-rect1.top;
    GetClientRect(hwnd,&rect2);
    width2=rect2.right-rect2.left;
    height2=rect2.bottom-rect2.top;
    SetWindowPos(hdlg,0,width2-width1-25,0,width1,height1,0);
    /////////
    {
    SplitFile();
    SetDlgItemText(hdlg,IDC_EDIT1,fname);
    SetDlgItemText(hdlg,IDC_EDIT2,ext);
    _findfirst(filename,&fd);
    sprintf(k,"%ld",fd.size);
    SetDlgItemText(hdlg,IDC_EDIT3,k);
    memcpy(k,ctime( &( fd.time_write )),24);
    k[24]=0;

    SetDlgItemText(hdlg,IDC_EDIT4,k);
    }
    //////////////
    break;
    case ID_FILE_PRINT1:
    PrintScreen( hwnd,"general viewer.exe");
    break;

    case ID_PLAY_RUN:
    ::ShellExecute(hwnd, "Open",filename, NULL, NULL, SW_SHOW);

    break;


    case ID_VIEW_FILECONTENT:

    ReadFile(hwnd);
    if (fd.size>9000)
    {
    //file cont large file
    {
    {hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG3),hwnd,DlgProc2);
    ShowWindow(hdlg,TRUE);
    }

    SplitFile();
    SetDlgItemText(hdlg,IDC_EDIT1,fname);
    SetDlgItemText(hdlg,IDC_EDIT2,ext);
    PrintFileconthex();
    SetDlgItemText(hdlg,IDC_EDIT3,outch);

    }

    }

    else{
    //file cont small file
    {
    {hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG2),hwnd,DlgProc1);
    ShowWindow(hdlg,TRUE);
    }

    SplitFile();
    SetDlgItemText(hdlg,IDC_EDIT1,fname);
    SetDlgItemText(hdlg,IDC_EDIT2,ext);
    PrintFileconthex();
    SetDlgItemText(hdlg,IDC_EDIT3,outch);

    }}
    break;

    case ID_FILE_EXIT:
    DestroyWindow(hwnd);
    break;

    }
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:return DefWindowProc(hwnd,mid,wp,lp);
    }
    return 0;
    }


    BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    { switch(mid)
    {

    case WM_CLOSE:
    EndDialog(hdlg,0);
    break;

    case WM_COMMAND:
    switch(wp)
    {

    case IDCANCEL:
    EndDialog(hdlg,0);
    break;


    } break;

    }
    return 0;

    }

    BOOL CALLBACK DlgProc1(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    {//file content small file
    switch(mid)
    {

    case WM_CLOSE:
    EndDialog(hdlg,0);
    break;

    case WM_COMMAND:
    switch(wp)
    {
    //dec
    case IDC_BUTTON1:
    PrintFilecontdec();
    SetDlgItemText(hdlg,IDC_EDIT3,outcd);
    break;
    //asc
    case IDC_BUTTON2:
    PrintFilecontasc();
    SetDlgItemText(hdlg,IDC_EDIT3,outca);
    break;
    //hex
    case IDC_BUTTON3:
    PrintFileconthex();
    SetDlgItemText(hdlg,IDC_EDIT3,outch);
    break;
    case IDCANCEL:
    EndDialog(hdlg,0);
    break;

    } break;

    }
    return 0;

    }

    BOOL CALLBACK DlgProc2(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    {//file content large file
    switch(mid)
    {

    case WM_CLOSE:
    EndDialog(hdlg,0);
    break;

    case WM_COMMAND:
    switch(wp)
    {
    //dec
    case IDC_BUTTON2:
    PrintFilecontdec();
    SetDlgItemText(hdlg,IDC_EDIT3,outcd);
    break;
    //asc
    case IDC_BUTTON3:
    PrintFilecontasc();
    SetDlgItemText(hdlg,IDC_EDIT3,outca);
    break;
    //hex
    case IDC_BUTTON1:
    PrintFileconthex();
    SetDlgItemText(hdlg,IDC_EDIT3,outch);
    break;
    case IDC_BUTTON4:
    {
    byteoff=byteoff-1000;

    PrintFileconthex();
    SetDlgItemText(hdlg,IDC_EDIT3,outch);
    }
    break;
    case IDC_BUTTON5:
    {
    byteoff=byteoff+1000;

    PrintFileconthex();
    SetDlgItemText(hdlg,IDC_EDIT3,outch);
    }
    break;

    case IDCANCEL:
    EndDialog(hdlg,0);
    break;

    } break;

    }
    return 0;

    }




    is this anything i can do ?

    can you help me?
    many thanks in advance
    regards
    rania

  • 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
    : #include
    : #include
    : #include"resource.h"
    :
    :
    : _finddata_t fd;
    :
    : unsigned char b[9999999];
    : long i;
    : //char filename[50];
    : char filename[100];
    : HDC hdc,memdc;
    : ///////
    : //variables
    : char outch[400000];
    : char outcd[400000];
    : char outca[400000];
    : long byteoff=0;
    : //functions
    : void PrintFileconthex();
    : void PrintFilecontdec();
    : void PrintFilecontasc();
    : //////
    :
    : char dir[40];
    : char drive[64];
    : char fname[90];
    : char ext[5];
    :
    : void SplitFile()
    : {
    : _splitpath(filename,drive,dir,fname,ext);
    : char k[100];
    : sprintf(k,"%s",fname);
    : sprintf(k,"%s",ext);
    : }
    :
    :
    : void ReadFile(HWND hwnd)
    : {
    : ifstream in(filename,ios::binary|ios::in);
    : in.read(b,999999);
    : }
    :
    :
    :
    : long WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
    : BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    : BOOL CALLBACK DlgProc1(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    : BOOL CALLBACK DlgProc2(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    : static BOOL PrintScreen(HWND hwnd, const TCHAR* docName);
    :
    : HINSTANCE hInst;
    : int APIENTRY WinMain(HINSTANCE hi,HINSTANCE pi,LPSTR cline,int scmd)
    : { WNDCLASS wc;
    : hInst=hi;
    : wc.style= CS_HREDRAW| CS_VREDRAW;
    : wc.lpszClassName="myclass";
    : wc.lpfnWndProc=WndProc ;
    : wc.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
    : wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    : //wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    : wc.hIcon=LoadIcon(hi,MAKEINTRESOURCE(IDI_ICON2));
    : wc.hInstance=hi;
    : wc.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
    : wc.cbWndExtra=0;
    : wc.cbClsExtra=0;
    : RegisterClass(&wc);
    : HWND hwnd;
    : hwnd=CreateWindow("myclass","GENERAL VIEWER",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hi,0);
    : ShowWindow(hwnd,scmd);
    : UpdateWindow(hwnd);
    : MSG msg;
    : while(GetMessage(&msg,hwnd,0,0)>0)
    : {
    : TranslateMessage(&msg);
    : DispatchMessage(&msg);
    : }
    : return 0;
    : }
    :
    : /*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;
    : }
    : */
    :
    : 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;
    : }
    :
    :
    :
    : long WINAPI WndProc(HWND hwnd ,UINT mid,WPARAM wp,LPARAM lp)
    : {
    : OPENFILENAME ofn;
    : HWND hdlg;
    : RECT rect1,rect2;
    : int width1,width2,height1,height2;
    : char k[30];
    :
    : switch(mid)
    : {
    :
    : case WM_COMMAND:
    : switch(wp)
    : {
    : case ID_FILE_OPEN1:
    : memset(&ofn,0,sizeof(ofn));
    : ofn.lStructSize=sizeof(ofn);
    : ofn.hInstance=hInst;
    : //ofn.nMaxFile=50;
    : ofn.nMaxFile=100;
    :
    : ofn.lpstrFile=filename;
    : GetOpenFileName(&ofn);
    : ReadFile(hwnd);
    :
    : hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    : ShowWindow(hdlg,1);
    :
    : GetWindowRect(hdlg,&rect1);
    : width1=rect1.right-rect1.left;
    : height1=rect1.bottom-rect1.top;
    : GetClientRect(hwnd,&rect2);
    : width2=rect2.right-rect2.left;
    : height2=rect2.bottom-rect2.top;
    : SetWindowPos(hdlg,0,width2-width1-25,0,width1,height1,0);
    : /////////
    : {
    : SplitFile();
    : SetDlgItemText(hdlg,IDC_EDIT1,fname);
    : SetDlgItemText(hdlg,IDC_EDIT2,ext);
    : _findfirst(filename,&fd);
    : sprintf(k,"%ld",fd.size);
    : SetDlgItemText(hdlg,IDC_EDIT3,k);
    : memcpy(k,ctime( &( fd.time_write )),24);
    : k[24]=0;
    :
    : SetDlgItemText(hdlg,IDC_EDIT4,k);
    : }
    : //////////////
    : break;
    : case ID_FILE_PRINT1:
    : PrintScreen( hwnd,"general viewer.exe");
    : break;
    :
    : case ID_PLAY_RUN:
    : ::ShellExecute(hwnd, "Open",filename, NULL, NULL, SW_SHOW);
    :
    : break;
    :
    :
    : case ID_VIEW_FILECONTENT:
    :
    : ReadFile(hwnd);
    : if (fd.size>9000)
    : {
    : //file cont large file
    : {
    : {hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG3),hwnd,DlgProc2);
    : ShowWindow(hdlg,TRUE);
    : }
    :
    : SplitFile();
    : SetDlgItemText(hdlg,IDC_EDIT1,fname);
    : SetDlgItemText(hdlg,IDC_EDIT2,ext);
    : PrintFileconthex();
    : SetDlgItemText(hdlg,IDC_EDIT3,outch);
    :
    : }
    :
    : }
    :
    : else{
    : //file cont small file
    : {
    : {hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG2),hwnd,DlgProc1);
    : ShowWindow(hdlg,TRUE);
    : }
    :
    : SplitFile();
    : SetDlgItemText(hdlg,IDC_EDIT1,fname);
    : SetDlgItemText(hdlg,IDC_EDIT2,ext);
    : PrintFileconthex();
    : SetDlgItemText(hdlg,IDC_EDIT3,outch);
    :
    : }}
    : break;
    :
    : case ID_FILE_EXIT:
    : DestroyWindow(hwnd);
    : break;
    :
    : }
    : break;
    : case WM_DESTROY:
    : PostQuitMessage(0);
    : break;
    : default:return DefWindowProc(hwnd,mid,wp,lp);
    : }
    : return 0;
    : }
    :
    :
    : BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    : { switch(mid)
    : {
    :
    : case WM_CLOSE:
    : EndDialog(hdlg,0);
    : break;
    :
    : case WM_COMMAND:
    : switch(wp)
    : {
    :
    : case IDCANCEL:
    : EndDialog(hdlg,0);
    : break;
    :
    :
    : } break;
    :
    : }
    : return 0;
    :
    : }
    :
    : BOOL CALLBACK DlgProc1(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    : {//file content small file
    : switch(mid)
    : {
    :
    : case WM_CLOSE:
    : EndDialog(hdlg,0);
    : break;
    :
    : case WM_COMMAND:
    : switch(wp)
    : {
    : //dec
    : case IDC_BUTTON1:
    : PrintFilecontdec();
    : SetDlgItemText(hdlg,IDC_EDIT3,outcd);
    : break;
    : //asc
    : case IDC_BUTTON2:
    : PrintFilecontasc();
    : SetDlgItemText(hdlg,IDC_EDIT3,outca);
    : break;
    : //hex
    : case IDC_BUTTON3:
    : PrintFileconthex();
    : SetDlgItemText(hdlg,IDC_EDIT3,outch);
    : break;
    : case IDCANCEL:
    : EndDialog(hdlg,0);
    : break;
    :
    : } break;
    :
    : }
    : return 0;
    :
    : }
    :
    : BOOL CALLBACK DlgProc2(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    : {//file content large file
    : switch(mid)
    : {
    :
    : case WM_CLOSE:
    : EndDialog(hdlg,0);
    : break;
    :
    : case WM_COMMAND:
    : switch(wp)
    : {
    : //dec
    : case IDC_BUTTON2:
    : PrintFilecontdec();
    : SetDlgItemText(hdlg,IDC_EDIT3,outcd);
    : break;
    : //asc
    : case IDC_BUTTON3:
    : PrintFilecontasc();
    : SetDlgItemText(hdlg,IDC_EDIT3,outca);
    : break;
    : //hex
    : case IDC_BUTTON1:
    : PrintFileconthex();
    : SetDlgItemText(hdlg,IDC_EDIT3,outch);
    : break;
    : case IDC_BUTTON4:
    : {
    : byteoff=byteoff-1000;
    :
    : PrintFileconthex();
    : SetDlgItemText(hdlg,IDC_EDIT3,outch);
    : }
    : break;
    : case IDC_BUTTON5:
    : {
    : byteoff=byteoff+1000;
    :
    : PrintFileconthex();
    : SetDlgItemText(hdlg,IDC_EDIT3,outch);
    : }
    : break;
    :
    : case IDCANCEL:
    : EndDialog(hdlg,0);
    : break;
    :
    : } break;
    :
    : }
    : return 0;
    :
    : }
    :
    :
    :
    :
    : is this anything i can do ?
    :
    : can you help me?
    : many thanks in advance
    : regards
    : rania
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

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

Categories