AutoHotKey / SendMessage/ How should i retrieve the corresponding number of an action for a specific control with sendmessage - autohotkey

I'd like to select a date in my calendar with a AHK script.
For this, i'm using the function sendMessage because i'd like to select a date from an external app.
I'd like to use the SETCURSEL_MCM message from Microsoft documentation.
How could i find the corresponding number from this message ? Bc it's not on this page
https://learn.microsoft.com/en-us/windows/win32/controls/mcm-setcursel
SendMessage, myCorrespondingNumberAsParam???, 0, lparam(which is my date),control, wintitle
By analogy, if i want to send a text to an edit control in notepad, i should send the WM_SETTEXT. The value of this message is clearly referenced by ahk doc as 12 for that control. But it's not the case for MCM_SETCURSEL message.
I tried to put the send message in a loop, an stop the loop when it executed the message, but it's too long, and it send bugs to the program.
If anyone could help me,
Thank you,
Gilles

You see from the documentation that this message is defined in the Commctrl.h header.
So you want to open that header from your Windows SDK files, the path might be e.g.
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um, but really I recommend just using some proper Windows search engine (such as Everything), and searching that header name to find it quickly.
Then you'll see in that header that the message is defined as follows:
#define MCM_FIRST 0x1000
// BOOL MonthCal_GetCurSel(HWND hmc, LPSYSTEMTIME pst)
// returns FALSE if MCS_MULTISELECT
// returns TRUE and sets *pst to the currently selected date otherwise
#define MCM_GETCURSEL (MCM_FIRST + 1)
#define MonthCal_GetCurSel(hmc, pst) (BOOL)SNDMSG(hmc, MCM_GETCURSEL, 0, (LPARAM)(pst))
// BOOL MonthCal_SetCurSel(HWND hmc, LPSYSTEMTIME pst)
// returns FALSE if MCS_MULTISELECT
// returns TURE and sets the currently selected date to *pst otherwise
#define MCM_SETCURSEL (MCM_FIRST + 2)
#define MonthCal_SetCurSel(hmc, pst) (BOOL)SNDMSG(hmc, MCM_SETCURSEL, 0, (LPARAM)(pst))
And there's your value, 0x1000 + 2.

Related

Qt Save form take 3-4 second to open

i'm using this on push button click in Qt:
QString fileName = QFileDialog::getSaveFileName(this, tr("Save file"),
QString(),
tr("(*.csv));
it take 3-4 second to open the save Form. why? how i can improve speed?
Try to connect this slot to a QPushButton:
void MainWindow::openFD(){
QTime myopentime=QTime::currentTime();
for (int i=0;i<1000000;i++) ;//comment out this line for the real test
QString fileName = QFileDialog::getSaveFileName(this,QString(),QString(myopentime.toString("m.s.zzz")+" "+QTime::currentTime().toString("m.s.zzz"))
,tr("*.csv") );
}
Then try to run it with and without the count part.
You will see, that the count part adds some ms... without it there is not even ms (mili-second) of difference in the time shown in filename place.
So, you have to search somewhere else in your code or give us a better example.
PS:
1) You will need :
#include <QTime>
2) The line that counting is there to show you that my method works (since you will see some difference when uncomment)
Result and Answer: The problem is not on QFileDialog if this test will not give you differences but somewhere else in your code or possibly in the Window manager of your OS.

Simple UDP socket in VC++ MFC

I have been trying to write a working program that takes in data from a UDP socket and displays it in an edit control box as you receive the data (My exposure to c++ is also only about a week :P have only done embedded C code before). I have a working program that can send and output data on a button click but I want something that can do it in real time. The aim is scale this up into a larger GUI program that can send control data to hardware and get responses from them.
I have run into various problems including:
The program just not executing my OnReceivefunction (derived from
CAsyncSocket)
Getting the OnReceive function to run on a separate thread so that it can still run after a button has been clicked sending a control packet to the client then waiting for a response in a while loop
Not being able to output the data in the edit box (tried using both CEdit and CString)
ReplaceSel error saying that the type char is incompatible with LPCTSTR
My code is based on this codeproject.com tutorial, being almost exactly what I want but I get the error in 4.
EDIT: the error in 4. disappears when I change it to a TCHAR but then it outputs random chinese characters. The codeproject.com tutorial outputs the correct characters regardless of char or TCHAR declaration. When debugged my code has type wchar_t instead type char like the other code.
Chinese output
In the working program echoBuffer[0] the character sent and displayed was a 1
UINT ReceiveData(LPVOID pParam)
{
CTesterDlg *dlg = (CTesterDlg*)pParam;
AfxSocketInit(NULL);
CSocket echoServer;
// Create socket for sending/receiving datagrams
if (echoServer.Create(12345, SOCK_DGRAM, NULL) == 0)
{
AfxMessageBox(_T("Create() failed"));
}
for (;;)
{ // Run forever
// Client address
SOCKADDR_IN echoClntAddr;
// Set the size of the in-out parameter
int clntAddrLen = sizeof(echoClntAddr);
// Buffer for echo string
char echoBuffer[ECHOMAX];
// Block until receive message from a client
int recvMsgSize = echoServer.ReceiveFrom(echoBuffer, ECHOMAX, (SOCKADDR*)&echoClntAddr, &clntAddrLen, 0);
if (recvMsgSize < 0)
{
AfxMessageBox(_T("RecvFrom() failed"));
}
echoBuffer[recvMsgSize] = '\0';
dlg->m_edit.ReplaceSel(echoBuffer);
dlg->m_edit.ReplaceSel(_T("\r\n"));
}
}
After reading the link that #IInspectable provided about working with strings and checking the settings differences between the two programs it became clear that the issue lay with an incorrect conversion to UNICODE. My program does not require it so I disabled it.
This has cleared up the issue in 4. and provided solutions for 2 and 3.
I also think I know why another instance of my program would not run OnReceivein 1. because that file was not being defined by one that was already being run by the program, but that is now irrelevant.

Screenshot of an active Window in Progress-4GL

I am working In Progress 4GL , in my application i wish to take a screeenshot of an active window on any KeyStroke Event such as (CTRL + F9) and save the same in a prespecified folder. Can anyone Help me in this ?
As mentioned in the comments this can be done by calling .NET from Progress ABL. Here's an example that takes a screenshot of the entire screen. You will need to adapt this to your needs.
USING System.Drawing.*.
USING System.Drawing.Imaging.*.
USING System.Windows.Forms.Screen.
DEFINE VARIABLE bmpScreenshot AS Bitmap NO-UNDO.
DEFINE VARIABLE gfxScreenshot AS Graphics NO-UNDO.
bmpScreenshot = NEW Bitmap(Screen:PrimaryScreen:Bounds:Width,
Screen:PrimaryScreen:Bounds:Height,
PixelFormat:Format32bppArgb).
gfxScreenshot = Graphics:FromImage(bmpScreenshot).
gfxScreenshot:CopyFromScreen(Screen:PrimaryScreen:Bounds:X,
Screen:PrimaryScreen:Bounds:Y,
0,
0,
Screen:PrimaryScreen:Bounds:Size,
CopyPixelOperation:SourceCopy).
/* Use ImageFormat:[Png|Gif|Bmp|Tiff] etc for different image formats */
bmpScreenshot:SAVE("c:\temp\Screenshot.png", ImageFormat:Png).
This is a C# to ABL translation of this question on SO.

Alternative of ControlSend() function of AutoIT in Perl

ControlSend() works in a similar way to Send() but it can send key strokes directly to a window/control, rather than just to the active window. It takes the window/control hwnd as a parameter with keystrokes.
I have used
SendMessage($_,WM_KEYDOWN, VK_RETURN, 0);
SendMessage($_,WM_KEYUP, VK_RETURN, 0);
and
SendMessage($Ctrls5,WM_CHAR, VK_RETURN, 0);
I have also used SendKeys("{ENTER}"); but it wants the window to be present in foreground.
Help me in solving this.
If you are sending the Enter key for carriage return in text box then you have no function for that.
But if you want to send enter key on a button or any other control(to click on it) then you can do so by the function
PushChildById(Parent_HWND ,ctrl_Hwnd);
PushChildButton(Parent_HWND , Ctrl_regex);

NSString parsing of continuous data

Good morning,
I am retrieving a stream of bytes from a serial device that connects to the iPad. Once connected the supplied SDK will call a delegate method with the bytes that have been forwarded.
The readings forwarded by the serial device via the SDK are in the following format:
!X1:000.0;
Once connected to the serial device the delegated methods will start receiving data immediately - this could be in various states of completion i.e.
:000.00;
What I need to do is establish a concrete way of splitting the readings returned from the serial device so that I can manipulate the data.
Some of the tried options are:
Simply concatenate the received strings for a fixed period and then split the NSString on the ";" character. This is a little inefficient though and does not allow me to manipulate the data dynamically
-(void)receivingDelegateMethod:(NSString *)aString {
if(counter < 60){
[self.PropertyString stringByAppendingString:aString];
}else{
NSArray *readings = [self.PropertyString componentsSeparatedByString: #";"];
}
}
Determine a starting point by looking for the "!" character and then appending the resulting substring to a NSString property. All previous calls to the delegated method will append to this property and then remove the first 10 characters.
I know there are further options such as NSScanners and RegEx but I wanted to get the opinion of the community before wasting more time of different methods.
Thanks
Make a BOOL flag that indicates that the stream has been initialized, and set it to false. When you receive the next chunk of data, check the flag first. If it is not set, skip all characters until you see an exclamation point '!'. Once you see it, discard everything in front of it, and copy the rest of the string into the buffer. If the "is initialized" flag is set, append the entire string to the buffer without skipping characters.
Once you finish the append, scan the buffer for ! and ; delimited sections. For each occurrence of that pattern, call a designated method with a complete portion of the pattern. You can get fancy, and define your own "secondary" delegate for processing pre-validated strings.
You may need to detect disconnections, and set the "is initialized" flag back to NO.