posting msg as first in queue?

This is a discussion on posting msg as first in queue? within the Windows Programming forums, part of the Platform Specific Boards category; is there any way to post a message and get it prossesed at that same time? i know the SendMessage() ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    28

    posting msg as first in queue?

    is there any way to post a message and get it prossesed at that same time?
    i know the SendMessage() function waits for the message to get processed before it returns but what if i need it to get done before anything else is done?
    ive tried manually posting messages by altering the message loop and at a certain message ive changed the MSG struct members to what i wanted... but that didnt work.... spy++ shows them as unknow messages.....
    ideas?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    I don't know of any "high priority" message posting - without implementing it yourself.

    *Why* do you need this? Describe your situation - perhaps there are multiple solutions...

    gg

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    ok
    my program is a basic phonebook. i have 4 list boxes that display the 4 fields you have in the phonebook listing (first name, last name, home phone, cell phone). each listbox displays one of those. when i select an item on one of them, i used LB_GETCURSEL for that field and then LB_SETCURSEL to set the selection for the other fields. the idea is to make it appear as if it was one big listbox. the problem is when i select one field, there is a sort of delay before the other ones are selected (the other 3 are synchronized) and im guessing that its because of when i get the LBN_SELCHANGE msg that tells me that something was selected, there are other messages in the queue waiting to be processed before my new LB_SETCURSEL messages are processed.
    that was long... anyway, got the idea?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    Not sure how to make it any better than just doing a SendMessage(LB_SETCURSEL) to the other 3 right there in your LBN_SELCHANGE handler.

    Another option would be to use a list-view control in report view mode: http://msdn2.microsoft.com/en-us/lib...35(VS.85).aspx

    gg

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,007
    The idea behind PostMessage is to post it to the message queue and the idea behind SendMessage is to send the message directly to the window proc (without the need of a translation and dispatch when posted into the message queue) and have the application process the message before returning.
    So why are you trying to emulate SendMessage behavior with PostMessage again?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    i wasnt using PostMessage. im using SendMessage but the problem remains. the first list box updates on mouseclick the other 3 that get my SendMessage LB_SETCURSEL update togather but a second later the the first list box.
    thats why i was thinking that maybe there were too many messages executing before my messages get done and thats why the delay happens...

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    No, even the message queue should never have such a delay.
    Use a profiler to find the real bottleneck.

    One thing I can think of is that the listbox doesn't redraw immediately on the change, but rather invalidates itself. Then the redrawing would not happen until you've finished handling the current message, which perhaps takes too long.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    Use a profiler to find the real bottleneck.
    ???

    One thing I can think of is that the listbox doesn't redraw immediately on the change, but rather invalidates itself. Then the redrawing would not happen until you've finished handling the current message, which perhaps takes too long.
    ive thought about that so ive tried using postmessage and invalidating the current LBN_SELCHANGE message. the way i figured is i can ignore the current selection of an item on a listbox and instead do em all togather at one point. i think that can work but i also think that LBN_SELCHANGE is not the message i need to invalidate (by doing return 1 instead of 0)

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A profiler is a program that follows the execution of your code and after you finish, tells you where (which lines/instructions) it spent the time. It helps in understanding where an application spends most of it's time.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    can you name me such a program please?

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    grpof, oprofile, vtune, codeanalyst.

    Which one works (best) for you depends on what OS you are using, what processor you have, and what compiler you use.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    i think vtune is right for me.

    anyway, im going to leave this program now, since i have other things i need to concentrate on and my time is pretty much up, but after im done with those, im going to get back to this and figure it out if i can.

    thanks for all your help!
    Last edited by robig2; 01-15-2008 at 01:06 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 09:17 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 10:09 PM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 12:39 PM
  5. queue help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-29-2001, 09:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21