Sunday, February 26, 2006

Window with Controls

Controls are just like windows - You create them with CreateWindowEx and get an HWND on creation.

#undef UNICODE
#undef _UNICODE
#include

//
// SIMPLE CONTROLS
//

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_COMMAND:
if (wParam==2) {
HWND target_hwnd = FindWindowEx(NULL, NULL, NULL, "My Computer");
if (target_hwnd==NULL) {
MessageBoxA(NULL, "FindWindow error", "Error", MB_OK);
} else {

// MoveWindow(target_hwnd, 50, 50, 320, 200, TRUE);
}
}
break;
case WM_CREATE:
//Use "edit" for textbox and "button" for command button; the hmenu value will appear as wParam with a WM_COMMAND message on clicking
CreateWindowEx(NULL, "button", "Click", WS_VISIBLE|WS_CHILD|WS_BORDER, 30, 30, 75, 30, hwnd, (HMENU) 2, NULL, NULL);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int __stdcall WinMain(HINSTANCE hPrevInstance, HINSTANCE hInstance, LPSTR CmdLine, int nCmdShow) {
WNDCLASSEX wc;
int ret=0;
HWND hwnd;
MSG msg;

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

if ((ret=RegisterClassExA(&wc))==0) ExitProcess(-1);

if ((hwnd = CreateWindowEx(0, "Mariott", "White Wine", WS_OVERLAPPEDWINDOW, 10, 10, 320, 200, NULL, NULL, hInstance, NULL))==NULL) ExitProcess(-1);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while (GetMessage(&msg, hwnd, 0, 0)>0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int) msg.wParam;
}

0 Comments:

Post a Comment

<< Home