Results 1 to 19 of 19

Thread: Twins?

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Twins?

    Hi, I created 2 Objects on a Win32 App Window. But every time:
    PHP Code:
    switch(msg){
    case 
    WM_COMMAND:
    switch(
    LOWORD(wParam)){
    case 
    BUTTON1:
    MessageBox(hwnd,"Clicked Button","",0);
    return 
    0;
    case 
    TEXT1:
    MessageBox(hwnd,"Clicked Text","",0);
    return 
    0;
    }
    break;
    default:
    return 
    DefWindowProc(hwnd,msg,wParam,lParam);

    Everytime I click on TEXT1, it pops up the "Clicked Text" messagebox twice, how do I make it pop up once?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You have already asked it

    The only way I can think of is subclassing so check out the code in the other thread
    Baaaaaaaaah

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You need to only catch the *_CLICK message. What is TEXT1? This is popping up a message box for every message targeted at that window.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Here's the code

    PHP Code:
    //Sviesoft Corporation(r)
    //Copyright(c) 1999 - 2001
    //All Rights Reserved
    //
    //Thanks to God, my Mom and the people
    //that have supported me all these years
    //
    //God Bless you all, Amen

    #include <windows.h>
    #include <iostream>
    #include <fstream>
    using namespace std;
    const 
    char tzID[]="myWindowClass";
    HINSTANCE hInst;
    char bgName[MAX_PATH];
    #define BUT1 1
    #define TEX1 2

    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
        
    ofstream PO("name.txt");
        switch(
    msg){
        case 
    WM_CREATE:
            
    CreateWindowEx(NULL,"edit","",WS_CHILD|WS_VISIBLE,100,40,80,60,hwnd,(HMENU)TEX1,hInst,NULL);
            
    CreateWindowEx(NULL,"button","Submit",WS_CHILD|WS_VISIBLE,100,100,80,20,hwnd,(HMENU)BUT1,hInst,NULL);
            break;
        case 
    WM_COMMAND:
            switch(
    LOWORD(wParam)){
            case 
    BUT1:
                
    GetDlgItemText(hwnd,TEX1,bgName,GetWindowTextLength(GetDlgItem(hwnd,TEX1))+1);
                goto 
    FI;

                return 
    0;
            case 
    TEX1:
                
                return 
    MessageBox(hwnd,"Hello!","",0);
            }
        case 
    WM_CLOSE:
            
    DestroyWindow(hwnd);
            break;
        case 
    WM_DESTROY:
            
    PostQuitMessage(0);
            break;
        default:
                
    FI:    if(PO.is_open()){PO<<bgName<<endl;PO.close();}
            return 
    DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return 
    0;
    }
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
        
    WNDCLASSEX tz;
        
    HWND hwnd;
        
    MSG Msg;

        
    tz.cbSize=sizeof(WNDCLASSEX);
        
    tz.style=0;
        
    tz.lpfnWndProc=WndProc;
        
    tz.cbClsExtra=0;
        
    tz.cbWndExtra=0;
        
    tz.hInstance=hInstance;
        
    tz.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        
    tz.hCursor=LoadCursor(NULL,IDC_ARROW);
        
    tz.hbrBackground=(HBRUSH)(COLOR_WINDOW+8);
        
    tz.lpszClassName=tzID;
        
    tz.lpszMenuName=NULL;
        
    tz.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
        if(!
    RegisterClassEx(&tz)){
            return 
    0;
        }
        
    hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,tzID,"Welcome!",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,300,NULL,NULL,hInstance,NULL);
        if(
    hwnd==NULL){
            return 
    0;
        }
        
    ShowWindow(hwnd,nCmdShow);
        
    UpdateWindow(hwnd);
        while(
    GetMessage(&Msg,NULL,0,0)){
            
    TranslateMessage(&Msg);
            
    DispatchMessage(&Msg);
        }
        return 
    Msg.wParam;

    Please help

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I'm a little new to this, but shouldn't you be assigning your CreateWindowEx statements to HWND's? Then looking for the click like this?

    PHP Code:
    if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == hWnd_Button) {
        
    MessageBox(hWnd"Button clicked!""Button"MB_OK);

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    crptcblade: use HIWORD instead of LOWORD
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post LOWORD HIWORD?

    What's the difference between LOWORD and HIWORD? What do they do?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    They get the low and high words (16-bit) out of a double-word (32-bit) respectively
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Difference?

    So is it a difference between speed or?...

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    About WM_COMMAND messages and windows simple data types

    The basic data types of windows (and CPUs) are: BYTE (unsigned 8-bit), WORD (unsigned 16-bit) and DWORD (double word, unsigned 32-bit)
    you can store two BYTEs in one WORD, and two WORDs in one DWORD
    in memory, a DWORD is the same as
    Code:
    BYTE BYTE BYTE BYTE
       \  /      \  /
        WORD    WORD
           \   /
           DWORD
    to combine two BYTEs to a WORD, you use the MAKEWORD macro
    to combine two WORDs to a DWORD, use the MAKELONG macro
    :P
    to extract a WORD from a DWORD, use the HIWORD and LOWORD macros
    for bytes, use the HIBYTE and LOBYTE macros

    the two components are called low and high

    the WM_COMMAND mesage has this structure:
    wParam (a DWORD despite it's name):
    LOWORD = ID of sender, this can be a menu option or a control
    if menu option, it is the thing you are looking for.
    if control, you probably don't need it.
    HIWORD = notification code
    this is important if the message comes from a control, because it contains the real information. e.g. if a button was clicked, HIWORD(wParam) has the value BN_CLICKED
    for a menu, this is less important, it is 0 if the menu option was selected and 1 if the corresponding accelerator key was pressed
    lParam contains the HWND of the control, or NULL if the sender is a menu.


    I hope that clears something up
    Last edited by CornedBee; Sep 6th, 2001 at 07:50 AM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I think the word size is 32-bit on 32-bit processors...or is it 64 for the Pentium? Can't remember.

    Although I would expect them to keep those sizes for compatibility.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, a word is still 16 bits wide. The 32 bit value is DWORD, and a 64 bit value is usually called a quadword.
    Search MSDN for WORD and select "windows simple data types"
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I know a WORD is 16-bit, but I'm talking about the processor's word size.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    from windef.h
    typedef unsigned long DWORD;
    typedef unsigned short WORD;
    typedef unsigned char BYTE;
    typedef unsigned int UINT;
    typedef UINT WPARAM;
    typedef LONG LPARAM;
    typedef LONG LRESULT;
    I couldn't find the typedef long LONG line, but that is really obvious.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    if a cpu word was 32 (or even 64) bit, what would you call a 16 bit value?
    I'll see what VC++ says by disassembling simple code.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    here we go:
    6: short a = 4;
    00401038 mov word ptr [ebp-4],offset main+1Ch(0040103c)
    7: long b = 3;
    0040103E mov dword ptr [ebp-8],3


    compiled with vc++6 on a pentium II and NT 4.0
    Last edited by CornedBee; Sep 6th, 2001 at 09:23 AM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Most computers (including 386, 486, and Pentium PCs) have a word size of 32 bits. The old 286 machines had a word size of 16. Old-style mainframes often had 36-bit words. A few processors (like the Alpha from what used to be DEC and is now Compaq) have 64-bit words. The 64-bit word will become more common over the next five years; Intel is planning to replace the Pentium series with a 64-bit chip called the `Itanium'.
    ...from http://www.linuxdoc.org/HOWTO/Unix-a...e-formats.html
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    So they seem to be keeping the names for compability.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I think if you have a 16-bit value it won't have a name since it'll be transmitted to the processor as part of a 32-bit value. This is why a lot of Pentium optimisation techniques involve passing 2 values at once in a packed variable
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width