004
28.06.2006, 12:16 Uhr
~ManiacL33T
Gast
|
Hier mal der ganze Source, vieleicht ist dann verständlicher was ich gemacht hab, bzw. machen will.
C++: |
#include "stdafx.h" #include "Adressbuch.h" #include <COMMCTRL.H> #pragma comment(lib,"Comctl32.lib")
//Button ID's Parent #define BTN_NEU 50 #define BTN_ABORT 51
//ID Childfenster #define TABCONTROL 100 #define CHILD 101
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ChildProc(HWND, UINT, WPARAM, LPARAM);
const TCHAR szAppName[]=TEXT("Adressbuch");
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { HWND hMain; MSG msg; WNDCLASS wc;
wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(hInstance, TEXT("#130")); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszMenuName = NULL; wc.lpszClassName = szAppName; wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
wc.lpszClassName = TEXT("SUB"); wc.lpfnWndProc = ChildProc; wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
RegisterClass(&wc);
hMain = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hMain,nCmdShow); UpdateWindow(hMain);
while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
return (int) msg.wParam; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT ps; HBRUSH hBrush; RECT clientRect; HDC hDCBkBuf; HBITMAP hBM; HRGN hRgn; static HWND hButNeu; static HWND hButAbort; static HWND hWndNeu; static int cxClient; static int cyClient;
switch (message) { case WM_CREATE: { hButNeu = CreateWindow(TEXT("button"), TEXT("Neu"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON |WS_TABSTOP, 0, 0, 0, 0, hWnd, (HMENU) BTN_NEU, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
SetFocus(hButNeu);
hButAbort = CreateWindow(TEXT("button"), TEXT("Abbrechen"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON |WS_TABSTOP, 0, 0, 0, 0, hWnd, (HMENU) BTN_ABORT, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
return 0; }
case WM_COMMAND: { switch(LOWORD(wParam)) { case BTN_NEU: hWndNeu = CreateWindowEx(NULL, TEXT("SUB"), TEXT("Erfassung der Mitarbeiterdaten"), WS_OVERLAPPEDWINDOW | WS_VISIBLE , 320, 240, 480, 240, NULL, NULL, NULL, NULL); return 0;
case BTN_ABORT: MessageBox(hWnd, TEXT("Abbruch"), TEXT("Wird schon fertig..."), MB_OK); return 0;
}
return 0; } case WM_KEYDOWN: switch(wParam) { case VK_RETURN: SendMessage(hWnd, WM_COMMAND, 0, 0); } return 0; case WM_SIZE: { cxClient = LOWORD(lParam); cyClient = HIWORD(lParam);
MoveWindow(hButNeu, 10, 10, cxClient / 8, cyClient / 12, TRUE); MoveWindow(hButAbort, 10, 70, cxClient / 8, cyClient / 12, TRUE); return 0; }
case WM_PAINT: { hDC = BeginPaint(hWnd, &ps); //DoubleBuffering hDCBkBuf = CreateCompatibleDC(hDC); hBM = CreateCompatibleBitmap(hDC, cxClient, cyClient); SelectObject(hDCBkBuf, hBM);
//Zeichenoperationen - START hBrush = CreateSolidBrush(RGB(130,0,130)); GetClientRect(hWnd, &clientRect); hRgn = CreateRectRgnIndirect(&clientRect); FillRgn(hDCBkBuf,hRgn,hBrush);
SelectObject(hDCBkBuf,GetStockObject(LTGRAY_BRUSH)); Rectangle(hDCBkBuf, 0, 0, cxClient / 4, cyClient);
DeleteObject(hBrush); DeleteObject(hRgn); //Zeichenoperationen - ENDE
BitBlt(hDC, 0, 0, cxClient, cyClient, hDCBkBuf, 0, 0, SRCCOPY);
DeleteObject(hDCBkBuf); DeleteObject(hBM); EndPaint(hWnd, &ps);
return 0; } case WM_ERASEBKGND: return(1);
case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK ChildProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT ps; TEXTMETRIC tm; static int cxChildClient; static int cyChildClient; static int cxChar; static int cyChar; HWND hTabControl; TCITEM item; static HWND hNam; static HWND hStrasse; static HWND hOrt; static HWND hPlz; switch(message) { case WM_CREATE: hDC = GetDC(hwnd);
GetTextMetrics(hDC, &tm); cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight + tm.tmExternalLeading;
/* Tab Control - Under Construction hTabControl = CreateWindowEx(0, WC_TABCONTROL, TEXT(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS | TCS_FOCUSNEVER | TCS_SINGLELINE, 0, 0, 0, 0, hwnd, HMENU (TABCONTROL), ((LPCREATESTRUCT) lParam) -> hInstance, NULL);
memset(&item, 0, sizeof(item)); item.mask = TCIF_TEXT; item.pszText = TEXT("Tab 1"); TabCtrl_InsertItem(hwnd, 0, &item); item.pszText = TEXT("Tab 2"); TabCtrl_InsertItem(hwnd, 0, &item);*/
hNam = CreateWindow(TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | ES_LEFT | WS_TABSTOP | WS_BORDER , 70, 30, 50 * cxChar, cyChar, hwnd, NULL, ((LPCREATESTRUCT) lParam)-> hInstance, NULL);
SetFocus(hNam);
hStrasse = CreateWindow(TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | ES_LEFT | WS_TABSTOP | WS_BORDER , 70, 60, 50 * cxChar, cyChar, hwnd, NULL, ((LPCREATESTRUCT) lParam)-> hInstance, NULL);
hPlz = CreateWindow(TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | ES_LEFT | WS_TABSTOP | WS_BORDER, 70, 90, 10 * cxChar, cyChar, hwnd, NULL, ((LPCREATESTRUCT) lParam)-> hInstance, NULL);
hOrt = CreateWindow(TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | ES_LEFT | WS_TABSTOP | WS_BORDER, 70 + (10* cxChar) + 5, 90, 30 * cxChar, cyChar, hwnd, NULL, ((LPCREATESTRUCT) lParam)-> hInstance, NULL); ReleaseDC(hwnd, hDC);
case WM_SIZE: cxChildClient = LOWORD(lParam); cyChildClient = HIWORD(lParam);
case WM_PAINT: hDC = BeginPaint(hwnd, &ps); SetBkMode(hDC, TRANSPARENT); TextOut(hDC, 5, 10, TEXT("Bitte geben Sie hier die Mitarbeiterdaten an!"), sizeof("Bitte geben Sie hier die Mitarbeiterdaten an!")-1); TextOut(hDC, 5, 30, TEXT("Name:"),sizeof("Name:")-1); TextOut(hDC, 5, 60, TEXT("Strasse:"), sizeof("Strasse:")-1); TextOut(hDC, 5, 90, TEXT("PLZ / Ort:"), sizeof("PLZ / Ort:")-1); EndPaint(hwnd, &ps); return 0; case WM_CLOSE: DestroyWindow(hwnd); return (0); }
return DefWindowProc (hwnd, message, wParam, lParam); }
|
|