Kategori: Yazılım
WinAPI'de TAB tuşu ile ana pencere ve diğer pencerelerde yer alan kontroller arasında geçiş sağlamak için, kullanıcı tarafından bir pencere oluşturulurken CreateWindowEx() fonksiyonunun 1 nci parametresi olan dwExStyle parametresi WS_EX_CONTROLPARENT değeri, kontroller oluşturulurken CreateWindowEx() fonksiyonunun 4 ncü parametresi olan dwStyle parametresi WS_TABSTOP değeri alır.
Ayrıca, kullanıcı tarafından oluşturulan pencere ve kontroller arasında TAB tuşu ile geçiş sağlanması için, program ana mesaj döngüsünde IsDialogMessage() mesajının çağrılması gerektiğinden, program ana mesaj döngüsü aşağıdaki şekilde olmalıdır:
while (GetMessage (&messages, NULL, 0, 0) > 0) {
if (!IsWindow(hwndMain) || !IsDialogMessage(hwndMain, &messages)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
Bir progam ana penceresinde oluşturulan 4 adet EDIT kontrolü ile kullanıcı tarafından oluşturulan bir panelde bulunan 2 adet EDIT kontrolü arasında TAB tuşu ile geçiş sağlayan program kodları aşağıdadır:
#include <windows.h>
#define IDC_EDIT01 101
#define IDC_EDIT02 102
#define IDC_EDIT03 103
#define IDC_EDIT04 104
#define IDC_EDIT05 105
#define IDC_EDIT06 106
#define IDC_PANEL 201
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK PanelProc (HWND, UINT, WPARAM, LPARAM);
BOOL CreatePanel (HWND);
char szClassName[ ] = "WinAPIWindowsApp";
HINSTANCE ghInst;
HWND hwndEdit01, hwndEdit02, hwndEdit03, hwndEdit04;
HWND hwndPanel;
HWND hwndEdit01Panel, hwndEdit02Panel;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwndMain;
MSG messages;
WNDCLASSEX wincl;
ghInst = hThisInstance;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl)) return 0;
hwndMain = CreateWindowEx (0, szClassName, "WinAPI Temel Program",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
600, 400, HWND_DESKTOP, NULL, hThisInstance, NULL);
if (!hwndMain) return 0;
ShowWindow (hwndMain, nCmdShow);
UpdateWindow(hwndMain);
while (GetMessage (&messages, NULL, 0, 0) > 0) {
if (!IsWindow(hwndMain) || !IsDialogMessage(hwndMain, &messages)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
hwndEdit01 = CreateWindowEx(0, "EDIT", "Edit01",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 20, 200, 20,
hwnd, (HMENU) IDC_EDIT01, NULL, NULL);
hwndEdit02 = CreateWindowEx(0, "EDIT", "Edit02",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 50, 200, 20,
hwnd, (HMENU) IDC_EDIT02, NULL, NULL);
hwndEdit03 = CreateWindowEx(0, "EDIT", "Edit03",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 80, 200, 20,
hwnd, (HMENU) IDC_EDIT03, NULL, NULL);
hwndEdit04 = CreateWindowEx(0, "EDIT", "Edit04",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 110, 200, 20,
hwnd, (HMENU) IDC_EDIT04, NULL, NULL);
if (CreatePanel (hwnd)) {
hwndEdit01Panel = CreateWindowEx(0, "EDIT", "Edit01Panel",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 20, 200, 20,
hwndPanel, (HMENU) IDC_EDIT05, NULL, NULL);
hwndEdit02Panel = CreateWindowEx(0, "EDIT", "Edit02Panel",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 20, 50, 200, 20,
hwndPanel, (HMENU) IDC_EDIT06, NULL, NULL);
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
BOOL CreatePanel (HWND hwndParent)
{
WNDCLASSEX winpan01 = {0};
winpan01.cbSize = sizeof (WNDCLASSEX);
winpan01.lpszClassName = TEXT("Panel");
winpan01.lpfnWndProc = PanelProc;
winpan01.hCursor = LoadCursor (NULL, IDC_ARROW);
winpan01.cbClsExtra = 0;
winpan01.cbWndExtra = 0;
winpan01.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
if (!RegisterClassEx (&winpan01)) return 0;
hwndPanel = CreateWindowEx (WS_EX_CONTROLPARENT, winpan01.lpszClassName, NULL,
WS_CHILD | WS_VISIBLE, 260, 20, 250, 200,
hwndParent, (HMENU) IDC_PANEL, ghInst, NULL);
return 1;
}
LRESULT CALLBACK PanelProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
break;
}
}
return DefWindowProc (hwnd, message, wParam, lParam);
}