Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows GUI
Hi Code Project,
 
I am making a simple program which opens a New Window when a correct Password is Entered.
But i do not know how i can do that : The source
#include<WinSock2.h>
#include<Windows.h>
#include<tchar.h>
#pragma comment(lib,"ws2_32.lib")
const char Cybernetwork[] ="Cyber Network";
HWND HWND_EDIT_Number;
HWND HWND_Button_Enter;
HWND HWND_Edit_Login;
char Number[100];
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg , WPARAM wParam , LPARAM lParam)
{
    switch (msg)
    {
    case WM_CREATE:
        HWND_EDIT_Number= CreateWindow(_T("Edit"),_T(""),WS_BORDER|WS_CHILD|WS_VISIBLE,0,20,100,20,hwnd,NULL,NULL,NULL);
        HWND_Button_Enter = CreateWindow(_T("Button"),_T("Login"),BS_PUSHBUTTON|WS_VISIBLE|WS_BORDER|WS_CHILD,0,40,50,20,hwnd,(HMENU)1001,NULL,NULL);
        HWND_Edit_Login= CreateWindow(_T("Edit"),_T("Welcome, to Cyber Network."),WS_BORDER|WS_DISABLED|WS_VISIBLE|WS_CHILD,0,0,500,20,hwnd,NULL,NULL,NULL);
        break;
    case WM_COMMAND:
        if(LOWORD(wParam)==1001)
        {
            GetWindowText(HWND_EDIT_Number,Number,100);
            if(strcmp(Number,"Cyberwarfare")==0)
            {
            MessageBox(NULL,"Correct Password Successfully Logged in ","Password Authentication",MB_OK);
            }
            else
            {
            MessageBox(NULL,"Password Incorrect","Password Authentication",MB_OK);
            }
        }
        break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(1);
        break;
    default:
        return DefWindowProc(hwnd,msg,wParam , lParam);
    }
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevhInstance , LPSTR CmdLine,int CmdShow)
{
    WNDCLASSEX ws;
    HWND hwnd ;
    MSG msg;
    ws.cbClsExtra = 0;
    ws.cbSize = sizeof(WNDCLASSEX);
    ws.cbWndExtra = 0;
    ws.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    ws.hCursor = LoadCursor(NULL,IDC_ARROW);
    ws.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    ws.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
    ws.hInstance= hInstance;
    ws.lpfnWndProc= WndProc;
    ws.lpszClassName= Cybernetwork;
    ws.lpszMenuName = 0;
    ws.style = 0;
    if(!RegisterClassEx(&ws))
    {
    MessageBoxA(NULL,"Error During Registering Class","Error",MB_OK | MB_ICONERROR);
    }
    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE ,Cybernetwork,Cybernetwork,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT ,500,500,NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd,CmdShow);
    UpdateWindow(hwnd);
    while(GetMessage(&msg,0,0,0)>0)
    {
        TranslateMessage(&msg);
        DispatchMessageA(&msg);
    }
    return msg.wParam; 
} 
Posted 26-Nov-12 10:21am
Comments
Sergey Alexandrovich Kryukov at 26-Nov-12 16:25pm
   
What's the problem, exactly?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Perhaps you need to think of the big picture of your application instead of coding things as they come along. The reason I mention this is because you're probably better off making your main window first (you don't have to show it, can be invisible) and THEN create the child modal dialog that requests the password from the user. If you do things in this order, it probably won't seem as confusing.
 
In another words:
0. Make WndProc for main window (message callback routine).
1. Make WndProc for child window.
2. Create your main window (don't show it).
3. Create your password window and show it.
4. If password is correct, you can have child window message the parent window to ask him to show himself (messaging is the way Windows processes communicate). Alternatively, you can just directly call ShowWindow() on the parent from the child... but it's usually preferred that you message the window (if you're going to be doing Windows programming you might as well learn the language... messaging). If you're worried about security, the child window should probably only be passing the collected text over to the main window for processing (i.e. messages could be intercepted) instead of doing the verification himself.
 
Good luck!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You create a new window using CreateWindow (or CreateWindowEx) exactly like you did for your main window and its child controls.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 309
1 BillWoodruff 300
2 Afzaal Ahmad Zeeshan 252
3 DamithSL 225
4 Maciej Los 215
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100