Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C++
#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
Comments
Sergey Alexandrovich Kryukov 26-Nov-12 16:25pm    
What's the problem, exactly?
--SA

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!
 
Share this answer
 
You create a new window using CreateWindow (or CreateWindowEx) exactly like you did for your main window and its child controls.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900