can't into OnChar() when deal with WM_KEYDOWN in 'PreTranslateMessage' function - visual-c++

For some reason, I need to do something when I get WM_KEYDOWN message in PreTranslateMessage, So I do something like this:
if(WM_KEYDOWN == pMsg->message && pMsg->hwnd == GetSafeHwnd())
{
SendMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
return TRUE;
}
After doing so, I find there is no way to get into OnChar function, It's bad.
Anybody knows why and how to solve this problem? Help will be greatly appreciated.

When you return TRUE from PreTranslateMessage() then the message won't be processed further. You do this for every keystroke, so none will be processed and can never generate a WM_CHAR message. In other words, you got what you ask for. It also looks like you are sending the message to yourself. Hard to suggest an alternative, the code doesn't make sense.

Why will you send the same message to yourself? If all you want to do is do some processing and let the message pass through all you need to do in the 'if' statement is do your processing and let the normal message chaining work. This way the message will dispatched for further processing and eventually reach your onChar.
so your code should be something like this:
void YourWnd::PreTranslateMessage(MSG *pMsg)
{
if(WM_KEYDOWN == pMsg->message && pMsg->hwnd == GetSafeHwnd())
{
processKeyDown();
}
return CWnd::PreTranslateMessage(pMsg);
}

Why PreTranslateMessage? What possible reason would you have to do it in PreTranslateMessage?
PreTranslateMessage as the name suggests pretlanslate messages containing hot/shortcut keys.
Using it as some kind of a bandage very frequently leads to disaster sooner or later.
Could you please tell us what you are trying to achieve? Somebody will be able to come up with better solution.

Related

Adding integers with the eval function is returning an error. (Nodejs)

Please don't ask me not to use eval, this isn't going to be public anyways.
I've made a chatting website, and I have implemented a "!eval" command (admin only), whatever is after it is run. I can use "!eval '2'+'2'" (Strings added), but not "!eval 2+2." The error returned is .
I've console.logged the input to the eval, and it returned exactly what I wanted: "1+1." I've looked around for this, but it seems like no one else had this problem before. A solution (more like a debugging one) is that I tried "eval('1+1')" and returned the same error. Any thoughts? Thanks in advance.
(I forgot to add what I was expecting)
I was expecting this.
VLAZ pointed out in the comments that it must be another piece of code, which he is correct. I was encrypting the messages so it can be sent securely to the client, and it only takes a string. I added
if (typeof(results) != 'string'){
results = String(results)
}
and it seemed to work, Thanks!

Ways to include custom error messages in shorthand if-else sanity checks Discord JS

I am a beginner and probably, this is a stupid question. I am writing a command handler for a discord.js bot. Every time, a user sends a message starting with the correct command prefix, I check whether the invoke is in an Enmap of possible commands.
Currently, it looks like this:
const command = client.commands.get(invoke);
if(!command) return;
...
I would like to keep this shorthand way of writing those sanity checks, but I would like to inform the user that there is no command with this name.
Is there an elegant way of doing this or does anyone know where I can find more information about good ways to solve this?
Thanks in advance :D
I wouldn't recommend telling the user if a command is invalid, but here's how you can do it:
const command = client.commands.get(command);
if (!command) return message.channel.send("Invalid Command.");

Transient result in Bixby

I am trying to make a result transient in bixby.
Specify a text reply like so:
text (reply) {
description (HomeAssistant conversation reply)
features {
transient
}
}
However it seems as if the result is still cached, what am I missing here?
Thanks.
Perhaps the data is being cached in your server side? Here's a related question and answer to this here.

DialogFlow follow up triggers empty response

I have a DialogFlow intent follow up that I'm having a hard time with. It's the only follow up to my main intent, and the issue I'm having is that when
the incidents.data array is empty it doesn't trigger the conv.ask statement in the else case and causes DialogFlow to throw an empty speech response error. The code looks something like this:
app.intent('metro_timetable - yes', async (conv: any) => {
const incidents = await serviceIncidents.getIncidents();
if (incidents.data.length > 0) {
conv.ask('I have incidents')
} else {
conv.ask(
`I wasn't able to understand your request, could you please say that again?`
);
}
});
incidents.data gets stored in the global scope, and is set deep within
the metro_timetable intent. It stores an incident for the follow up. Because all yes responses trigger the follow up I setup an else case so it catches it if someone says yes when metro_timetable doesn't understand their original request and asks them to repeat it. If incidents.data actually has information to share the dialog triggers correctly and I have incidents is correctly read to the user.
In DialogFlow it looks something like this. Where am I going wrong here?
Your description is a little convoluted how incidents.data actually gets set, but it sounds possible that instead of it being set to an empty array, it isn't set at all. In this case, I suspect that the following happened:
incidents.data would be undefined
Trying to evaluate incidents.data.length would cause an error
Since the program crashes, your webhook doesn't return a result. Since you probably didn't set a result in the UI for the intent, an empty result was returned.
You can probably solve this by doing a test such as (for example)
incidents && incidents.data && incidents.data.length > 0
Your other issue, however, seems to be that you have a Followup Intent set for a scenario where you don't actually want that as the followup. This is one of the reasons you probably shouldn't use Followup Intents but, instead, only set a context when you send a response where that context would make sense, and look for the "Yes" response in the context you define. Then, when metro_timetable doesn't understand the request, you don't set the context and you give an error.
To do this, you would remove the automatically generated metro_timetable-followup context from the two Intents. You'll create your own context, which I'll name timetable for purposes of this example.
In the fulfillment for the metro_timetable Intent, if you respond with something that needs confirmation (ie - when "yes" will be something the user says), you would set the timetable context with something like
conv.contexts.set('timetable',2);
conv.ask('Are you sure?');
You can then create an Intent that checks for timetable as the Incoming Context and has training phrases that are equivalent to "yes". In that Intent, you'd do what you need to and respond.

Optimization callbacks in MeteorJS

I dont know how to ask my question correctly, but for example I have some structure like this
get_data:function(){
this.unblock();
request("example.com", Meteor.bindEnvironment(function(error, response, body) {
if (!error && response.statusCode == 200) {
$ = Cheerio.load(body);// get HTML of example.com
$(".someclass").each(function() {
if (!somedata_doesnt_exist_in_Mongo) {
request(nexturl, Meteor.bindEnvironment(function(error, response, body)
//... logic
}));
}
});
}
}))
}
Main idea is that I get data from many sites like agregator and have a lot of methods like this. And it'a a lot of time. So I have 2 questions
1 - for Meteor guys. When I use this.unblock() this ensures that my method will work without taking time with customers, like work in other thread ?
2 - How can I optimaze code stucture like above ?
Sorry if it's not in StackOverflow format but
I am waiting for any help !
this.unblock is relevant only to each client individually. It
allows subsequent method calls from client A to run without
having the previous method calls from that client A to finish.
It is like working in a new thread asynchronously in the sense that
the previous method calls are not blocking for client A for this
function using this.unblock. If you have client B, his/her
method invocation wouldn't be blocking A's regardless of whether
you use this.unblock.
I recommend using this.unblock whenever you are sure subsequent method calls will not rely on the result of the function you use this.unblock in. Sending out emails is the most common example. Subsequent method calls will not need the emails to finish sending before doing its job. For your example, I think it should be good to use this.unblock, but of course it depends on what you plan to do with the results following the execution of code after this.unblock.

Resources