replease help

well i try with TextOut and it works and it print"Hello there"
then i try with stretchblt another time nothing is printed
what can i do now? can it is a problem with dialog box or what?
Please can you help me?
many thanks in advance.
regards
rania


Comments

  • : well i try with TextOut and it works and it print"Hello there"
    : then i try with stretchblt another time nothing is printed
    : what can i do now? can it is a problem with dialog box or what?
    : Please can you help me?
    : many thanks in advance.
    : regards
    : rania
    :
    :
    :
    can you show the stretchblt code?
  • well i try with TextOut and it works and it print"Hello there"
    then i try with stretchblt another time nothing is printed
    what can i do now? can it is a problem with dialog box or what?
    Please can you help me?

    well this is my source code to print the output of my program, this output is presented in the form of 2 dialog boxes that are shown in the same time and i want that out put to be printed in paper .
    (i try with this source code but nothing is hapened (no paper is printed the paper is white))
    //////////////////
    #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);


    // TextOut(pd.hDC, 100, 100, "Hello there", lstrlen("Hello there"));

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

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