Thread: Visualizing/Manipulating Nodes in a Linked List?

  1. #1
    Registered User
    Join Date
    Aug 2012
    Location
    Temecula, CA
    Posts
    4

    Visualizing/Manipulating Nodes in a Linked List?

    I am trying to design a Win32/C program that maintains a bi-directional linked list, individual nodes of which can be modified, inserted, deleted, etc. by a visual interface. I have created small bitmap images representing different node "types."

    I think would be fairly straightforward to write a paint procedure that cycles through the linked list to paint bitmaps corresponding to the different node types. The problem is, I don't see how they could be selected/acted upon unless the nodes are "objectified" in some way. (Maybe mouse clicks could be correlated to the bitmap dumps appearing in the client window, but that sounds like a lot of programming overhead.)

    Reading ahead into Petzold, I don't quite see how I will accomplish this. I'm guessing that each node could be a button control. The problem I see is that (1) the buttons would be printed on the main window (frame), not a dialog box, and (2) there is no standard button I'm aware of that would incorporate my bitmap. Petzold mentions user-defined controls. Perhaps I could create a custom button composed of the bitmap, but that sounds complicated.

    Am I making sense? I'm trying to get a realistic idea of how to actually implement this as I read through Petzold. And yes, I am an absolute Win32 newbie. Ideas or directions would be appreciated!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    When doing things like this I custom draw the image and record the rectange/region that can be clicked. (ie as you draw the image for a node, with FillRect() or BitBlt()etc, record the position as part of the node).


    When the user clicks on the screen (and you get a mouse button down msg) test each node's rectangle/region to see if contains the location clicked (look at PtInRect() ).

    Make sure you use the same coord system, screen or client.

    IIRC you have to convert the mouse click from screen to client coords with ScreenToClient() (or store the rectangle/region in screen coords after drawing it in client).

    [screen coords have the top left of the monitor's screen as 0,0 while client coords have the top left of the window's client area as 0,0]
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    PS there should not be any drawing done in WM_PAINT.

    WM_PAINT should be a single BitBlt() from your buffer (or memory DC) to the DC in the PAINTSTRUCT (from BeginPaint()) and only the rect in the PAINTSTUCT should be redrawn (not the whole client area).

    All drawing should be done in response to other msgs and then the screen updated with an InvalidateRect() and UpdateWindow() call (as UpdateWindow() bypasses the OS msg queue and posts the paint msg directly to the window's callback).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Aug 2012
    Location
    Temecula, CA
    Posts
    4
    Thanks a lot Novacain, I will try it this way. Sounds very doable!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Swap nodes in linked list
    By Boaz in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 08:06 PM
  2. Adding nodes into linked list
    By Suchy in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2007, 04:03 PM
  3. Adding nodes to a linked list
    By bluescreen in forum C Programming
    Replies: 4
    Last Post: 11-09-2006, 01:59 AM
  4. Help with swapping nodes in a linked list
    By Axel in forum C Programming
    Replies: 3
    Last Post: 10-18-2005, 09:16 AM
  5. Linked List and Nodes
    By paperbox005 in forum C++ Programming
    Replies: 2
    Last Post: 08-04-2004, 09:12 AM