PSP Coding


 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 Typing stuff in GUI

Go down 
AuthorMessage
Jellyforme



Posts : 38
Points : 63
Reputation : 1
Join date : 2010-09-30

PostSubject: Typing stuff in GUI   Mon Oct 04, 2010 5:52 pm

I'm having trouble figuring how to type stuff in the actual GUI window. In console application it was cin but I have no idea how to do it in GUI.
Back to top Go down
View user profile
-LeetGamer-
Admin


Posts : 247
Points : 397
Reputation : 4
Join date : 2010-09-29
Age : 25

PostSubject: Re: Typing stuff in GUI   Mon Oct 04, 2010 6:02 pm

Cout = print to the window

Cin = Get input from use

in console applications, the PDF file I posted tells us how but here is how in my words:

Print text:

I like to first do this at global scope:

UINT GetSizeOf (LPSTR Text)
{
for (int i = 0; i != -1; i++)
{
if (Text [i] == '\0')
{
return 0;
}
}
}

LPSTR Text [] = {
"Hello World";
};

UINT TextSize [] = {
GetSizeOf (Text [0])
};

Then I add this in my window procedure:

case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc = BeginPaint (hwnd, &ps); // hwnd = Window handle so use what you used for that
TextOut (hdc, 10, 10, Text [0], TextSize [0]);
//10 = x coord to print to
//next 10 = y
//then we got the string to print out
//then we got the size of the string, I made a function to get the size for us (GetSizeOf)
EndPaint (hwnd, &ps);
break;


Now here is how you get input (You will need to read a lot to get this, it requires creating a new window:

Form1.h:

Code:

http://Form1.h
#define  IDC_EDIT      2000
#define  IDC_BUTTON    2005

typedef struct        WindowsEventArguments
{
 HWND                  hWnd;
 WPARAM                wParam;
 LPARAM                lParam;
 HINSTANCE            hIns;
}WndEventArgs,        *lpWndEventArgs;


struct EVENTHANDLER
{
 unsigned int          Code;
 long                  (*fnPtr)(lpWndEventArgs);
};

Main.cpp:

Code:

http://Main.cpp
#include <windows.h>
#include <tchar.h>
#include "Form1.h"
EVENTHANDLER  EventHandler[3];


long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
 HWND hCtrl;

 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
 hCtrl=
 CreateWindowEx(WS_EX_CLIENTEDGE,
                "edit","",WS_CHILD|WS_VISIBLE,
                10,30,270,30,
                Wea->hWnd,
                (HMENU)IDC_EDIT,
                Wea->hIns,
                0);
 hCtrl = CreateWindow("button",
                      "Click Me",
                      WS_CHILD|WS_VISIBLE,
                      70,80,150,30,
                      Wea->hWnd,
                      (HMENU)IDC_BUTTON,
                      Wea->hIns,
                      0);

 return 0;
}


long fnWndProc_OnCommand(lpWndEventArgs Wea)
{
 switch(LOWORD(Wea->wParam))
 {
  case IDC_BUTTON:
  {
    TCHAR szBuffer[256];
    GetWindowText(GetDlgItem(Wea->hWnd,IDC_EDIT),szBuffer,256);
    MessageBox(Wea->hWnd,
                szBuffer,
                _T("Here Is The Text You Entered"),
                MB_OK);
  }
 }

 return 0;
}


long fnWndProc_OnClose(lpWndEventArgs Wea)
{
 DestroyWindow(Wea->hWnd);
 PostQuitMessage(0);
 return 0;
}


void AttachEventHandlers(void)
{
 EventHandler[0].Code=WM_CREATE;
 EventHandler[0].fnPtr=fnWndProc_OnCreate;
 EventHandler[1].Code=WM_COMMAND;
 EventHandler[1].fnPtr=fnWndProc_OnCommand;
 EventHandler[2].Code=WM_CLOSE;
 EventHandler[2].fnPtr=fnWndProc_OnClose;
}


long __stdcall fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
 WndEventArgs Wea;

 for(unsigned int i=0; i<3; i++)
 {
    if(EventHandler[i].Code==msg)
    {
        Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
        return (*EventHandler[i].fnPtr)(&Wea);
    }
 }

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int __stdcall WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 TCHAR szClassName[]=_T("Form1");
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 AttachEventHandlers();
 wc.lpszClassName=szClassName;
 wc.lpfnWndProc=fnWndProc;
 wc.cbSize=sizeof (WNDCLASSEX);
 wc.style=CS_DBLCLKS;
 wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 wc.hInstance=hIns;
 wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);
 wc.hCursor=LoadCursor(NULL,IDC_ARROW);
 wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;
 wc.cbWndExtra=0;
 wc.cbClsExtra=0;
 wc.lpszMenuName=NULL;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,_T("Enter Text In Text Box"),WS_OVERLAPPEDWINDOW,100,100,300,175,HWND_DESKTOP,0,hIns,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}

I didn't make the input one.

lmao good luck, you WILL need it Very Happy
Back to top Go down
View user profile
Jellyforme



Posts : 38
Points : 63
Reputation : 1
Join date : 2010-09-30

PostSubject: Re: Typing stuff in GUI   Mon Oct 04, 2010 6:14 pm

So I have to do all that just to make a simple box like the one I'm typing in now? D:
Back to top Go down
View user profile
-LeetGamer-
Admin


Posts : 247
Points : 397
Reputation : 4
Join date : 2010-09-29
Age : 25

PostSubject: Re: Typing stuff in GUI   Mon Oct 04, 2010 6:16 pm

Yeah, it's actually very easy, just learn it and boom there you go Very Happy
Back to top Go down
View user profile
Jellyforme



Posts : 38
Points : 63
Reputation : 1
Join date : 2010-09-30

PostSubject: Re: Typing stuff in GUI   Mon Oct 04, 2010 6:53 pm

Nevermind, this code BBcode text for this skin just makes it look long because its so big and orange. Razz
Back to top Go down
View user profile
-LeetGamer-
Admin


Posts : 247
Points : 397
Reputation : 4
Join date : 2010-09-29
Age : 25

PostSubject: Re: Typing stuff in GUI   Mon Oct 04, 2010 6:57 pm

Jellyforme wrote:
Nevermind, this code BBcode text for this skin just makes it look long because its so big and orange. Razz

lol, let me know if you need any help, also once you get some time (Like a day or so) read all of the pdf file
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Typing stuff in GUI   

Back to top Go down
 
Typing stuff in GUI
Back to top 
Page 1 of 1
 Similar topics
-
» Trade: Xmas Holiday Stuff!
» Dalu's Stuff and Nonsense
» Free Fantage Stuff!!!
» Stop Animal Abuse Club
» Firefox 4 - Mybrute stuff

Permissions in this forum:You cannot reply to topics in this forum
PSP Coding :: Windows Programming :: Windows Programming Help :: GUI Help-
Jump to: