Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Winapi//gui C++ Question
New Posts  All Forums:Forum Nav:

Winapi//gui C++ Question - Page 2

post #11 of 18
Thread Starter 
I have another question... I'd like to know why I can't paste the sourcecode for a window into my program. I get errors when I try to compile.

This is the program:

Code:
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>

using namespace std;

int main ()
{
cout << " \
 \
 Welcome to LyokoHaCk's carthage emulator. I do not own Code:Lyoko and am not currently affiliated with MoonScoop. \
 \
";
string SCIPIO;
string mystr;
cout << "Enter your name here: ";
getline (cin, mystr);
incorrect:
cout << "Please enter the password " << mystr << ":";
getline (cin, SCIPIO);

if (SCIPIO != "SCIPIO")
{
cout << "Incorrect Password. \
";
cout << endl;
goto incorrect;
}

else

cout << "Connecting to Holosphere... ";
cout << "\
Connected!\
";
cout << "\
Welcome to Carthage " << mystr << "!\
";



}
and I'm trying to get this in (The window code)

Code:
#ifndef _WINDOWS_// if windows.h is not included...
#include <windows>// include it!
#endif
#include "WinTut.h"//include WinTut header file


WinTut::WinTut(HINSTANCE hIns)
{
hInst = hIns;

winTutWndCls.cbSize = sizeof(WNDCLASSEX);
winTutWndCls.style = NULL;
winTutWndCls.lpfnWndProc = WndProc;
winTutWndCls.cbClsExtra = 0;
winTutWndCls.cbWndExtra = 0;
winTutWndCls.hInstance = hInst;
winTutWndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winTutWndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
winTutWndCls.hbrBackground = (HBRUSH)(COLOR_WINDOW);
winTutWndCls.lpszMenuName = NULL;
winTutWndCls.lpszClassName = "WinTutClass";
winTutWndCls.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&winTutWndCls))
{
MessageBox(NULL, "Grrr!\
Could not register window class!", "ERROR", MB_OK | MB_ICONERROR);
}

hWnd = CreateWindowEx(WS_EX_APPWINDOW, "WinTutClass", "WinTut!", WS_OVERLAPPEDWINDOW, 0, 0, 300, 400, NULL, NULL, hInst, NULL);

if(hWnd == NULL)
{
MessageBox(NULL, "Could not create Window! :(", "ERROR", MB_OK | MB_ICONERROR);
}
}

void WinTut::show(void)
{
ShowWindow(hWnd, SW_SHOW);
}



int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{

MSG Msg;

WinTut mainWindow(hInst);
mainWindow.show();

while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;

}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
   
      case WM_CLOSE:
      
         DestroyWindow(hWnd);
         
      break;
      
      case WM_DESTROY:
      
         PostQuitMessage(0);
      break;
      default:
         return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
Please help
post #12 of 18
I think you have to put your code in WinMain. I'm not that good with windows so sorry.
I <3 480's
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8600 ASUS P5Q PRO Turbo Evga GTX 480 4GB OCZ Platinum 
Hard DriveOSMonitorPower
x2 30GB Vertex SSD in RAID0, 120GB WD Windows 7 Ultimate 64 bit 19" Dell LCD Corsair TX750 
Case
Cheap Rosewill 
  hide details  
Reply
I <3 480's
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8600 ASUS P5Q PRO Turbo Evga GTX 480 4GB OCZ Platinum 
Hard DriveOSMonitorPower
x2 30GB Vertex SSD in RAID0, 120GB WD Windows 7 Ultimate 64 bit 19" Dell LCD Corsair TX750 
Case
Cheap Rosewill 
  hide details  
Reply
post #13 of 18
Thread Starter 
how do I put in Winmain?
post #14 of 18
Edit: Nevermind lol
6625WD
(13 items)
 
  
CPUMotherboardGraphicsRAM
T7500 2.2GHz Core 2 Duo Intel 965 (Santa Rosa) 8600M GT 512MB GDDR3 2GB DDR2 800MHz Kingston 
Hard Drive
120GB SATA Hitachi 
  hide details  
Reply
6625WD
(13 items)
 
  
CPUMotherboardGraphicsRAM
T7500 2.2GHz Core 2 Duo Intel 965 (Santa Rosa) 8600M GT 512MB GDDR3 2GB DDR2 800MHz Kingston 
Hard Drive
120GB SATA Hitachi 
  hide details  
Reply
post #15 of 18
Thread Starter 
Well, I made a project in Dev CPP and my ProjectA.cpp file (the code shown earlier) and main.cpp (the window code) and it compiles just fine. The problem is, I see the process in task manager but it dont see anything on my screen. I tried putting the pause code at the end of my projecta.cpp and it still doesn't work. Please help!

Code:
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "WindowsApp",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           600,                 /* The programs width */
           400,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
^Above is the window code
post #16 of 18
Thread Starter 
Incase anybody was wondering, I am simply trying to change the program to a window / api or gui. What ever. The console/dos window looks crummy.
post #17 of 18
Thread Starter 
bump
post #18 of 18
Thread Starter 
I'm using visual c++ now, and I'm having issues combining this into a simple form project. How do I display the code in the window?
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Winapi//gui C++ Question