Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

wah_on_2

Win32 API provided Picture Box?

This topic is 6115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know i can use CreateWindow(....); to create button, textbox, label. But i don''t know how to create "Picture Box" and "Picture Button" using Win32API? Can help? Thank a lot of!

Share this post


Link to post
Share on other sites
Advertisement
picture boxes are just another name for static controls...as for picture buttons, you will have to make an owner draw one

Share this post


Link to post
Share on other sites
I am not so clear. Can you explain more?

e.g
i can find static control in MSDN, but what is it?
What is the layout of static control?
Can i use static control to make "PictureBox" and "Picture Button"?

Thanks.

Share this post


Link to post
Share on other sites
Ok, I can help you...

To load a bitmap from resource file:

  

HWDN g_hWnd;

int l_iResourceID = IDB_MYPITCURE;

HINSTANCE l_hInstance = (HINSTANCE) GetWindowLong(g_hWnd, GWL_HINSTANCE);

HBITMAP l_hBitmap = (HBITMAP) LoadImage(l_hInstance,
MAKEINTRESOURCE (l_iResourceID), IMAGE_BITMAP, 0, 0, NULL);



To set bitmap to a button:

  

SendMessage(g_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (HANDLE) l_hBitmap);



or a static window:

  

SendMessage(g_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (HANDLE) l_hBitmap);



and then resize button or static window to dimension of bitmap:

  

// Resize window to bitmap size

BITMAP l_hBitmap;

GetObject (l_hBitmap, sizeof (BITMAP), &l_Bitmap);

SetWindowPos(g_hWnd, 0, 0, 0, l_Bitmap.bmWidth, l_Bitmap.bmHeight, SWP_NOZORDER | SWP_NOMOVE);






Zeblar Nagrim, Lord of Chaos

Share this post


Link to post
Share on other sites
Thanks for your help! Sorry, i am so late to see your reply.

But i have a question, if i have two buttons, how can those codes know which button will set image? Or both button will set image?

Thanks.

Share this post


Link to post
Share on other sites
so you mean the g_hWnd of this statement is the HWND of button?

SendMessage(g_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (HANDLE) l_hBitmap);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!