Summary of the invention
The invention provides a kind of message treatment method and device, can adjust the order of the message in the message queue of operating system establishment, thereby more neatly the message in the message queue handled.
The invention provides following scheme:
A kind of message treatment method comprises:
Application program is created a message queue;
From the message queue that operating system is created, take out all current message;
The message of being taken out is carried out the order adjustment, and put into the message queue that said application program is created;
According to the order of each message in the message queue of said application program establishment, each message is carried out distribution processor.
Preferably, saidly from the message queue that operating system is created, take out after all current message, also comprise:
The message of said taking-up is removed from the message queue that said operating system is created.
Wherein, saidly from the message queue that operating system is created, take out all current message and comprise:
From operating system is to take out all current message the message queue created of given thread;
Saidly each message carried out distribution processor comprise:
With the window of each message distribution, so that each message is handled by the window of said correspondence to correspondence.
Wherein, said given thread is the thread relevant with the interface.
Wherein, saidly from the message queue that operating system is created, take out all current message and comprise:
From the system message queue that operating system is created, take out all current message;
Saidly each message carried out distribution processor comprise:
Is the message queue of the thread creation of correspondence with each message distribution to operating system, so that by the thread of said correspondence each message distribution is handled to corresponding window.
A kind of message processing apparatus comprises:
The unit is created in formation, is used for application program and creates a message queue;
The message retrieval unit is used for taking out all current message from the message queue that operating system is created, and the message of said taking-up is removed from the message queue that said operating system is created;
The order adjustment unit is used for the message of being taken out is carried out the order adjustment, and puts into the message queue that said application program is created;
The message distribution unit is used for the order according to each message of message queue of said application program establishment, and each message is carried out distribution processor.
Preferably, also comprise:
Remove the unit, be used for the said message queue of creating from operating system and take out after all current message, the message of said taking-up is removed from the message queue that said operating system is created.
Wherein, said message retrieval unit comprises:
First takes out subelement, and being used for from operating system is that the message queue that given thread is created takes out all current message;
Said message distribution unit comprises:
The first distribution subelement is used for each message distribution to corresponding window, so that by the window of said correspondence each message is handled.
Wherein, said given thread is the thread relevant with the interface.
Wherein, said message retrieval unit comprises:
Second takes out subelement, is used for taking out all current message from the system message queue that operating system is created;
Said message distribution unit comprises:
The second distribution subelement is used for each message distribution to the message queue of operating system for corresponding thread creation, so that by the thread of said correspondence each message distribution is handled to corresponding window.
According to specific embodiment provided by the invention, the present invention has reached following technique effect:
Pass through the embodiment of the invention; Because application program can be created message queue voluntarily, and, put into the message queue that this is created voluntarily with the current message taking-up in the message queue of operating system establishment; Thereby make that the priority execution sequence of message is adjustable; Rather than, like this, can handle the message in the message queue more neatly uniformly according to the principle of stipulating in the operating system of handling earlier that arrives first.For example; Can so that some real-time external events in time handled; And; Before other message that formerly arrives, handle the situation that just can reach desired effects if some message that arrives in the back must be caught up with, then can the message that arrive in the back be mentioned before the message that formerly arrives, thereby reach desired effects.
Embodiment
To combine the accompanying drawing in the embodiment of the invention below, the technical scheme in the embodiment of the invention is carried out clear, intactly description, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, the every other embodiment that those of ordinary skills obtained belongs to the scope that the present invention protects.
Referring to Fig. 1; The embodiment of the invention at first provides a kind of message treatment method; This method can be applied in the application program that (this application program can be for realizing a kind of application program of this message processing function exploitation; Also can be on existing other base of applications, to increase this message processing function), when specifically realizing, this method can may further comprise the steps:
S101: application program is created a message queue;
This message queue is created by application program oneself, and therefore, what kind of the message that application program can be decided in its sole discretion wherein arrange with in proper order, can also adjust order voluntarily.
S102: from the message queue that operating system is created, take out all current message;
In order to understand this step better, at first the message processing procedure in the operating system is introduced simply below.Generally speaking, be processed to the end can the following process of experience from producing for message (is example with outside input message): when mouse or keyboard had action, device drives converted input operation into message and it is put in the system message queue (1); When (2) operating system shifts out a message at every turn from system message queue; Can judge which target window is this message belong to; Then it is distributed in the message queue of the thread of creating target window; In other words, the message queue of thread is window all mouses of reception and the keyboard message of its establishment; (3) thread shifts out message and guidance system comes these message distributions message is handled to correct window from its message queue.It is thus clear that operating system can be created two kinds of message queues, a kind of is system message queue, and all message all can be put into this system message queue earlier; Another kind is the message queue of thread, need can be put into the message queue of this thread by all message of the window treatments of certain thread creation.
In embodiments of the present invention, can from aforementioned system message queue, take out all current message, also can be from the message queue of concrete thread, to take out all current message.But in practical application, possibly the demand of adjustment order all arranged not all message, but have only the message in those threads relevant just to have this demand usually with the interface; Therefore, in preferred embodiment, can be only from the message queue of some threads of appointment, take out all current message; Perhaps; Can also judge at first whether current each thread is relevant with the interface,, then the message in its message queue taken out if relevant; Otherwise, can not carry out the order adjustment and handle the message in its message queue.Certainly, can also confirm that the message from which thread message queue adjusts according to the needs of reality.
Need to prove that the message in the message queue that operating system is created is except the message that comprises the said external input (message that is also promptly produced by mouse-keyboard etc.); Also possibly comprise system message (message that also promptly produces), in addition, also possibly comprise the message of each program generation that moves in the operating system by operating system; For example, certain operation possibly not be to handle immediately, at this moment; Can delay processing through the mode that produces message, perhaps some operation possibly need cross-thread to carry out again, at this moment; Also can be put into earlier in the message queue, be distributed to then in the corresponding thread message queue, or the like.In the embodiment of the invention, when from the message queue that operating system is created, taking out current message, can comprise above-mentioned all types of message; Also be; All message, no matter its come from outside input still be operating system still be the program of moving in the system, can it be taken out; Put in the message queue of creating voluntarily, so that order is adjusted.Certainly, the execution sequence of some system messages possibly be sealed mounted, at this moment, can this system message not carried out the order adjustment.
Need to prove that in addition specifically when from the message queue of system creation, taking out message, the modes such as API (Application Programming Interface, API) function that can utilize operating system to provide are carried out.For example, if from the message queue of given thread, take out message, then can directly use following api function: PeekMessage; If from system message queue, take out message, then can perhaps directly obtain all message and realize through the message hook technology in Drive Layer, repeat no more here.Certainly, in program operation process, mistake occurs, the message queue of creating from operating system, take out after the current message, can also the message of taking out be removed from the message queue that said operating system is created.
S103: the message of being taken out is carried out the order adjustment, and put into the message queue that said application program is created;
The message that can from the message queue that operating system is created, take out is put in the message queue of application program; When putting into this message queue; Just can adjust the order of message; Certainly, also can in putting into message queue, adjust the order of each message more afterwards.The foundation of specifically message being adjusted can be confirmed according to the needs in the practical application; For example; Can think that the message that some operations relevant with user interactions produce needs priority processing, at this moment, just can put into position earlier in the message queue with such message.And for example, if the user is seeing video, the operation that video is relevant so just possibly need priority service, at this moment, just can the corresponding message of this operation be put into position earlier in the message queue.For another example,, carried out other operations again if the user is when seeing video, then just can think that message of this operation correspondence of user need be jumped the queue, advanced processing, or the like.
Need to prove; Operating system can be numbered each message, and each message has the ID of oneself, can comprise information such as window handle, type of message in the message; Api function through system (for example can be known these information; Can check whether keyboard or mouse information are arranged in thread message queue through GetInputState, can check the message of a certain type in the message queue through GetQueueStatus, or the like) can know each message operation that needs by which window are handled and message is corresponding respectively or the like according to these information; And then just can confirm the order of each message in message queue according to preset rule.For example, the corresponding operation of certain message of find taking out need be by certain video playback window treatments, and it is higher that the priority ratio of this type message is set in advance; Therefore; Just can this message be placed on position earlier in the message queue, even can put in the first place, or the like.
S104:, each message is carried out distribution processor according to the order of each message in the message queue of said application program establishment.
Because in the message queue that application program is created voluntarily, each message is adjusted again, therefore, just can carry out distribution processor to each message according to the order after the adjustment.Concrete, if be the message of from the message queue of given thread, taking out in step S102, then when distribution processor, can directly message distribution be arrived corresponding window, message is handled getting final product by the window of correspondence.That is to say; In this case; Be the equal of after operating system arrives concrete thread message queue with the message distribution in the system queue; Be not by thread with message distribution to concrete window, but by application program, replace each concrete thread to accomplish this distribute work with the described message processing function of the embodiment of the invention.During concrete the realization, when replacing concrete thread to accomplish the operation of message distribution, can realize that (this api function can be: DispatchMessage by the api function that this application program with message processing function uses operating system to provide equally.
In addition; If among the step S102 be the message of from system message queue, taking out, then when distribution processor, can at first message distribution be arrived the message queue of the thread of creating window; Follow-up operation then can continue to be accomplished voluntarily by thread; Also promptly, by thread with the message distribution in its oneself the message queue to corresponding window, by the window of correspondence message is handled again.That is to say, in this case, be the equal of before operating system arrives concrete thread message queue with the message distribution in the system queue; By application program with the said message processing function of the embodiment of the invention to the message processing of sorting; And then the message after will sorting by this application program, be distributed to the message queue of each thread, like this; Remain by thread message distribution to concrete window; But, be by application program with the described message processing function of the embodiment of the invention, replace operating system with the message queue of each message distribution to each thread.
In a word, the message treatment method that provides through the embodiment of the invention is because application program can be created message queue voluntarily; And with the current message taking-up in the message queue of operating system establishment; Put into the message queue that this is created voluntarily, thereby make that the priority execution sequence of message is adjustable, rather than uniformly according to the principle of stipulating in the operating system of handling earlier that arrives first; Like this, can handle the message in the message queue more neatly.For example; Can so that some real-time external events in time handled; And, if must catching up with, some message that arrives in the back before other message that formerly arrives, handles the situation that just can reach desired effects, then can the message that arrive in the back be mentioned before the message that formerly arrives; Thereby reach desired effects, or the like.
Corresponding with the message treatment method that the embodiment of the invention provides, the embodiment of the invention also provides a kind of message processing apparatus, and same, this device is applied in the application program, and referring to Fig. 2, this device comprises with lower unit:
Unit 201 is created in formation, is used for application program and creates a message queue;
Message retrieval unit 202 is used for taking out all current message from the message queue that operating system is created;
Order adjustment unit 203 is used for the message of being taken out is carried out the order adjustment, and puts into the message queue that said application program is created;
Message distribution unit 204 is used for the order according to each message of message queue of said application program establishment, and each message is carried out distribution processor.
Certainly, in program operation process, mistake occurs, the message queue of creating from operating system, take out after the current message, can also the message of taking out be removed from the message queue that said operating system is created.When concrete the realization, this device can also comprise:
Remove the unit, be used for the said message queue of creating from operating system and take out after all current message, the message of said taking-up is removed from the message queue that said operating system is created.
Wherein, when specifically realizing, message retrieval unit 202 can comprise
First takes out subelement, and being used for from operating system is that the message queue that given thread is created takes out all current message;
Accordingly, message distribution unit 204 can comprise:
The first distribution subelement is used for each message distribution to corresponding window, so that by the window of said correspondence each message is handled.
Under this mode, given thread can be the thread relevant with the interface, can certainly be other threads that need in the practical application.
Perhaps, under another kind of implementation, message retrieval unit 202 also can comprise:
Second takes out subelement, is used for taking out all current message from the system message queue that operating system is created;
Accordingly, message distribution unit 204 can comprise:
The second distribution subelement is used for each message distribution to the message queue of operating system for corresponding thread creation, so that by the thread of said correspondence each message distribution is handled to corresponding window.
The message processing apparatus that provides through the embodiment of the invention; Because application program can be created message queue voluntarily, and, put into the message queue that this is created voluntarily with the current message taking-up in the message queue of operating system establishment; Thereby make that the priority execution sequence of message is adjustable; Rather than, like this, can handle the message in the message queue more neatly uniformly according to the principle of stipulating in the operating system of handling earlier that arrives first.For example; Can so that some real-time external events in time handled; And, if must catching up with, some message that arrives in the back before other message that formerly arrives, handles the situation that just can reach desired effects, then can the message that arrive in the back be mentioned before the message that formerly arrives; Thereby reach desired effects, or the like.
Description through above embodiment can know, those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential general hardware platform.Based on such understanding; The part that technical scheme of the present invention contributes to prior art in essence in other words can be come out with the embodied of software product; This computer software product can be stored in the storage medium, like ROM/RAM, magnetic disc, CD etc., comprises that some instructions are with so that a computer equipment (can be a personal computer; Server, the perhaps network equipment etc.) carry out the described method of some part of each embodiment of the present invention or embodiment.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and identical similar part is mutually referring to getting final product between each embodiment, and each embodiment stresses all is the difference with other embodiment.Especially, for device or system embodiment, because it is basically similar in appearance to method embodiment, so describe fairly simplely, relevant part gets final product referring to the part explanation of method embodiment.Apparatus and system embodiment described above only is schematic; Wherein said unit as the separating component explanation can or can not be physically to separate also; The parts that show as the unit can be or can not be physical locations also; Promptly can be positioned at a place, perhaps also can be distributed on a plurality of NEs.Can select wherein some or all of module to realize the purpose of present embodiment scheme according to the actual needs.Those of ordinary skills promptly can understand and implement under the situation of not paying creative work.
More than to a kind of message treatment method provided by the present invention and device; Be described in detail; Used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, part in specific embodiments and applications all can change.In sum, this description should not be construed as limitation of the present invention.