PureBasic

윈도우 (폼) 모양 바꾸기 - 1

홍사훈     0건     334회

본문

SetWindowRgn_() API를 사용하여 기본 창의 모양을 바꿀 수 있습니다. 아래 예제에서는 간단하게 만들기 위해 각 가젯의 영역을 이용해 region을 생성했지만, 원형이나 마름모 등 다른 모양으로도 region을 생성할 수 있습니다.

 

 

8b66e02d2b4883e265286d1e6f50633e_1433946 

* 참고 자료 *

- CreateRectRgnIndirect API : https://msdn.microsoft.com/en-us/library/dd183515(VS.85).aspx

- CombineRgn API : https://msdn.microsoft.com/en-us/library/dd183465(VS.85).aspx

- SetWindowRgn API : https://msdn.microsoft.com/en-us/library/dd145102(VS.85).aspx

Enumeration

  #Window_0_Button_0

  #Window_0_Text_2

  #Window_0_Container_3

  #Window_0_CheckBox_4

  #Window_0_Option_5

  #Window_0_Frame3D_6

  #Window_0_String_7

EndEnumeration

 

 

If OpenWindow(0, 396, 121, 456, 335, "Window_0", #PB_Window_BorderLess|#PB_Window_ScreenCentered)

  SetWindowColor(0, #Blue)

  

  

  a = ButtonGadget(#Window_0_Button_0, 30, 45, 90, 30, "프로그램 종료")

  

  

  b = TextGadget(#Window_0_Text_2, 160, 45, 120, 30, "Gadget_2")

  SetGadgetColor(#Window_0_Text_2, #PB_Gadget_BackColor, #Green)

  

  

  c = ContainerGadget(#Window_0_Container_3, 30, 95, 350, 155)

    CheckBoxGadget(#Window_0_CheckBox_4, 20, 30, 115, 25, "Gadget_4")

    OptionGadget(#Window_0_Option_5, 20, 65, 115, 25, "Gadget_5")

    Frame3DGadget(#Window_0_Frame3D_6, 10, 5, 190, 145, "Gadget_6")

    StringGadget(#Window_0_String_7, 20, 95, 115, 30, "Gadget_7")

  CloseGadgetList()

  SetGadgetColor(#Window_0_Container_3, #PB_Gadget_BackColor, #Yellow)

  

  

  ;가젯의 클라이언트 좌표, 영역 구함.

  GetClientRect_(a, r1.RECT)

  GetClientRect_(b, r2.RECT)

  GetClientRect_(c, r3.RECT)

  ;부모 윈도우 좌표로 변환.

  MapWindowPoints_(a, WindowID(0), @r1, 2)

  MapWindowPoints_(b, WindowID(0), @r2, 2)

  MapWindowPoints_(c, WindowID(0), @r3, 2)

  

  

  ;각 가젯의 크기로 region 생성.

  hRgn = CreateRectRgnIndirect_(r1)

  hRgn2 = CreateRectRgnIndirect_(r2)

  hRgn3 = CreateRectRgnIndirect_(r3)

  

  

  ;각 region을 hRgn 하나에 결합.

  CombineRgn_(hRgn, hRgn, hRgn2, #RGN_OR)

  CombineRgn_(hRgn, hRgn, hRgn3, #RGN_OR)

  

  

  ;불필요한 region 삭제.

  DeleteObject_(hRgn2)

  DeleteObject_(hRgn3)

  

  

  ;창에 region 설정.

  SetWindowRgn_(WindowID(0), hRgn, 1)

  

  

  Repeat

    Event = WaitWindowEvent()

    Select Event

      Case #PB_Event_Gadget

        EventGadget = EventGadget()

        EventType = EventType()

        

        If EventGadget = #Window_0_Button_0 And EventType = #PB_EventType_LeftClick

          Break

        EndIf

        

      Case #PB_Event_CloseWindow

        Break

        

      Case #WM_LBUTTONDOWN  ;창에서 왼 버튼 누르고 드래그하여 창 이동.

        SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)

    EndSelect

  ForEver

  

  DeleteObject_(hRgn)

EndIf

 

; IDE Options = PureBasic 4.60 RC 1 (Windows - x86)

; CursorPosition = 37

; CursorColumn = 43

; FirstLine = 27

; Folding = -

; EnableUnicode

; EnableXP

; EnableUser

; EnableBuildCount = 0

; EnableExeConstant

 

[이 게시물은 최고관리자님에 의해 2023-04-15 20:43:53 PureBasic에서 이동 됨]

등록된 댓글이 없습니다.



Copyrightⓡ1996~2025, sahoon.com All Rights Reserved.