How do i know the handle of a windows message?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 5132 Views - Last Post: 01 January 2012 - 11:56 AM Rate Topic: -----

#1 Ty Meador  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 23-May 11

How do i know the handle of a windows message?

Posted 28 December 2011 - 05:51 PM

I am writing my first (useful) G.U.I. program using the windows api. i am trying to get the user's input from a combo box. i already have the boxes populated im just having trouble dispatching the CB_GETCURSEL message, and storing the index to an integer. I know WHY I'm receiving these errors but i cannot find another way to do what i am trying to do. how SHOULD i be checking the handler?
#include <windows.h>
#include "musickey.h"
#include <string>
#include <iostream>
using namespace std;
// Global variables

// The main window class name.
static TCHAR szWindowClass[] = ("Key3.0");

// The string that appears in the application's title bar.
static TCHAR szTitle[] = ("Key 3.0");

HINSTANCE hInst;

// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;


    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance,IDI_APPLICATION);

    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            ("Call to RegisterClassEx failed!"),
            ("Win32 Guided Tour"),
            NULL);

        return 1;
    }

    hInst = hInstance; // Store instance handle in our global variable

    HWND parent = CreateWindow(
        szWindowClass,
        szTitle,
        WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        CW_USEDEFAULT, CW_USEDEFAULT,
        500, 400,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!parent)
    {
        MessageBox(NULL,
            ("Call to CreateWindow failed!"),
            ("Key 3.0"),
            NULL);
        return 1;
    }

    musickey myKey;
    const LPCSTR chromatic[]=
    {
        "A","A#","B","C","C#","D","D#","E","F","F#","G","G#"
    };

    const LPCSTR modeOptions[] =
	{
        "major",
        "minor",
        "dorian",
        "phrygian",
        "lydian",
        "mixolydian",
        "locrian",
	};
//Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
    HWND ComboBox1 = CreateWindow
    (
        TEXT("COMBOBOX"),
        NULL,
        WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
        50,50,80,250,
        parent,
        (HMENU)1,
        hInst,
        NULL
    );


    for(int Count = 0; Count < 12; Count++)
    {
        SendMessage
        (
            ComboBox1,
            CB_ADDSTRING,
            NULL,
            reinterpret_cast<LPARAM>(chromatic[Count])
        );
    }
    SendMessage(ComboBox1, CB_SETCURSEL, 3, NULL);
//\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
//Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
    HWND ComboBox2 = CreateWindow
    (
        TEXT("COMBOBOX"),
        NULL,
        WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
        150,50,180,150,
        parent,
        (HMENU)2,
        hInst,
        NULL
    );

    for(int Count = 0; Count < 7; Count++)
    {
        SendMessage
        (
            ComboBox2,
            CB_ADDSTRING,
            NULL,
            reinterpret_cast<LPARAM>(modeOptions[Count])
        );
    }
    SendMessage(ComboBox2, CB_SETCURSEL, 0, NULL);
//\Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

    // The parameters to ShowWindow explained:
    // parent: the value returned from CreateWindow
    // nCmdShow: the fourth parameter from WinMain
    ShowWindow(parent,
        nCmdShow);
    UpdateWindow(parent);


//=====
    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
            break;

        case WM_CREATE:
            break;

        case WM_COMMAND:
            if(hWnd == ComboBox1)
            {
                int key = SendMessage
                (
                    hWnd,
                    CB_GETCURSEL,
                    0,0
                );
            }
            else if(hWnd == ComboBox2)
            {
                int mode = SendMessage
                (
                    hWnd,
                    CB_GETCURSEL,
                    0,0
                );
            }
        break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
            break;
    }
    return 0;
}




Errors

I:\Computer Programming\C++\Key 3.0 (2)\main.cpp||In function 'LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|181|error: 'ComboBox1' was not declared in this scope|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|183|warning: unused variable 'key'|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|190|error: 'ComboBox2' was not declared in this scope|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|192|warning: unused variable 'mode'|
||=== Build finished: 2 errors, 2 warnings ===|

Is This A Good Question/Topic? 0
  • +

Replies To: How do i know the handle of a windows message?

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do i know the handle of a windows message?

Posted 28 December 2011 - 07:20 PM

Well, there are two ways to get a handle of a control OR know what control sent the message.
1. When you create a control/window with CreateWindow/Ex, it returns a handle to the newly created window which you are doing already ComboBox1 = CreateWindow (I think, I don't know C.

2. You get the handle of the window sending you the message in WM_COMMAND (in the case of buttons, static controls etc...), and in WM_NOTIFY.

In the case of Comboboxes, the notifications are sent in WM_COMMAND. You want to get the index of the selected item when it changes? You could handle the CBN_SELCHANGE in your WM_COMMAND message handler:
The High Word of wParam contains the message and lParam contains the handle to the combobox. Not sure how you get the High Word in your lang.

This is a snippet to get the text of selected item when it changes (sorry in Assembly but you should get the picture)
    .elseif eax==WM_COMMAND
        mov		edx,wParam
        movzx	eax,dx
        shr		edx,16
        .if edx==BN_CLICKED
            ; oooh a button was clicked
            
        .elseif edx == CBN_SELCHANGE
            invoke	SendMessage, lParam, CB_GETCURSEL , 0, 0
            invoke	SendMessage, lParam, CB_GETLBTEXTLEN, eax, 0
            inc     eax
            mov		ebx, eax
            invoke	HeapAlloc, hHeap, HEAP_ZERO_MEMORY, eax
            mov		esi, eax
            sub		ebx, 1
            invoke	SendMessage, lParam, WM_GETTEXT, ebx, esi
            
            invoke  MessageBox, NULL, esi, NULL, NULL


Now, if you want to press a button and get something from the combobox, remember you already have the handle from CreateWindowEx -> ComboBox1. Just use ComboBox1 with SendMessage in your button click handler.

As for your error? Can't help you there, sorry.

This post has been edited by GunnerInc: 28 December 2011 - 07:21 PM

Was This Post Helpful? 1
  • +
  • -

#3 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1325
  • View blog
  • Posts: 4,551
  • Joined: 19-February 09

Re: How do i know the handle of a windows message?

Posted 28 December 2011 - 08:41 PM

Hi, scope (local or global) concerns where a variable is declared and thus able to be accessed. Wikipedia: local variable


Wikipedia said:

... a (local) variable is accessible only from the function or block in which it is declared.


You create the combo box windows in WinMain and the corresponding local HWND variables and also the arrays. If you wish to access the variables and arrays in WinProc you could declare them in global scope.

Another option is to create the combo box windows in the WinProc WM_CREATE section and use static local variables to remember the state of the variables between calls.

http://zetcode.com/t...pi/controlsIII/
Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • Posts: 2,234
  • Joined: 20-March 10

Re: How do i know the handle of a windows message?

Posted 28 December 2011 - 11:32 PM

Yes you should be creating your comboboxes in WM_CREATE:


case WM_CREATE:



//Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        ComboBox1 = CreateWindow
                    (
                        TEXT("COMBOBOX"),
                        NULL,
                        WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                        50,50,80,250,
                        hWnd,
                        (HMENU)COMBOBOX1,
                        hInst,
                        NULL
                    );


        for(int Count = 0; Count < 12; Count++)
        {
            SendMessage
            (
                ComboBox1,
                CB_ADDSTRING,
                0,
                reinterpret_cast<LPARAM>(chromatic[Count])
            );
        }
        SendMessage(ComboBox1, CB_SETCURSEL, 3, 0);
//\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
//Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
        ComboBox2 = CreateWindow
                    (
                        TEXT("COMBOBOX"),
                        NULL,
                        WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
                        150,50,180,150,
                        hWnd,
                        (HMENU)COMBOBOX2,
                        hInst,
                        NULL
                    );

        for(int Count = 0; Count < 7; Count++)
        {
            SendMessage
            (
                ComboBox2,
                CB_ADDSTRING,
                0,
                reinterpret_cast<LPARAM>(modeOptions[Count])
            );
        }
        SendMessage(ComboBox2, CB_SETCURSEL, 0, 0);


        return 0;





And in your HMENU for the boxes you shouldn't be using magic numbers like 1 and 2

so define some labels for them

#define COMBOBOX1 101
#define COMBOBOX2 202

in WinMain take all the combobox creation out so it looks like this


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;


    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance,IDI_APPLICATION);

    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
                   ("Call to RegisterClassEx failed!"),
                   ("Win32 Guided Tour"),
                   MB_OK);

        return 1;
    }

    hInst = hInstance; // Store instance handle in our global variable

    HWND parent = CreateWindow(
                      szWindowClass,
                      szTitle,
                      WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      500, 400,
                      NULL,
                      NULL,
                      hInstance,
                      NULL
                  );

    if (!parent)
    {
        MessageBox(NULL,
                   ("Call to CreateWindow failed!"),
                   ("Key 3.0"),
                   MB_OK);
        return 1;
    }


//\Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

    // The parameters to ShowWindow explained:
    // parent: the value returned from CreateWindow
    // nCmdShow: the fourth parameter from WinMain
    ShowWindow(parent,
               nCmdShow);
    UpdateWindow(parent);


//=====
    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}




For your MessageBoxes you should not be passing NULL for the last parameter use MB_OK or something similar.

ListItem and ItemIndex should be really made global
as I take it you are going to use them in other functions.
using namespace std;
// Global variables
TCHAR  ListItem[256];
int ItemIndex;



In WndProc you should forward declare your comboboxes like this
along with variables that need to be initialised.

 HWND ComboBox1;
    HWND ComboBox2;

    musickey myKey;

    const LPCSTR chromatic[]=
    {
        "A","A#","B","C","C#","D","D#","E","F","F#","G","G#"
    };


    const LPCSTR modeOptions[] =
    {
        "major",
        "minor",
        "dorian",
        "phrygian",
        "lydian",
        "mixolydian",
        "locrian",
    };



In WM_CREATE: You should be creating the comboxes like this


 switch (message)
    {
    case WM_INITDIALOG:
        break;

    case WM_CREATE:



//Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        ComboBox1 = CreateWindow
                    (
                        TEXT("COMBOBOX"),
                        NULL,
                        WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                        50,50,80,250,
                        hWnd,
                        (HMENU)COMBOBOX1,
                        hInst,
                        NULL
                    );


        for(int Count = 0; Count < 12; Count++)
        {
            SendMessage
            (
                ComboBox1,
                CB_ADDSTRING,
                0,
                reinterpret_cast<LPARAM>(chromatic[Count])
            );
        }
        SendMessage(ComboBox1, CB_SETCURSEL, 3, 0);
//\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
//Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
        ComboBox2 = CreateWindow
                    (
                        TEXT("COMBOBOX"),
                        NULL,
                        WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
                        150,50,180,150,
                        hWnd,
                        (HMENU)COMBOBOX2,
                        hInst,
                        NULL
                    );

        for(int Count = 0; Count < 7; Count++)
        {
            SendMessage
            (
                ComboBox2,
                CB_ADDSTRING,
                0,
                reinterpret_cast<LPARAM>(modeOptions[Count])
            );
        }
        SendMessage(ComboBox2, CB_SETCURSEL, 0, 0);


        return 0;




and you really dont need reinterpret_cast here, a simple (LPARAM) will do.


We always react to events in WM_COMMAND:
To do this for comboboxes it would be something like this

case WM_COMMAND:

        switch(LOWORD(wParam)) //the ID is wParam
        {
        case COMBOBOX1:

            if(HIWORD(wParam) == CBN_SELCHANGE)
                // If the user makes a selection from the list:
                //   Send CB_GETCURSEL message to get the index of the selected list item.
                //   Send CB_GETLBTEXT message to get the item.
                //   Display the item in a messagebox.
            {

                ItemIndex = SendMessage((HWND) lParam, (UINT) CB_GETCURSEL,
                                            (WPARAM) 0, (LPARAM) 0);

                SendMessage((HWND) lParam, (UINT) CB_GETLBTEXT,
                                    (WPARAM) ItemIndex, (LPARAM) ListItem);

            }




        case COMBOBOX2:

            if(HIWORD(wParam) == CBN_SELCHANGE)
                // If the user makes a selection from the list:
                //   Send CB_GETCURSEL message to get the index of the selected list item.
                //   Send CB_GETLBTEXT message to get the item.
                //   Display the item in a messagebox.
            {
                ItemIndex = SendMessage((HWND) lParam, (UINT) CB_GETCURSEL,
                                            (WPARAM) 0, (LPARAM) 0);

                SendMessage((HWND) lParam, (UINT) CB_GETLBTEXT,
                                    (WPARAM) ItemIndex, (LPARAM) ListItem);

            }


        return 0;
        }




remember that we set up some defines earlier and used them in our combobox creation
well now they come into play and makes it easier to read what is happening instead of just

case 1:
.....

case 2:
.....

etc.

Hope that sorts a few things out for you.

Snoopy.

This post has been edited by snoopy11: 28 December 2011 - 11:35 PM

Was This Post Helpful? 1
  • +
  • -

#5 Ty Meador  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 23-May 11

Re: How do i know the handle of a windows message?

Posted 31 December 2011 - 11:02 PM

View Postsnoopy11, on 28 December 2011 - 11:32 PM, said:

Quote

Here is my new code.

#include <windows.h>
#include "musickey.h"
#include <cstring>
#include <iostream>
using namespace std;
// Global variables

// The main window class name.
static TCHAR szWindowClass[] = ("Key3.0");

// The string that appears in the application's title bar.
static TCHAR szTitle[] = ("Key 3.0");
HINSTANCE hInst;
HWND parent;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND ComboBox1;
HWND ComboBox2;
HWND TextBox;
int keyIndex = 3, modeIndex = 0;
musickey myKey;
const LPCSTR chromatic[]=
{
    "A","A#","B","C","C#","D","D#","E","F","F#","G","G#"
};

const LPCSTR modeOptions[] =
{
    "major",
    "minor",
    "dorian",
    "phrygian",
    "lydian",
    "mixolydian",
    "locrian",
};
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;


    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance,IDI_APPLICATION);

    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            ("Call to RegisterClassEx failed!"),
            ("Win32 Guided Tour"),
            NULL);

        return 1;
    }

    hInst = hInstance; // Store instance handle in our global variable

        parent = CreateWindow(
        szWindowClass,
        szTitle,
        WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        CW_USEDEFAULT, CW_USEDEFAULT,
        500, 400,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!parent)
    {
        MessageBox(NULL,
            ("Call to CreateWindow failed!"),
            ("Key 3.0"),
            NULL);
        return 1;
    }

    // The parameters to ShowWindow explained:
    // parent: the value returned from CreateWindow
    // nCmdShow: the fourth parameter from WinMain
    ShowWindow(parent,
        nCmdShow);
    UpdateWindow(parent);



//=====
    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {

        case WM_CREATE:
            //Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
            ComboBox1 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                50,50,80,250,
                parent,
                (HMENU)1,
                hInst,
                NULL
            );


            for(int Count = 0; Count < 12; Count++)
            {
                SendMessage
                (
                    ComboBox1,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(chromatic[Count])
                );
            }
            SendMessage(ComboBox1, CB_SETCURSEL, 3, NULL);
        //\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        //Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
            ComboBox2 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
                150,50,180,150,
                parent,
                (HMENU)2,
                hInst,
                NULL
            );

            for(int Count = 0; Count < 7; Count++)
            {
                SendMessage
                (
                    ComboBox2,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(modeOptions[Count])
                );
            }
            SendMessage(ComboBox2, CB_SETCURSEL, 0, NULL);
        //\Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

        break;

        case WM_PAINT:
            PAINTSTRUCT ps;
            TextOut( BeginPaint(hWnd, &ps),25,25,myKey.generateScale(string(chromatic[keyIndex]), string(modeOptions[modeIndex])).c_str(),16);
            EndPaint(hWnd, &ps);
        break;

        case WM_COMMAND:
			switch(LOWORD(wParam))

				case CobmoBox1:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						keyIndex = SendMessage
						(
							ComboBox1,
							CB_GETCURSEL,
							0,0
						);
					}
				break;

				case ComboBox2:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						modeIndex = SendMessage
						(
							ComboBox2,
							CB_GETCURSEL,
							0,0
						);
					}

				break;
				SendMessage
				(
					parent,
					WM_PAINT,
					NULL,
					NULL
				);
			break;
        break;

        case WM_DESTROY:
            PostQuitMessage(0);
        break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }
    return 0;
}


but i get the errors
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp||In function 'LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|189|error: 'CobmoBox1' was not declared in this scope|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|201|error: 'ComboBox2' cannot appear in a constant-expression|
||=== Build finished: 2 errors, 0 warnings ===|
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • Posts: 2,234
  • Joined: 20-March 10

Re: How do i know the handle of a windows message?

Posted 31 December 2011 - 11:22 PM

Hi Ty...


your not really getting this in WM_COMMAND:
your case statements should be whatever you set (HMENU) to in your combobox creation routine..

In your case you set Combobox1 to a HMENU of 1
and Combobox2 to a HMENU of 2

so in WM_COMMAND it should look like

case WM_COMMAND:

            switch(LOWORD(wParam))

 

                case 1:

                    if(HIWORD(wParam) == CBN_SELCHANGE)

                    {

                        keyIndex = SendMessage

                        (

                            ComboBox1,

                            CB_GETCURSEL,

                            0,0

                        );

                    }

                break;




but i dont recommend using magic numbers for this as in a large program it becomes confusing and hard to remember what 1 or 2 represents so set up some defines like
#define combo1 1
#define combo2 2
then

case WM_COMMAND:

            switch(LOWORD(wParam))

 

                case combo1://use defined constant here

                    if(HIWORD(wParam) == CBN_SELCHANGE)

                    {

                        keyIndex = SendMessage

                        (

                            ComboBox1,

                            CB_GETCURSEL,

                            0,0

                        );

                    }

                break;



Was This Post Helpful? 1
  • +
  • -

#7 Ty Meador  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 23-May 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 09:32 AM

View Postsnoopy11, on 31 December 2011 - 11:22 PM, said:


How do you define like that? ive never used it except in header files.

#include <windows.h>
#include "musickey.h"
#include <cstring>
#include <iostream>
using namespace std;
// Global variables

// The main window class name.
static TCHAR szWindowClass[] = ("Key3.0");

// The string that appears in the application's title bar.
static TCHAR szTitle[] = ("Key 3.0");
HINSTANCE hInst;
HWND parent;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND ComboBox1;
HWND ComboBox2;
HWND TextBox;
int keyIndex = 3, modeIndex = 0;
musickey myKey;
#define ComboB1 1;
#define ComboB2 2;
const LPCSTR chromatic[]=
{
    "A","A#","B","C","C#","D","D#","E","F","F#","G","G#"
};

const LPCSTR modeOptions[] =
{
    "major",
    "minor",
    "dorian",
    "phrygian",
    "lydian",
    "mixolydian",
    "locrian",
};
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;


    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance,IDI_APPLICATION);

    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            ("Call to RegisterClassEx failed!"),
            ("Win32 Guided Tour"),
            NULL);

        return 1;
    }

    hInst = hInstance; // Store instance handle in our global variable

        parent = CreateWindow(
        szWindowClass,
        szTitle,
        WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        CW_USEDEFAULT, CW_USEDEFAULT,
        500, 400,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!parent)
    {
        MessageBox(NULL,
            ("Call to CreateWindow failed!"),
            ("Key 3.0"),
            NULL);
        return 1;
    }

    // The parameters to ShowWindow explained:
    // parent: the value returned from CreateWindow
    // nCmdShow: the fourth parameter from WinMain
    ShowWindow(parent,
        nCmdShow);
    UpdateWindow(parent);



//=====
    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {

        case WM_CREATE:
            //Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
            ComboBox1 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                50,50,80,250,
                parent,
                (HMENU)1,
                hInst,
                NULL
            );


            for(int Count = 0; Count < 12; Count++)
            {
                SendMessage
                (
                    ComboBox1,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(chromatic[Count])
                );
            }
            SendMessage(ComboBox1, CB_SETCURSEL, 3, NULL);
        //\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        //Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
            ComboBox2 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
                150,50,180,150,
                parent,
                (HMENU)2,
                hInst,
                NULL
            );

            for(int Count = 0; Count < 7; Count++)
            {
                SendMessage
                (
                    ComboBox2,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(modeOptions[Count])
                );
            }
            SendMessage(ComboBox2, CB_SETCURSEL, 0, NULL);
        //\Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

        break;

        case WM_PAINT:
            PAINTSTRUCT ps;
            TextOut( BeginPaint(hWnd, &ps),25,25,myKey.generateScale(string(chromatic[keyIndex]), string(modeOptions[modeIndex])).c_str(),16);
            EndPaint(hWnd, &ps);
        break;

        case WM_COMMAND:
			switch(LOWORD(wParam))

				case ComboB1:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						keyIndex = SendMessage
						(
							ComboBox1,
							CB_GETCURSEL,
							0,0
						);
					}
				break;

				case ComboB2:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						modeIndex = SendMessage
						(
							ComboBox2,
							CB_GETCURSEL,
							0,0
						);
					}

				break;
				SendMessage
				(
					parent,
					WM_PAINT,
					NULL,
					NULL
				);
			break;
        break;

        case WM_DESTROY:
            PostQuitMessage(0);
        break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }
    return 0;
}


This post has been edited by Ty Meador: 01 January 2012 - 09:35 AM

Was This Post Helpful? 0
  • +
  • -

#8 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 09:59 AM

You have to create the variables to hold the handles to your comboboxes as a global variable. When you create them as a local (private to the function) of a callback, they are destroyed when the callback returns.

You save the handles of your comboboxes when you create them in WM_CREATE but when WM_CREATE is finished those locals will contain whatever garbage is on the stack, so when WM_COMMAND is processed, those variables won't contain what you expect.
Was This Post Helpful? 1
  • +
  • -

#9 Ty Meador  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 23-May 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 10:23 AM

View PostGunnerInc, on 01 January 2012 - 09:59 AM, said:

You have to create the variables to hold the handles to your comboboxes as a global variable. When you create them as a local (private to the function) of a callback, they are destroyed when the callback returns.

You save the handles of your comboboxes when you create them in WM_CREATE but when WM_CREATE is finished those locals will contain whatever garbage is on the stack, so when WM_COMMAND is processed, those variables won't contain what you expect.

they are declared as global variables. look at the code above
Was This Post Helpful? 0
  • +
  • -

#10 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 10:28 AM

Eh, my bad

This post has been edited by GunnerInc: 01 January 2012 - 10:29 AM

Was This Post Helpful? 1
  • +
  • -

#11 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 10:36 AM

One thing I do see, is you are saving the parent handle for your main window when you create it, then using that same handle to create your controls in WM_CREATE, that handle is 0 when using it in WM_CREATE since CreateWindow hasn't returned a handle yet.

So, in your WM_CREATE use hWnd instead of parent for your controls parent.
Was This Post Helpful? 1
  • +
  • -

#12 Ty Meador  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 23-May 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 10:49 AM

View PostGunnerInc, on 01 January 2012 - 10:36 AM, said:


Okay, i fixed that. here is my code thus far.

#include <windows.h>
#include "musickey.h"
#include <cstring>
#include <iostream>
using namespace std;
// Global variables

// The main window class name.
static TCHAR szWindowClass[] = ("Key3.0");

// The string that appears in the application's title bar.
static TCHAR szTitle[] = ("Key 3.0");
HINSTANCE hInst;
HWND parent;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND ComboBox1;
#define ComboB1 1;
HWND ComboBox2;
#define ComboB2 2;
HWND TextBox;
int keyIndex = 3, modeIndex = 0;
musickey myKey;


const LPCSTR chromatic[]=
{
    "A","A#","B","C","C#","D","D#","E","F","F#","G","G#"
};

const LPCSTR modeOptions[] =
{
    "major",
    "minor",
    "dorian",
    "phrygian",
    "lydian",
    "mixolydian",
    "locrian",
};
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;


    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance,IDI_APPLICATION);

    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            ("Call to RegisterClassEx failed!"),
            ("Win32 Guided Tour"),
            NULL);

        return 1;
    }

    hInst = hInstance; // Store instance handle in our global variable

        parent = CreateWindow(
        szWindowClass,
        szTitle,
        WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        CW_USEDEFAULT, CW_USEDEFAULT,
        500, 400,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!parent)
    {
        MessageBox(NULL,
            ("Call to CreateWindow failed!"),
            ("Key 3.0"),
            NULL);
        return 1;
    }

    // The parameters to ShowWindow explained:
    // parent: the value returned from CreateWindow
    // nCmdShow: the fourth parameter from WinMain
    ShowWindow(parent,
        nCmdShow);
    UpdateWindow(parent);



//=====
    // Main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {

        case WM_CREATE:
            //Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
            ComboBox1 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                50,50,80,250,
                hWnd,
                (HMENU)1,
                hInst,
                NULL
            );


            for(int Count = 0; Count < 12; Count++)
            {
                SendMessage
                (
                    ComboBox1,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(chromatic[Count])
                );
            }
            SendMessage(ComboBox1, CB_SETCURSEL, 3, NULL);
        //\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        //Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
            ComboBox2 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
                150,50,180,150,
                hWnd,
                (HMENU)2,
                hInst,
                NULL
            );

            for(int Count = 0; Count < 7; Count++)
            {
                SendMessage
                (
                    ComboBox2,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(modeOptions[Count])
                );
            }
            SendMessage(ComboBox2, CB_SETCURSEL, 0, NULL);
        //\Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

        break;

        case WM_PAINT:
            PAINTSTRUCT ps;
            TextOut( BeginPaint(hWnd, &ps),25,25,myKey.generateScale(string(chromatic[keyIndex]), string(modeOptions[modeIndex])).c_str(),16);
            EndPaint(hWnd, &ps);
        break;

        case WM_COMMAND:
			switch(LOWORD(wParam))
				case ComboB1:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						keyIndex = SendMessage
						(
							ComboBox1,
							CB_GETCURSEL,
							0,0
						);
					}
				break;

				case ComboB2:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						modeIndex = SendMessage
						(
							ComboBox2,
							CB_GETCURSEL,
							0,0
						);
					}

				break;
				SendMessage
				(
					parent,
					WM_PAINT,
					NULL,
					NULL
				);
			break;
        break;

        case WM_DESTROY:
            PostQuitMessage(0);
        break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }
    return 0;
}


Errors
||=== Key 3.0, Debug ===|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp||In function 'LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|193|error: expected ':' before ';' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|193|error: expected primary-expression before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|193|error: expected ';' before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|205|error: expected ':' before ';' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|205|error: expected primary-expression before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|205|error: expected ';' before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|227|error: duplicate case value|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|205|error: previously used here|
||=== Build finished: 8 errors, 0 warnings ===|
Was This Post Helpful? 0
  • +
  • -

#13 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • Posts: 2,234
  • Joined: 20-March 10

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 10:52 AM

Hi Ty,

you generally put your

#define ComboB1 1

below your #includes


your WM_COMMAND: would look like

case WM_COMMAND:

            switch(LOWORD(wParam))

 

                case comboB1://use defined constant here

                    if(HIWORD(wParam) == CBN_SELCHANGE)

                    {

                        keyIndex = SendMessage

                        (

                            ComboBox1,

                            CB_GETCURSEL,

                            0,0

                        );

                    }

                break;






your ComboBox creation would look like



//Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        ComboBox1 = CreateWindow
                    (
                        TEXT("COMBOBOX"),
                        NULL,
                        WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                        50,50,80,250,
                        hWnd,
                        (HMENU)ComboB1,
                        hInst,
                        NULL
                    );





Best Wishes

Snoopy
Was This Post Helpful? 1
  • +
  • -

#14 Ty Meador  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 23-May 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 11:05 AM

View Postsnoopy11, on 01 January 2012 - 10:52 AM, said:

Hi Ty,

THis is soooo frustrating. im getting nonsensical errors. as if the compiler is compiling old code or something.

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {

        case WM_CREATE:
            //Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
            ComboBox1 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE| WS_CHILD | CBS_DROPDOWN | WS_VSCROLL| CBS_HASSTRINGS,
                50,50,80,250,
                hWnd,
                (HMENU)ComboB1,
                hInst,
                NULL
            );


            for(int Count = 0; Count < 12; Count++)
            {
                SendMessage
                (
                    ComboBox1,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(chromatic[Count])
                );
            }
            SendMessage(ComboBox1, CB_SETCURSEL, 3, NULL);
        //\Box 1=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=
        //Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-
            ComboBox2 = CreateWindow
            (
                TEXT("COMBOBOX"),
                NULL,
                WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
                150,50,180,150,
                hWnd,
                (HMENU)ComboB2,
                hInst,
                NULL
            );

            for(int Count = 0; Count < 7; Count++)
            {
                SendMessage
                (
                    ComboBox2,
                    CB_ADDSTRING,
                    NULL,
                    reinterpret_cast<LPARAM>(modeOptions[Count])
                );
            }
            SendMessage(ComboBox2, CB_SETCURSEL, 0, NULL);
        //\Box 2=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

        break;

        /*case WM_PAINT:
            PAINTSTRUCT ps;
            TextOut( BeginPaint(hWnd, &ps),25,25,myKey.generateScale(string(chromatic[keyIndex]), string(modeOptions[modeIndex])).c_str(),16);
            EndPaint(hWnd, &ps);*/
        break;

        case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case ComboB1:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						keyIndex = SendMessage
						(
							ComboBox1,
							CB_GETCURSEL,
							0,0
						);
					}
				break;

				case ComboB2:
					if(HIWORD(wParam) == CBN_SELCHANGE)
					{
						modeIndex = SendMessage
						(
							ComboBox2,
							CB_GETCURSEL,
							0,0
						);
					}

				break;
				SendMessage
				(
					parent,
					WM_PAINT,
					NULL,
					NULL
				);
			return 0
			}
        break;

        case WM_DESTROY:
            PostQuitMessage(0);
        break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }
    return 0;
}


ERRORS

I:\Computer Programming\C++\Key 3.0 (2)\main.cpp||In function 'LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|132|error: expected ')' before ';' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|132|error: expected primary-expression before ',' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|132|error: expected ';' before ')' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|158|error: expected ')' before ';' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|158|error: expected primary-expression before ',' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|158|error: expected ';' before ')' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|194|error: expected ':' before ';' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|194|error: expected primary-expression before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|194|error: expected ';' before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|206|error: expected ':' before ';' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|206|error: expected primary-expression before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|206|error: expected ';' before ':' token|
I:\Computer Programming\C++\Key 3.0 (2)\main.cpp|226|error: expected ';' before '}' token|
||=== Build finished: 13 errors, 0 warnings ===|
Was This Post Helpful? 0
  • +
  • -

#15 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do i know the handle of a windows message?

Posted 01 January 2012 - 11:42 AM

Not too sure about the C syntax, but shouldn't you remove the semicolon after you define ComboB1?

Wrong:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND ComboBox1;
#define ComboB1 1;
HWND ComboBox2;
#define ComboB2 2;
HWND TextBox;


correct:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND ComboBox1;
#define ComboB1 1
HWND ComboBox2;
#define ComboB2 2
HWND TextBox;

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2