| |

VerySource

 Forgot password?
 Register
Search
View: 565|Reply: 7

How do I send a message to the OK button of the print dialog?

[Copy link]

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-28 12:20:01
| Show all posts |Read mode
I am now using crystal report printing. The crystalReportViewer control in .NET C # has a PrintReport () function, but it does not print directly, but pops up the print dialog box, and prints only after you click the "OK" button in the print dialog box. But I now have hundreds of records. It is impossible to print a page at a time by clicking the button like this. I want to do it in a loop, but how do I send a message to the "OK" button in the print dialog box? Can anyone tell me, thank you!
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-3-11 13:15:02
| Show all posts
practice:
Findwindow caught dlg
FindwindowEx caught Button
SendMessage

The above are win32 functions, you will know if you check it. C # itself cannot do it, you need to use these functions
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-4-16 18:30:02
| Show all posts
Okay, first of all these three are api functions, so you need DLLImport
second
Let me introduce a few functions
HWND FindWindow (
  LPCTSTR lpClassName, // pointer to class name
  LPCTSTR lpWindowName // pointer to window name
);
lpClassName is the form class, you do n’t know if you can write it, null is enough
lpWindowName is your form title, you can find it

HWND FindWindowEx (
  HWND hwndParent, // handle to parent window
  HWND hwndChildAfter, // handle to a child window
  LPCTSTR lpszClass, // pointer to class name
  LPCTSTR lpszWindow // pointer to window name
);

hwndParent: the previous return value to it
LPCTSTR lpszClass, // pointer to class name
LPCTSTR lpszWindow // pointer to window name
For the button you want, lpszClass = "button"
lpszWindow is "OK"

SendMessage is the first to return with hwnd above, the second message may have to be checked
Reply

Use magic Report

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-4-20 00:00:01
| Show all posts
I now know what you mean, but I am programming in .NET C #. As you said, I wrote the following lines of code:
using System.Runtime.InteropServices;

[DllImport ("user32.dll")]
public static extern void Findwindow (String strClassName, String strWindowsName);

[DllImport ("user32.dll")]
public static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

But there is such an error when compiling: you should enter class, delegate, enum, interface or struct
what is going on? What should be changed?
In addition, I wonder if you will use crystal reports in C #, do you know how to create crystal reports dynamically? Thank you!
Reply

Use magic Report

2

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-4-24 12:15:01
| Show all posts
Also, the standard print dialog box appears in the form of ShowDialog (), which is different from other windows that pop up in the form of Show (). Can you receive it by sending a message to it?
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-4-29 09:45:01
| Show all posts
1) I see that there is no error in your writing. It is estimated that it is wrong in other places. It is recommended to put the above functions in a class called API_Func and call API_Func.FindWindow after you call it. You have written FindWindow wrong and w must be capitalized.
Findwindow return value you also wrote wrong

2) Never done

3) You don't need to worry about this. The modal can be received, and it can certainly be received.
I have seen an article before: It is described like this, the modal dialog has its own message processing thread, and the non-modal is the previous one. I did n’t understand it at first, but I might understand it now, but you do n’t have to worry about this. You The main difference between sendmessage and postmessage is that if you force it to be sent, it will respond first, and the message will not be pushed.
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-10 21:45:01
| Show all posts
I simulated it, you can refer to:
class API_Func
    {
        [DllImport ("user32.dll")]
        public static extern IntPtr FindWindow (string lpClassName, string lpWindowName);

        [DllImport ("user32.dll")]
        public static extern IntPtr FindWindowEx (IntPtr hwndParent, IntPtr hwndChildAfter,
                                                string lpszClass, string lpszWindow);

        [DllImport ("user32.dll")]
        public static extern bool PostMessage (IntPtr hWnd, uint Msg, int wParam, int lParam);
    }
 private void button2_Click (object sender, EventArgs e)
        {
            IntPtr hwnd = API_Func.FindWindow (null, "Form1");
            if (hwnd! = null)
            {
                IntPtr hbutton = API_Func.FindWindowEx (hwnd, (IntPtr) null, null, "yes");
                if (hbutton == null)
                    return;

                API_Func.PostMessage (hbutton, WM_LBUTTONDOWN, MK_LBUTTON, 0x000B0024);
                API_Func.PostMessage (hbutton, WM_LBUTTONUP, MK_LBUTTON, 0x000B0024);
            }
        }
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-10 22:30:02
| Show all posts
private const uint WM_LBUTTONDOWN = 0x0201;
        private const uint WM_LBUTTONUP = 0x0202;
        private const int MK_LBUTTON = 0x0001;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list