Therefore, I found a code to actually change the shape of the window. You would only need an original bmp image with a shape. In bmp format, the compiler sees white as blank space, so I can actually draw the shape of my window. I would just need the following code:
BOOL CreateMainWnd(HINSTANCE hInstance)
{
HFONT buttonfont; /*create windows and set fonts*/
hwMain = CreateWindowEx(0,"Window Shaping","Window Shaping", WS_OVERLAPPED,50,50,450,350,0,0,hInstance,0);
hwStatica = CreateWindowEx(0,"Button","Sant Bani",WS_CHILD | WS_VISIBLE | SS_CENTER, 100,88,50,20,hwMain,0,hInstance,0);
hwStaticb = CreateWindowEx(0,"Button","Exit",WS_CHILD | WS_VISIBLE | SS_CENTER, 194,88,50,20,hwMain,0,hInstance,0);
buttonfont = CreateFont(16,0,FW_DONTCARE,FW_DONTCARE,FW_DONTCARE,
FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Arial");
SendMessage(hwStatica,WM_SETFONT,reinterpret_cast(buttonfont),MAKELPARAM(1, 0));
SendMessage(hwStaticb,WM_SETFONT,reinterpret_cast(buttonfont),MAKELPARAM(1, 0));
SetWindowPos(hwMain,HWND_TOPMOST,50,50,626,374, NULL);
ShowWindow(hwMain,1);
if(!hwMain)
return FALSE;
return TRUE;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
switch(wMsg) {
case WM_DESTROY:
PostQuitMessage(0); /*destroy window*/
return 0;
break;
case WM_PAINT:
HDC hdcTemp, bpHDC;
PAINTSTRUCT sentinel;
BITMAP bm;
bpHDC = BeginPaint(hwMain, &sentinel);
if(work) /*if its our first time painting, shape the window*/
{
ShowWindow(hwMain,0); /* window not visible until shaped*/
Mold(bpHDC);
ShowWindow(hwMain,1);
}
hdcTemp = CreateCompatibleDC(bpHDC); /*load and bitblt image to our hdc*/
hwBmp = LoadBitmap(hInst,MAKEINTRESOURCE(102));
SelectObject(hdcTemp,static_cast(hwBmp));
GetObject(static_cast(hwBmp),sizeof(bm),&bm);
BitBlt(bpHDC,0,-30,bm.bmWidth,bm.bmHeight,hdcTemp,0,0,SRCCOPY);
DeleteDC(bpHDC); /*delete uneeded objects to free up memory*/
DeleteDC(hdcTemp);
EndPaint(hwMain,&sentinel);
return 0;
break;
case WM_COMMAND:
/*put a couple of buttons there, just for fun*/
if(wParam == BN_CLICKED)
{
if(reinterpret_cast(lParam) == hwStatica)
ShellExecute(NULL, "open", "http://www.santbani.org", NULL, NULL, SW_SHOWNORMAL);
else if(reinterpret_cast(lParam) == hwStaticb)
DestroyWindow(hwMain);
}
return 0;
break;
case WM_LBUTTONDOWN:
SendMessage(hwMain,WM_SYSCOMMAND,SC_MOVE,0); /*tell the window the user wants to move the window*/
break;
default:
return DefWindowProc(hWnd,wMsg,wParam,lParam);
}
return FALSE;
}
And all the other usual code routines.
I also found out I need to include "windows.h" in any windows application I do. There is also a huge code for just creating a new window and showing it on the screen, which I am trying to understand by lines now. It seems not so hard, but really cool!
No comments:
Post a Comment