Jump to content
  • Advertisement
Sign in to follow this  
Thehuffermsu

win32 controls

This topic is 3799 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

In an effort to learn win32 programming with C++ I decided to try to impliment a battleship game I'd written in C#. The problem I'm having is I'd like to create my board of 100 buttons at runtime instead of making a dialog resource and placing them by hand. I started out placing them directly on my main window but decided to try placing them on a modeless dialog inside the window. What'd I'd like to do is create a modeless dialog from a resource, and size it to equal the size of the client area of the main window and place my controls on the dialog, but im not sure thats possible?

Share this post


Link to post
Share on other sites
Advertisement
if i recall right you most certainly can make a modeless dialog box a child window and resize it from the parent's WM_SIZE handler. modal is a different story, but modeless you should be fine.

Share this post


Link to post
Share on other sites
basic.cpp

#include<windows.h>
#include "crap.h"

HINSTANCE basead = 0;
LPCTSTR title = TEXT("Fundamental Window");
LPCTSTR cname = TEXT("Fundamental Window");

LRESULT CALLBACK MainWndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam);
INT_PTR CALLBACK TestDialogProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam);

int WINAPI WinMain(HINSTANCE handle, HINSTANCE, LPSTR, int)
{
basead = handle;

WNDCLASS wc;
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = basead;
wc.hIcon = 0;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = title;

if(!RegisterClass(&wc))
return MessageBox(0, TEXT("Could not register main window."), TEXT("Error"), MB_ICONSTOP);

DWORD style = WS_OVERLAPPEDWINDOW;
int x = CW_USEDEFAULT; int w = CW_USEDEFAULT;
int y = CW_USEDEFAULT; int h = CW_USEDEFAULT;

HWND window = CreateWindowEx(0, cname, title, style, x, y, w, h, 0, 0, basead, 0);
if(!window) return MessageBox(0, TEXT("Could not create main window."), TEXT("Error"), MB_ICONSTOP);

ShowWindow(window, SW_SHOW);
UpdateWindow(window);

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

return (int)msg.wParam;
}

LRESULT CALLBACK MainWndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
static HWND dialog = 0;

switch(message) {
case(WM_CREATE) : {
dialog = ::CreateDialogW(basead, MAKEINTRESOURCE(ID_TESTDIALOG), window, TestDialogProc);
ShowWindow(dialog, SW_SHOW);
break;
}
case(WM_SIZE) : {
RECT rect;
GetClientRect(window, &rect);
if(dialog) MoveWindow(dialog, 0, 0, rect.right - rect.left, rect.bottom - rect.top, TRUE);
break;
}
case(WM_DESTROY) : {
PostQuitMessage(0);
break;
}
}
return DefWindowProc(window, message, wparam, lparam);
}

INT_PTR CALLBACK TestDialogProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
return FALSE;
}



crap.h

#include<windows.h>

#define ID_TESTDIALOG 9




crap.rc

#include "crap.h"

ID_TESTDIALOG DIALOGEX 0, 0, 187, 95
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,130,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,130,24,50,14
END

Share this post


Link to post
Share on other sites
Thanks yadango, after looking at your simple resource file im pondering if it wouldn't just be simpler to hand write the .rc file with all the buttons placed and then have handles to use then to dynamically add them in code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!