Thread: Button handler

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    29

    Button handler

    Kinda stupid - I actually forgot how to handle buttons

    Code:
    HWND hBtn;
    
    hBtn = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("BUTTON"),                         //'class' of control to create
                    TEXT("Submit"),            //the control caption
                    WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,   //control style: how it looks
                    20,                                     //control position: left
                    440,                                     //control position: top
                    75,                                    //control width
                    25,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    (HMENU)BTN_SUBMIT,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );   
            SendMessage(hBtn,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    In WM_COMMAND:

    Code:
    if (HIWORD(wParam) == BN_CLICKED) {
            MessageBox(hwnd, "lol", "lol", MB_OK);
    }
    BTN_SUBMIT defined as:

    Code:
    #define BTN_SUBMIT 100
    The messagebox doesnt pop up?
    Dev-C++ 4.9.9.2
    Code::Blocks
    Win XP

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    there's no problem with your code, it works fine; in the 'WM_CREATE', you create the button, then switching the 'WM_COMMAND' you search in the 'WPARAM wParam' parameter of the window function (procedure) for a 'HIWORD((WPARAM)wParam)' such as 'BN_CLICKED', if you find it then launch the message. maybe you have an error while the creation of the window, or in the declaration of the main procedure

    niara
    Last edited by Niara; 03-11-2006 at 12:32 PM.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    29
    Weird that it doesnt work.Might be becuase i defined HWND hBtn; in a function?
    Dev-C++ 4.9.9.2
    Code::Blocks
    Win XP

  4. #4
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    It's probably due to some other part of your code. Maybe you could post the whole file's contents?

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    29
    here it is
    Code:
    /*
        Author      : Lars "Nephiroth" Wesselius
        For         : British/Hollands Special Forces
        File        : main.cpp
        Description : Main source file for WarManager
        Version     : Alpha 1.0
        
        Goal        : To provide an easy to use warmanager, where you can easily 
                        add/edit wars.Saving wars via the registry.
    
    
    Release info Alpha 1.0:
    */
    
    #include <stdio.h>
    #include <string>
    #include <windows.h>
    #include <fstream>
    #include <commctrl.h>
    #include "Wm.h"
    #include "splash.h"
    #include "splash.cpp"
    
    using namespace std;
    
    HANDLE LoadMain;
    HINSTANCE hThisInstance;
    HWND hwnd;
    HWND hPic;
    HWND hStatus;
    HWND hList;
    HWND hGroupWarr;
    HWND hGroupPbss;
    HWND hGroupLe;
    SPLASH mysplash;
    
    ifstream fin;
    ofstream ofin;
    
    int Status = 0;
    int Open = 0;
    
    int OnCreate(HWND hwnd);
    int OnCommand(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    int InitOpen(void);
    int InitSave(void);
    
    int InitWarreport();
    int InitPbss();
    int InitLe();
    
    int ErrorExit(BOOL fatal);
    
    int Test(void);
    
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        PAINTSTRUCT paintStruct;
        HDC hDC;
        HDC hMemDC;
        HBITMAP hOldBmp;
        int iIndex;
        switch (message)
        {
            case WM_LBUTTONDOWN:
                    if (mysplash.SHOWING) {
                        mysplash.Hide();
                    }
                break;
            case WM_CREATE:
                OnCreate(hwnd);
                break;
            case WM_COMMAND:
                OnCommand(hwnd, message, wParam, lParam);
                break;
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            case WM_PAINT:
    			hDC = BeginPaint(hwnd,&paintStruct);
                hMemDC=CreateCompatibleDC(paintStruct.hdc);
                //and copy the bitmap into it
                hOldBmp=(HBITMAP)SelectObject(hMemDC,LoadMain);
                //blt (pronounced 'blit' - bit block transfer) the image onto the window
                //this is essentially copying the image from the memory dc to the display dc.
                BitBlt(paintStruct.hdc,                //target dc
                    1,1,           //left-top to place bitmap on target
                    722,154,  //dimensions of target to receive bitmap
                    hMemDC,                //source dc
                    0,0,                   //left-top to take bitmap from source
                    SRCCOPY);              //flag for blt operation - here it's just a copy
                //now restore the memory dc to preserve our bitmap
                SelectObject(hMemDC,hOldBmp);
                //free resources back to system used by memory dc
                DeleteDC(hMemDC);            
                //SendMessage(hwnd,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
                HFONT DefGuiFont;
                // Select standard font
                DefGuiFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
                SelectObject(hDC, DefGuiFont);
                SetBkMode(hDC, TRANSPARENT);
    			SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
                //TextOut(hDC,200,200,text1,sizeof(text1)-1);
    			EndPaint(hwnd, &paintStruct);
        
                break;
            case WM_SIZE:
                // Tabs
                //MoveWindow(hTab, 130, 158, 590, 469, TRUE);
    
                // list view
                MoveWindow(hList,6,158,130,469,TRUE);
                SendMessage(hList,LVM_ARRANGE,LVA_ALIGNTOP,0);
            break;
            case WM_NOTIFY:
                if(((LPNMHDR)lParam)->code == NM_CLICK) {
                    iIndex = (int)SendMessage(hList, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
    				if(iIndex == -1) {
                        ErrorExit(FALSE);					
                    }
                    if (iIndex == 0) {
                        InitWarreport();
                    } else if (iIndex == 1) {
                        InitPbss();
                    } else if (iIndex == 2) { 
                        InitLe();
                    }
                }
            break;
            default:
                break;
        }
        return DefWindowProc(hwnd,message,wParam,lParam);
    }
    
    
    char szClassName[ ] = "Wm";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {             
        int a = 15, b = 5;
        a = a + b;
        MSG messages;            
        WNDCLASSEX wincl;        
    
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      
        wincl.style = CS_DBLCLKS;                 
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = "MainMenu";                 
        wincl.cbClsExtra = 0;                      
        wincl.cbWndExtra = 0;                      
        wincl.hbrBackground = HBRUSH(COLOR_3DFACE + 1); 
        
        if (!RegisterClassEx (&wincl))
            return 0;
    
        
    
    
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "ClanPortal - British / Hollands Special Forces",       /* Title Text */
               WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX, /* default window */
               80,       /* Windows decides the position */
               20,       /* where the window ends up on the screen */
               730,                 /* The programs width */
               700,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL
               );
        // 730
        // 700
        ShowWindow (hwnd, nFunsterStil);
    
        while (GetMessage (&messages, NULL, 0, 0))
        {
    
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
    
    /* Functions */
    
    /* Function which handles the message WM_CREATE */
    int OnCreate(HWND hwnd) {
        InitCommonControls();
        mysplash.Init(hwnd, hThisInstance, IDB_SPLASH);
        mysplash.Show();
        int statwidths[] = {100, -1};
    
        LoadMain = (HBITMAP)LoadImage(0, "sig.bmp\0", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
      
        if (LoadMain == NULL) {
            ErrorExit(FALSE);
        }
    
        hStatus = CreateWindowEx(
                0,
                STATUSCLASSNAME,
                NULL,
                WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 
                0, 
                0, 
                0, 
                0,
                hwnd,
                (HMENU)IDC_MAIN_STATUS,
                hThisInstance,
                NULL
        );
    
        SendMessage(hStatus, SB_SETPARTS, 2, (LPARAM) statwidths);
        SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM) "Ready");
        SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)"Welcome to WarManager.");
        Status = 1;
    
    
        /*hTab = CreateWindowEx(
                0,                       //more or 'extended' styles
                WC_TABCONTROL,           //the 'class' of window to create
                NULL,                    //the window title
                WS_CHILD|WS_VISIBLE|     //window style: how it looks
                TCS_FIXEDWIDTH, 
                0,                       //window position: left
                0,                       //window position: top
                0,                       //window width
                0,                       //window height
                hwnd,                    //parent window handle
                NULL,                    //handle to this windows's menu
                hThisInstance,                 //application instance
                NULL
        );                  
        if (hTab == NULL) {
            DWORD err = GetLastError();
            BOOL fatal = TRUE;
            ErrorExit(err, fatal);
        }
            
            ZeroMemory(&tabPage,sizeof(TCITEM));
            tabPage.mask=TCIF_TEXT;
            tabPage.pszText=TEXT("Make Report");
            tabPage.cchTextMax=lstrlen(tabPage.pszText);
            SendMessage(hTab,TCM_INSERTITEM,0,(LPARAM)&tabPage);
    
            tabPage.pszText=TEXT("Read Reports");
            tabPage.cchTextMax=lstrlen(tabPage.pszText);
            SendMessage(hTab,TCM_INSERTITEM,1,(LPARAM)&tabPage);
    
            SendMessage(hTab,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);*/
            
    
        hList = CreateWindow(
                    WC_LISTVIEW,
                    "",
                    WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | LVS_SINGLESEL,
                    0,
                    0,
                    0,
                    0,
                    hwnd, 
                    NULL,
                    hThisInstance,
                    NULL
                );
        static HIMAGELIST hLargeIcons;
        HINSTANCE hLib;
        int nNumIcons;
        int i;
        LVITEM lvitem;
        LVCOLUMN lvcolumn;
    
        hLargeIcons=ImageList_Create(GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),ILC_COLOR32|ILC_MASK,1,1); 
    
           HBITMAP hLIcons = (HBITMAP)LoadImage(0, "splash.bmp\0", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
    	   int bmp = ImageList_Add(hLargeIcons, (HBITMAP)hLIcons, NULL);
           hLIcons = (HBITMAP)LoadImage(0, "sig.bmp\0", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
    	   int bmp1 = ImageList_Add(hLargeIcons, (HBITMAP)hLIcons, NULL);
    
    	   DeleteObject(hLIcons);
                
         
            ListView_SetImageList(hList,hLargeIcons,LVSIL_SMALL);
    
            ZeroMemory(&lvitem,sizeof(lvcolumn));
            lvcolumn.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;    // Type of mask
            lvcolumn.cx=0x28;                                   // width between each coloum
            lvcolumn.pszText="Menu";                            // First Header Text
            lvcolumn.cx=0x80;             
            SendMessage(hList,LVM_INSERTCOLUMN,0,(LPARAM)&lvcolumn);
            ZeroMemory(&lvitem,sizeof(lvitem));
            //  Setting properties Of members:    
    
            lvitem.mask=LVIF_TEXT | LVIF_IMAGE;   // Text Style
            lvitem.cchTextMax = 256; // Max size of test
            lvitem.iItem=0;          // choose item  
            lvitem.iImage=bmp;
            lvitem.iSubItem=0;       // Put in first coluom
            lvitem.pszText="TWL Clan League"; // Text to display (can be from a char variable) (Items)
    
            SendMessage(hList,LVM_INSERTITEM,0,(LPARAM)&lvitem);
    
            lvitem.mask=LVIF_TEXT | LVIF_IMAGE;   // Text Style
            lvitem.cchTextMax = 256; // Max size of test
            lvitem.iItem=0;          // choose item  
            lvitem.iImage=bmp;
            lvitem.iSubItem=0;       // Put in first coluom
            lvitem.pszText="PBSS Organizer"; // Text to display (can be from a char variable) (Items)
    
            SendMessage(hList,LVM_INSERTITEM,0,(LPARAM)&lvitem);
    
            lvitem.mask=LVIF_TEXT | LVIF_IMAGE;   // Text Style
            lvitem.cchTextMax = 256; // Max size of test
            lvitem.iItem=0;          // choose item  
            lvitem.iImage=bmp;
            lvitem.iSubItem=0;       // Put in first coluom
            lvitem.pszText="Warreport"; // Text to display (can be from a char variable) (Items)
    
            SendMessage(hList,LVM_INSERTITEM,0,(LPARAM)&lvitem);
       
    }   
    
    /* Function which handles the message WM_COMMAND */
    int OnCommand(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
        switch (LOWORD(wParam)) {
            ErrorExit(FALSE);
            case MENU_FILE_ID_OPEN:
                InitOpen();
            break;
            case MENU_FILE_ID_CLOSE:
                SendMessage(hwnd, WM_DESTROY, 0, 0);
            break;
            case MENU_HELP_ID_ABOUT:
                MessageBox(hwnd, "This program is created under GNU GPL license.This program may not be rewritten, without asking permission to the author of this program.If you are not sure what is, and what is not allowed; mail Nephiroth.\nAuthor: Lars \"Nephiroth\" Wesselius <[email protected]>", "About...", MB_OK);
            break;
            case MENU_FILE_ID_SAVE:
                InitSave();
            break;
            case MENU_FILE_ID_TEST:
                Test();
            break;
            case MENU_VIEW_ID_SBAR:
                if (Status == 1) {
                    ShowWindow(hStatus, 0);
                    Status = 0;
                } else if (Status == 0) {
                    ShowWindow(hStatus, 1);
                    Status = 1;
                }
            break;
            default:
            break;
        }
        if (HIWORD(wParam) == BN_CLICKED) {
            MessageBox(hwnd, "lol", "lol", MB_OK);
        }
    }
    
    
    
    /* Function to handle all save calls */
    int InitSave (void) {
    
    }
    
    /* Funtion to handle open file calls */
    int InitOpen (void) {
        if ((Open == 0) || (Open == 1)) {
            SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Succesfully Loaded.");
            if (GetFocus() == hwnd) { 
                FlashWindow(hwnd, TRUE);
            }
            Open = 1;
        } else if (Open == 2) {
            SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Loading...");
        }
    }
    
    /* Function where all the tests go */
    int Test (void) {
    }
    
    /* Automatic error handler */
    int ErrorExit (BOOL fatal) {
        DWORD err = GetLastError();
        LPVOID lpMsgBuf;
    
        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
            NULL,
            err,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR) &lpMsgBuf,
            0,
            NULL
        );
       
        if (fatal == TRUE) {
            MessageBox(hwnd, (const char*)lpMsgBuf, "Fatal Error", MB_ICONERROR | MB_OK);
        } else {
            MessageBox(hwnd, (const char*)lpMsgBuf, "Error", MB_ICONEXCLAMATION | MB_OK); 
        }
     
        LocalFree(lpMsgBuf);
        
        if (fatal == TRUE) {
            PostQuitMessage (0);
        }  
    }
    
    /* Warreport database structure
    
    X VS X  Date+Time   map   report
    HSF VS BSF  23 March 12:00  Pipeline    the match sucked
    
    //0 war     //hGroupWarr
    //1 PBSS    //hGroupPbss
    //2 League  //hGroupLe
     Function to handle warreport screen */
    int InitWarreport(void) {
        BOOL pbss = IsWindowVisible(hGroupPbss);
        BOOL le = IsWindowVisible(hGroupLe);
        if (pbss == TRUE) {
            ShowWindow(hGroupPbss, 0);
        } else if (le == TRUE) {
            ShowWindow(hGroupLe, 0);
        }
    
        if (hGroupWarr == NULL) {
            HWND hEdit1;
            HWND hEdit2;
            HWND hEdit3;
            HWND hEdit4;
            HWND hEdit5;
            HWND hEdit6;
            HWND hText;
            HWND hText1;
            HWND hText2;
            HWND hText3;
            HWND hText4;
            HWND hText5;
            HWND hCombo;
            HWND hBtn;
            hGroupWarr = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("BUTTON"),                         //'class' of control to create
                    TEXT("Create Warreport"),                      //the control caption
                    WS_CHILD|WS_VISIBLE|BS_GROUPBOX,        //control style: how it looks
                    140,                                    //control position: left
                    155,                                      //control position: top
                    581,                                    //control width
                    473,                                     //control height
                    hwnd,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
    
            /* All text */
            SendMessage(hGroupWarr,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
            hText = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("VS"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    200,                                    //control position: left
                    20,                                      //control position: top
                    20,                                    //control width
                    20,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
    
            hText1 = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("Date and time"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    20,                                    //control position: left
                    97,                                      //control position: top
                    70,                                    //control width
                    50,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            SendMessage(hText1,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hText2 = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("Map (Press and hold)"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    20,                                    //control position: left
                    150,                                      //control position: top
                    150,                                    //control width
                    20,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            SendMessage(hText2,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
        
            hText3 = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("Report"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    20,                                    //control position: left
                    195,                                      //control position: top
                    40,                                    //control width
                    20,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            SendMessage(hText3,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hText4 = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("Result"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    20,                                    //control position: left
                    50,                                      //control position: top
                    40,                                    //control width
                    20,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            SendMessage(hText4,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hText5 = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT(":"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    83,                                    //control position: left
                    67,                                      //control position: top
                    20,                                    //control width
                    20,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            
    
    
    
            /* All edits */
            hEdit1 = CreateWindowEx(
                    WS_EX_CLIENTEDGE,                      //more or 'extended' styles
                    TEXT("EDIT"),                          //'class' of control to create
                    TEXT("British Special Forces"),      //the control caption
                    WS_CHILD|WS_VISIBLE|WS_BORDER,         //control style: how it looks
                    20,                                    //control position: left
                    18,                                    //control position: top
                    160,                                   //control width
                    25,                                    //control height
                    hGroupWarr,                                  //parent window handle
                    NULL,                                  //control's ID
                    hThisInstance,                               //application instance
                    NULL
            );
            SendMessage(hEdit1,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
            
            hEdit2 = CreateWindowEx(
                    WS_EX_CLIENTEDGE,                      //more or 'extended' styles
                    TEXT("EDIT"),                          //'class' of control to create
                    TEXT("Flame Grilled"),      //the control caption
                    WS_CHILD|WS_VISIBLE|WS_BORDER,         //control style: how it looks
                    235,                                    //control position: left
                    18,                                    //control position: top
                    160,                                   //control width
                    25,                                    //control height
                    hGroupWarr,                                  //parent window handle
                    NULL,                                  //control's ID
                    hThisInstance,                               //application instance
                    NULL
            );
            SendMessage(hEdit2,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hEdit3 = CreateWindowEx(
                    WS_EX_CLIENTEDGE,                      //more or 'extended' styles
                    TEXT("EDIT"),                          //'class' of control to create
                    TEXT("23 March 20:00 GMT"),      //the control caption
                    WS_CHILD|WS_VISIBLE|WS_BORDER,         //control style: how it looks
                    20,                                    //control position: left
                    115,                                    //control position: top
                    160,                                   //control width
                    25,                                    //control height
                    hGroupWarr,                                  //parent window handle
                    NULL,                                  //control's ID
                    hThisInstance,                               //application instance
                    NULL
            );
            SendMessage(hEdit3,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hEdit4 = CreateWindowEx(
                    WS_EX_CLIENTEDGE,                      //more or 'extended' styles
                    TEXT("EDIT"),                          //'class' of control to create
                    TEXT(""),    //the control caption
                    WS_CHILD|WS_VISIBLE|WS_BORDER|         //control style: how it looks
                    ES_MULTILINE | ES_AUTOVSCROLL,
                    20,                                    //control position: left
                    215,                                    //control position: top
                    350,                                   //control width
                    220,                                    //control height
                    hGroupWarr,                                  //parent window handle
                    NULL,                                  //control's ID
                    hThisInstance,                               //application instance
                    NULL
            );
            SendMessage(hEdit4,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hEdit5 = CreateWindowEx(
                    WS_EX_CLIENTEDGE,                      //more or 'extended' styles
                    TEXT("EDIT"),                          //'class' of control to create
                    TEXT(""),    //the control caption
                    WS_CHILD|WS_VISIBLE|WS_BORDER,         //control style: how it looks
                    20,                                    //control position: left
                    65,                                    //control position: top
                    50,                                   //control width
                    25,                                    //control height
                    hGroupWarr,                                  //parent window handle
                    NULL,                                  //control's ID
                    hThisInstance,                               //application instance
                    NULL
            );
            SendMessage(hEdit5,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
    
            hEdit6 = CreateWindowEx(
                    WS_EX_CLIENTEDGE,                      //more or 'extended' styles
                    TEXT("EDIT"),                          //'class' of control to create
                    TEXT(""),    //the control caption
                    WS_CHILD|WS_VISIBLE|WS_BORDER,         //control style: how it looks
                    100,                                    //control position: left
                    65,                                    //control position: top
                    50,                                   //control width
                    25,                                    //control height
                    hGroupWarr,                                  //parent window handle
                    NULL,                                  //control's ID
                    hThisInstance,                               //application instance
                    NULL
            );
            SendMessage(hEdit6,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
           
    
            /* Rest */
            hCombo = CreateWindowEx(
                        0,                                     //more or 'extended' styles
                        TEXT("COMBOBOX"),                      //'class' of control to create
                        NULL,                                  //the control caption
                        WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,      //control style: how it looks
                        20,                                    //control position: left
                        170,                                   //control position: top
                        200,                                   //control width
                        500,                                    //control height
                        hGroupWarr,                                  //parent window handle
                        NULL,                                  //control's ID
                        hThisInstance,                               //application instance
                        NULL
                );
            SendMessage(hCombo,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Bridge Crossing");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Bridge SE");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"MOUT McKenna");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Collapsed Tunnel");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Pipeline");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Pipeline SF");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"FLS Assault");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Mountain Pass");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Mountain Ambush");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Mountain Pass SE");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"JRTC Farm Raid");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Weapons Cache");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Weapons Cache SE");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Insurgent Camp");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"River Basin");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Radio Tower");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Headquarters Raid");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Swamp Raid");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF CSAR");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Recon");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Hospital");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF SandStorm");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Arctic");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Village");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Oasis");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Taiga");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Urban Assault");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Woodland Outpost");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Courtyard");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF PCR");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Blizzard");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Water Treatment");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Dockside");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"SF Extraction");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Dusk");
            SendMessage(hCombo,CB_ADDSTRING,0,(LPARAM)"Border");
    
            hBtn = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("BUTTON"),                         //'class' of control to create
                    TEXT("Submit"),            //the control caption
                    WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,   //control style: how it looks
                    20,                                     //control position: left
                    440,                                     //control position: top
                    75,                                    //control width
                    25,                                     //control height
                    hGroupWarr,                                   //parent window handle
                    (HMENU)BTN_SUBMIT,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );   
            SendMessage(hBtn,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
        } else if (hGroupWarr != NULL) {
            ShowWindow(hGroupWarr, 1);
        }
    }
    
    
    /* Function to the PBSS organizer */
    int InitPbss (void) {
        BOOL warr = IsWindowVisible(hGroupWarr);
        BOOL le = IsWindowVisible(hGroupLe);
        if (warr == TRUE) {
            ShowWindow(hGroupWarr, 0);
        } else if (le == TRUE) {
            ShowWindow(hGroupLe, 0);
        }
        if (hGroupPbss == NULL) {
            HWND hText;
            hGroupPbss = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("BUTTON"),                         //'class' of control to create
                    TEXT("Pbss"),                      //the control caption
                    WS_CHILD|WS_VISIBLE|BS_GROUPBOX,        //control style: how it looks
                    140,                                    //control position: left
                    155,                                      //control position: top
                    581,                                    //control width
                    473,                                     //control height
                    hwnd,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            SendMessage(hGroupPbss,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
            hText = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("pb"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    140,                                    //control position: left
                    155,                                      //control position: top
                    581,                                    //control width
                    473,                                     //control height
                    hGroupPbss,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
        } else {
            ShowWindow(hGroupPbss, 1);
        }
    }
    
    /* Function to the League */
    int InitLe (void) {
        BOOL pbss = IsWindowVisible(hGroupPbss);
        BOOL warr = IsWindowVisible(hGroupWarr);
        if (pbss == TRUE) {
            ShowWindow(hGroupPbss, 0);
        } else if (warr == TRUE) {
            ShowWindow(hGroupWarr, 0);
        }
            ShowWindow(hGroupWarr, 0);
            ShowWindow(hGroupPbss, 0);
        if (hGroupLe == NULL) {
            HWND hText;
            hGroupLe = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("BUTTON"),                         //'class' of control to create
                    TEXT("League"),                      //the control caption
                    WS_CHILD|WS_VISIBLE|BS_GROUPBOX,        //control style: how it looks
                    140,                                    //control position: left
                    155,                                      //control position: top
                    581,                                    //control width
                    473,                                     //control height
                    hwnd,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
            SendMessage(hGroupLe,WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
            hText = CreateWindowEx(
                    0,                                      //more or 'extended' styles
                    TEXT("STATIC"),                         //'class' of control to create
                    TEXT("aap"),                      //the control caption
                    WS_CHILD|WS_VISIBLE,        //control style: how it looks
                    200,                                    //control position: left
                    200,                                      //control position: top
                    581,                                    //control width
                    473,                                     //control height
                    hGroupLe,                                   //parent window handle
                    NULL,                                   //control's ID
                    hThisInstance,                                //application instance
                    NULL
            );
        } else {
            ShowWindow(hGroupLe, 1);
        }
    }
    Dev-C++ 4.9.9.2
    Code::Blocks
    Win XP

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    29
    It has to do with, that the hGroupWarr gets the message.Any way to 'forward' the messages to the messageproc?
    Dev-C++ 4.9.9.2
    Code::Blocks
    Win XP

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Controls need to use the main window (hwnd) as parent rather than the group box (hGroupWarr). Just position the controls over the group box. You don't receive the WM_COMMAND message because notifications (WM_COMMAND and WM_NOTIFY) are sent to the parent window of the control.

  8. #8
    Registered User
    Join Date
    Jan 2006
    Posts
    29
    I know, but if you look further at the code, you see that im hiding the hGroupWarr, which will also hide all controls on it.

    But I have another idea.Instead of the groupbox, Ill make a new window, with a new messageproc.The same, only a messageproc will be added.
    Dev-C++ 4.9.9.2
    Code::Blocks
    Win XP

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    well just send the main procedure HWND to the 'InitWarreport()' and use it as the handle to the parent or owner window; something like:
    Code:
    ...
    int InitWarreport(HWND );
    ...
    case WM_NOTIFY:
        {
        ...
        if (iIndex == 0) {InitWarreport(hwnd);}
        ...
        }
    break;
    ...
    ...
    int InitWarreport(HWND thehwnd)
    {
    ...
    hBtn=CreateWindowEx(0,"BUTTON","Submit",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
    200,640,75,25,thehwnd,(HMENU)1,hThisInstance,NULL);
    ...
    }
    niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  2. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  3. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM
  4. Add ON_COMMAND menu button handler
    By kybert in forum Windows Programming
    Replies: 6
    Last Post: 09-15-2002, 07:33 PM