![]() |
| | #1 |
| Programmer Join Date: Dec 2004
Posts: 114
| Windows API: Edit Box Help Code: #define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
///////////////////////////////////////////////////////////////////////
// Globals
//////////////////////////
// This section will define globals
///////////////////////////////////////////////////////////////////////
HWND main_hwnd = NULL;
HINSTANCE main_instance = NULL;
///////////////////////////////////////////////////////////////////////
// Events Handler
//////////////////////////
// This section will handle windows events
///////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg){
case WM_CREATE:
{
HDC hdc = GetDC(hwnd);
COLORREF TextColor = RGB(0,175,0);
SetTextColor(hdc,TextColor);
SetBkMode(hdc,TRANSPARENT);
return(0);
}break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,55,40,"Username:",strlen("Username:"));
TextOut(hdc,55,80,"Password:",strlen("Password:"));
EndPaint(hwnd,&ps);
return(0);
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
default:break;
}
return(DefWindowProc(hwnd,msg,wparam,lparam));
}
///////////////////////////////////////////////////////////////////////
// Window main
//////////////////////////
// This section is where the main program code goes.
///////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
///////////////////////////////////////////////////////////////////////
// Windows Class
//////////////////////////
// This section sets up the windows class structure.
// This section creates the application, and determines its
// properties.
///////////////////////////////////////////////////////////////////////
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(100));
winclass.hCursor = LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "WINCLASS1";
winclass.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
if(!RegisterClassEx(&winclass))
return(0);
main_instance = hinstance;
main_hwnd = hwnd;
///////////////////////////////////////////////////////////////////////
// Create Window
//////////////////////////
// This section will create our window.
///////////////////////////////////////////////////////////////////////
if(!(main_hwnd = CreateWindowEx(NULL,"WINCLASS1","Lightning Round: Please Log In",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,100,75,400,300,NULL,NULL,
hinstance, NULL)))
return(0);
///////////////////////////////////////////////////////////////////////
// Create Edit Controls
//////////////////////////
// This section will create our edit controls
///////////////////////////////////////////////////////////////////////
CreateWindowEx(NULL,"WINCLASS1","Username:",ES_LEFT | WS_VISIBLE | WS_CHILD,
60,40,CW_USEDEFAULT,CW_USEDEFAULT,main_hwnd,NULL,main_instance,NULL);
CreateWindowEx(NULL,"WINCLASS1","Password:",ES_LEFT | WS_VISIBLE | WS_CHILD,
60,80,CW_USEDEFAULT,CW_USEDEFAULT,main_hwnd,NULL,main_instance,NULL);
///////////////////////////////////////////////////////////////////////
// Main Event Loop
//////////////////////////
// This section will be where the main program code goes
///////////////////////////////////////////////////////////////////////
while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT){
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam);
}
|
| Frantic- is offline | |
| | #2 |
| Registered User Join Date: Jun 2005 Location: New York
Posts: 1,465
| Don't be afraid to put tab your code, use lots of whitespace, break it into multiple files, etc. Other than that, I saw the problem was that your width and height specifications for your edit box were CW_USEDEFAULT, and the computer has no idea what the default width and height in that case would be, so I modified your code to look something like this: Code: CreateWindowEx(NULL,"Edit","",ES_LEFT | WS_VISIBLE | WS_CHILD, 140,40,100,20,main_hwnd,NULL,main_hinstance,NULL); CreateWindowEx(NULL,"Edit","",ES_LEFT | WS_VISIBLE | WS_CHILD, 140,80,100,20,main_hwnd,NULL,main_hinstance,NULL); Code: //----In some header---// #define ID_PASSBOX 1001 #define ID_USERBOX 1002 //---End header---// ... CreateWindowEx(NULL,"WINCLASS1","",ES_LEFT | WS_VISIBLE | WS_CHILD, 140,40,100,20,hwnd,(HMENU)ID_USERBOX,hinstance,NULL); CreateWindowEx(NULL,"WINCLASS1","",ES_LEFT | WS_VISIBLE | WS_CHILD, 140,80,100,20,hwnd,(HMENU)ID_PASSBOX,hinstance,NULL); ... //---Later in WinProc---// char szBuffer[128]; GetDlgItemText(hwnd, ID_USERBOX, szBuffer, 128); |
| Tonto is offline | |
| | #3 |
| Programmer Join Date: Dec 2004
Posts: 114
| I got it to work with slightly different code, but the major changes you listed were made :-) thanks for the help. |
| Frantic- is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Subclassed editbox: Do I need to create 2 subclasses for 2 edit controls? | BenPage | C++ Programming | 3 | 07-23-2005 08:00 AM |
| display a file in dropdown edit box | sunburnbyRA | Windows Programming | 2 | 03-10-2004 01:58 PM |
| Colouring Edit Box Child Windows | face_master | Windows Programming | 3 | 10-06-2002 02:58 AM |
| Tab Controls - API | -KEN- | Windows Programming | 7 | 06-02-2002 09:44 AM |
| Rich edit control example Win API | Echidna | Windows Programming | 1 | 09-17-2001 02:12 AM |