Jump to content

C++ Window Controls


cppman
 Share

Recommended Posts

Hi. I've been going through a GUI tutorial for C++, and am having trouble with checking the wnd message to see if my button has been pressed.. Im not too sure how to do it.

here is my code:

#include <windows.h>
const char *ClassName = "WndClass";
const char *WndName   = "MyWindow";
HWND myButton;
LRESULT CALLBACK MessageProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void wndProperties(WNDCLASSEX &WndClsEx, HINSTANCE hInstance)
{
    WndClsEx.cbSize     = sizeof(WNDCLASSEX);
    WndClsEx.style       = CS_HREDRAW | CS_VREDRAW;
    WndClsEx.lpfnWndProc   = MessageProc;
    WndClsEx.cbClsExtra = 0;
    WndClsEx.cbWndExtra = 0;
    WndClsEx.hIcon       = LoadIcon(NULL, IDI_APPLICATION);
    WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
    WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClsEx.lpszMenuName  = NULL;
    WndClsEx.lpszClassName = ClassName;
    WndClsEx.hInstance   = hInstance;
    WndClsEx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
}

HWND MakeWindow(char *title, int width, int height, HINSTANCE hInstance)
{
    return CreateWindowEx(0,ClassName,title,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hInstan
ce,NULL);

}
LRESULT CALLBACK MessageProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_DESTROY:
        PostQuitMessage(WM_QUIT); break;
        break;
        //case myButton:
        //  MessageBox(NULL, "Test", "tesT", MB_OK);
        //break;
        default:
        DefWindowProc(hWnd, uMsg, wParam, lParam); break;
    }
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
    //Inside my windows function
    MSG Msg;
    HWND hWnd;
    WNDCLASSEX WC;
    wndProperties(WC, hInstance);
    RegisterClassEx(&WC);
    HWND myWindow = MakeWindow("my title", 500, 500, hInstance);
    myButton = CreateWindowEx(0, "BUTTON", "This is my button!", WS_CHILD | WS_VISIBLE, 0, 0, 200, 20, myWindow, (HMENU)100, GetModuleHandle(NULL), NULL);
    ShowWindow(myWindow,nCmdShow);
    UpdateWindow(myWindow);
    while( GetMessage(&Msg, NULL, 0, 0) )
    {
             TranslateMessage(&Msg);
             DispatchMessage(&Msg);
    }
}

the button im trying to check is the only button, myButton. I'd appreciate any help :lmao:

Edited by CHRIS95219
Link to comment
Share on other sites

Then why is it a subforum of AutoIt v3?

Because before the source went closed the Dev's discussed things here.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...